xref: /aosp_15_r20/system/extras/tests/workloads/powerave.py (revision 288bf5226967eb3dac5cce6c939ccc2a7f2b4fe5)
1*288bf522SAndroid Build Coastguard Worker#!/usr/bin/python
2*288bf522SAndroid Build Coastguard Worker
3*288bf522SAndroid Build Coastguard Workerimport sys
4*288bf522SAndroid Build Coastguard Workerimport getopt
5*288bf522SAndroid Build Coastguard Worker
6*288bf522SAndroid Build Coastguard Workerdef usage():
7*288bf522SAndroid Build Coastguard Worker    print "powersum.py [OPTIONS] HZ VOLTAGE [FILE]"
8*288bf522SAndroid Build Coastguard Worker    print "OPTIONS: "
9*288bf522SAndroid Build Coastguard Worker    print "-o OFFSET: subtract OFFSET from all data points"
10*288bf522SAndroid Build Coastguard Worker    print "\nHZ: samples per second in FILE or stdin"
11*288bf522SAndroid Build Coastguard Worker    sys.exit(0)
12*288bf522SAndroid Build Coastguard Worker
13*288bf522SAndroid Build Coastguard Workeroffset = 0.0
14*288bf522SAndroid Build Coastguard Workervoltage = 4.3
15*288bf522SAndroid Build Coastguard Worker
16*288bf522SAndroid Build Coastguard Workerparsedargv,argvrem = getopt.getopt(sys.argv[1:], "vo:w:l:h", ["help"])
17*288bf522SAndroid Build Coastguard Workerfor o,a in parsedargv:
18*288bf522SAndroid Build Coastguard Worker    if o == '-o': offset = float(a)
19*288bf522SAndroid Build Coastguard Worker    if o == '-h' or o == '--help': usage()
20*288bf522SAndroid Build Coastguard Worker
21*288bf522SAndroid Build Coastguard Workerhz = float(argvrem[0])
22*288bf522SAndroid Build Coastguard Workervoltage = float(argvrem[1])
23*288bf522SAndroid Build Coastguard Workerif len(argvrem) > 1:
24*288bf522SAndroid Build Coastguard Worker    f = open(argvrem[2], "r")
25*288bf522SAndroid Build Coastguard Workerelse:
26*288bf522SAndroid Build Coastguard Worker    f = sys.stdin
27*288bf522SAndroid Build Coastguard Worker
28*288bf522SAndroid Build Coastguard Workertotalpower = 0.0
29*288bf522SAndroid Build Coastguard Workersamplectr = 0
30*288bf522SAndroid Build Coastguard Worker
31*288bf522SAndroid Build Coastguard Workerfor line in f:
32*288bf522SAndroid Build Coastguard Worker    try:
33*288bf522SAndroid Build Coastguard Worker        val = float(line.split(" ")[1]) # xxx take 2nd arg in line
34*288bf522SAndroid Build Coastguard Worker        val -= offset
35*288bf522SAndroid Build Coastguard Worker    except:
36*288bf522SAndroid Build Coastguard Worker        print "Can't parse data line, did you remember the timestamp?"
37*288bf522SAndroid Build Coastguard Worker        print "data was: %s" % line
38*288bf522SAndroid Build Coastguard Worker        sys.exit(1)
39*288bf522SAndroid Build Coastguard Worker
40*288bf522SAndroid Build Coastguard Worker    samplectr+=1
41*288bf522SAndroid Build Coastguard Worker    totalpower += val/hz
42*288bf522SAndroid Build Coastguard Worker
43*288bf522SAndroid Build Coastguard Workeravecurrent = totalpower * hz *1000 / samplectr
44*288bf522SAndroid Build Coastguard Workeravepower = avecurrent * voltage
45*288bf522SAndroid Build Coastguard Worker
46*288bf522SAndroid Build Coastguard Workerprint "%.3f %.3f" % (avecurrent, avepower)
47