-
Notifications
You must be signed in to change notification settings - Fork 0
/
getresult.py
executable file
·78 lines (64 loc) · 2.07 KB
/
getresult.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/python
"""Get a result, from the command line
Usage:
getresult [options] FILE
getresult -h
Options:
-h --help Show this help screen
-c --csv energy, time, power comma seperated output
--no-avg Don't average, print all the values
"""
import docopt
import sys
def getresult(fname):
f = open(fname, "r")
times = []
cur = []
for l in f.readlines():
l = l.strip()
if l == "":
if len(cur) > 0:
times.append(cur)
cur = []
else:
cur.append(map(int, l.split()))
energy = []
time = []
power = []
peakpower = []
for trace in times:
e = 0
t = 0
p = 0
n = 0
pp = 0
for i in range(len(trace)-1):
tv = trace[i+1][4] - trace[i][4]
if trace[i][4] > trace[i+1][4]:
tv = tv + 2**32
e += tv * trace[i][1]
t += tv
p += trace[i][1]
if trace[i][1] > pp:
pp = trace[i][1]
n += 1
energy.append(e)
time.append(t)
power.append(float(p)/n)
peakpower.append(pp)
return (energy, time, power, peakpower)
if __name__ == "__main__":
arguments = docopt.docopt(__doc__)
(energy, time, power, peakpower) = getresult(arguments["FILE"])
if arguments['--csv']:
print "{:f}, {:f}, {:f}".format(float(sum(energy))/len(energy), float(sum(time))/len(time), float(sum(power))/len(power))
else:
if arguments['--no-avg']:
print "Total Energy (10 aJ):\t{}".format(energy)
print "Total Time (10 ns):\t{}".format(time)
print "Average Power (uW):\t{}".format(power)
else:
print "Total Energy (10 aJ):\t{:f}".format(float(sum(energy))/len(energy))
print "Total Time (10 ns):\t{:f}".format(float(sum(time))/len(time))
print "Average Power (uW):\t{:f}".format(float(sum(power))/len(power))
print "Peak Power (uW):\t{:f}".format(float(sum(peakpower))/len(peakpower))