8a750fac9d0dd542ad438527936ae8c96653c645
[debian/gnuradio] / gcell / apps / split_and_avg_results.py
1 #!/usr/bin/env python
2 #
3 # Copyright 2007,2008 Free Software Foundation, Inc.
4
5 # This file is part of GNU Radio
6
7 # GNU Radio is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3, or (at your option)
10 # any later version.
11
12 # GNU Radio is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
16
17 # You should have received a copy of the GNU General Public License along
18 # with this program; if not, write to the Free Software Foundation, Inc.,
19 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #
21
22 """
23 input file looks like this:
24
25 nspes:  1  udelay:   10  elapsed_time:   6.842  njobs: 500000  speedup:  0.731
26 nspes:  2  udelay:   10  elapsed_time:   4.093  njobs: 500000  speedup:  1.221
27 """
28
29 import sys
30 from optparse import OptionParser
31 from pprint import pprint
32
33 class data(object):
34     def __init__(self, nspes, work_per_job, elapsed_time, njobs):
35         self.nspes = nspes
36         self.work_per_job = work_per_job  # seconds
37         self.elapsed_time = elapsed_time  # seconds
38         self.njobs = njobs
39         self.speedup = work_per_job * njobs / elapsed_time
40
41     def __repr__(self):
42         return "<data nspes=%d work_per_job=%s elapsed_time=%s njobs=%s speedup=%s>" % (
43             self.nspes, (self.work_per_job),
44             (self.elapsed_time),
45             (self.njobs),
46             (self.speedup))
47
48 def cmp_data(x, y):
49     t = x.nspes - y.nspes
50     if t == 0:
51         t = x.work_per_job - y.work_per_job
52         if t < 0:
53             return -1
54         elif t > 0:
55             return +1
56         else:
57             return 0
58     return t
59
60 def main():
61     usage = "usage: %prog [options] input_filename"
62     parser = OptionParser(usage=usage)
63     (options, args) = parser.parse_args()
64     if len(args) != 1:
65         parser.print_help()
66         raise SystemExit, 1
67     input_filename = args[0]
68
69     
70     m = {}
71     for line in open(input_filename, "r"):
72         s = line.split()
73         nspes = int(s[1])
74         work_per_job = int(s[3]) * 1e-6
75         elapsed_time = float(s[5])
76         njobs = float(s[7])
77         d = data(nspes, work_per_job, elapsed_time, njobs)
78
79         # collect lists that have the same values for nspes and work_per_job
80         # so we can generate an average elapsed_time from all observations
81         key = (nspes, work_per_job)
82         v = m.get(key, [])
83         v.append(d)
84         m[key] = v
85
86     r = []
87     for k, v in m.iteritems():
88         total_elapsed_time = sum([x.elapsed_time for x in v])
89         r.append(data(v[0].nspes,
90                       v[0].work_per_job,
91                       total_elapsed_time/len(v),
92                       v[0].njobs))
93
94     r.sort(cmp_data)
95
96     #pprint(r)
97     for t in r:
98         print t.nspes, t.work_per_job, t.elapsed_time, t.njobs, t.speedup
99
100 if __name__ == '__main__':
101     main()