Imported Upstream version 3.2.2
[debian/gnuradio] / gnuradio-examples / python / mp-sched / plot_flops.py
1 #!/usr/bin/env python
2 #
3 # Copyright 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 Reads output from run_synthetic.py and runs gnuplot showing
24 GFLOPS as f(npipes, nstages)
25 """
26
27 import re
28 import sys
29 import os
30 import tempfile
31 from optparse import OptionParser
32
33
34 def parse_file(input_filename, output):
35     last = None
36     desc = ''
37     for line in open(input_filename, 'r'):
38         s = line.strip()
39         if s.startswith('>>>'):         # ignore ">>> using SSE cruft"
40             continue
41         
42         if s.startswith('#D'):          # machine description
43             desc = s[2:].strip()
44             continue
45
46         fields = s.split()
47         npipes, nstages, flops = fields[0], fields[1], fields[8]
48
49         if last is not None and npipes != last:
50             output.write('\n')
51         last = npipes
52
53         output.write(' '.join((npipes, nstages, flops)))
54         output.write('\n')
55
56     output.flush()
57     return desc
58
59
60 def handle_file(input_filename):
61     cmd_file = tempfile.NamedTemporaryFile(mode='w+', prefix='pf', suffix='.cmd')
62     cmd_file_name = cmd_file.name
63     data_file = tempfile.NamedTemporaryFile(mode='w+', prefix='pf', suffix='.dat')
64     data_file_name = data_file.name
65     desc = parse_file(input_filename, data_file)
66     if len(desc) > 0:
67         cmd_file.write("set title '%s'\n" % (desc,))
68     cmd_file.write("set xlabel 'N pipes'\n")
69     cmd_file.write("set ylabel 'N stages'\n")
70     cmd_file.write("set zlabel 'GFLOPS'\n")
71     cmd_file.write("set key off\n")
72     cmd_file.write("set view 60, 312\n")
73     cmd_file.write("set pm3d\n")
74     cmd_file.write("splot '%s' using 1:2:($3*1e-9) with pm3d at b, '%s' using 1:2:($3*1e-9) with pm3d\n" % (
75         data_file_name, data_file_name))
76
77     cmd_file.flush()
78     data_file.flush()
79
80     os.system("gnuplot " + cmd_file_name + " -")
81     
82     #sys.stdout.write(open(cmd_file_name,'r').read())
83     #sys.stdout.write(open(data_file_name,'r').read())
84
85
86 def main():
87     usage = "usage: %prog [options] file.dat"
88     parser = OptionParser(usage=usage)
89     (options, args) = parser.parse_args()
90     if len(args) != 1:
91         parser.print_help()
92         raise SystemExit, 1
93
94     handle_file(args[0])
95
96
97 if __name__ == '__main__':
98     main()