gnuradio-core: add ASSERTs for proper alignment
[debian/gnuradio] / gcell / apps / gen_script.py
1 #!/usr/bin/env python
2
3 import sys
4 import time
5 import os
6
7 from optparse import OptionParser
8
9
10 def get_svn_rev():
11     try:
12         f = os.popen("svn info", "r")
13         lines = f.readlines()
14         f.close()
15     except:
16         return "unk"
17
18     svn_rev = "unk"
19     for l in lines:
20         if l.startswith('Revision:'):
21             t = l.rstrip()
22             svn_rev = t.split()[-1]
23     return svn_rev
24     
25 def is_ps3():
26     try:
27         f = open("/proc/cpuinfo")
28         s = f.read()
29     except:
30         return False
31
32     return s.find('PS3') != -1
33
34
35 def main():
36
37     def make_fname(suffix):
38         return basename + '.' + suffix
39
40     max_spes_default = 16
41     if is_ps3():
42         max_spes_default = 6
43         
44     parser = OptionParser()
45     parser.add_option("-m", "--max-spes", type="int", default=max_spes_default,
46                       metavar="NSPES",
47                       help="maximum number of SPEs to use [default=%default]")
48     parser.add_option("", "--min-spes", type="int", default=1,
49                       metavar="NSPES",
50                       help="minimum number of SPEs to use [default=%default]")
51     parser.add_option("-p", "--oprofile", action="store_true", default=False,
52                       help="emit oprofile commands")
53     parser.add_option("-t", "--tag", default=None,
54                       help="additional goodie in generated filenames")
55     (options, args) = parser.parse_args()
56     if len(args) != 0:
57         parser.print_help()
58         sys.exit(1)
59
60     #FIXME to use git now
61     svn_rev = get_svn_rev()
62
63     os.environ['TZ'] = 'PST8PDT'        # always pacific
64     time.tzset()
65
66     tag = ''
67     if options.tag:
68         tag = '-' + options.tag
69         
70     basename = 'R-%s%s-%s' % (svn_rev, tag, time.strftime('%Y%m%d-%H%M'))
71
72     base_njobs = int(500e3)
73     njobs = {
74          1 : base_njobs,
75         10 : base_njobs,
76         50 : base_njobs,
77        100 : base_njobs, 
78        200 : int(base_njobs/2),
79        250 : int(base_njobs/2.5),
80        300 : int(base_njobs/3),
81        400 : int(base_njobs/4),
82        500 : int(base_njobs/5)
83         }
84
85     
86     f_results = make_fname('results')
87     f_opreport = make_fname('opreport')
88     f_avg = make_fname('avg')
89     f_png = make_fname('png')
90
91     f = sys.stdout
92     f.write("#!/bin/bash\n")
93
94     if options.oprofile:
95         f.write("opcontrol --stop\n")
96         f.write("opcontrol --reset\n")
97         f.write("opcontrol --start\n")
98
99     f.write("(\n")
100
101     for udelay in (10, 50, 100, 200, 300):
102         for nspes in range(options.min_spes, options.max_spes+1):
103             cmd = "./benchmark_nop -n %d -u %d -N %d\n" % (nspes, udelay, njobs[udelay])
104             f.write(cmd)
105             f.write(cmd)
106
107     f.write(") | tee %s\n" % (f_results,))
108
109     if options.oprofile:
110         f.write("opcontrol --dump\n")
111         f.write("opcontrol --stop\n")
112         f.write("opreport -l | head -100 > %s\n" % (f_opreport,))
113
114     f.write("./split_and_avg_results.py %s > %s\n" % (f_results, f_avg))
115     f.write("./plot_speedup.py %s -o %s\n" % (f_avg, f_png))
116
117
118 if __name__ == '__main__':
119     main()