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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
#!/usr/bin/env python
from optparse import OptionParser
from pylab import *
from pprint import pprint
import os.path
def add_entry(d, nspes, speedup, work_incr):
if d.has_key(work_incr):
d[work_incr].append((nspes, speedup))
else:
d[work_incr] = [(nspes, speedup)]
def parse_file(f):
d = {}
for line in f:
items = [float(x) for x in line.split()]
# print "items =", items
nspes = items[0]
work_incr = int(1e6 * items[1])
speedup = items[4]
add_entry(d, nspes, speedup, work_incr)
return d
class plot_data(object):
def __init__(self, filenames, output_filename):
self.fig = figure(1, figsize=(8, 6), facecolor='w')
self.sp = self.fig.add_subplot(1,1,1)
self.sp.set_xlabel("nspes", fontweight="bold")
self.sp.set_ylabel("speedup", fontweight="bold")
self.sp.grid(True)
# print 'rcParams["legend.fontsize"] =', rcParams["legend.fontsize"]
rcParams["legend.fontsize"] = 10
self.markers = {
5 : 'x',
10 : 'o',
50 : 's',
100 : '^',
200 : 'D',
300 : 'v',
400 : '>',
500 : 'h'
}
if len(filenames) == 1:
f = filenames[0]
d = parse_file(open(f))
self.make_single_plot(d, f)
else:
for f in filenames:
d = parse_file(open(f))
self.make_plot(d, f, f == filenames[0])
if output_filename:
savefig(output_filename)
else:
show()
def make_single_plot(self, d, filename):
def style(k):
return self.markers[k]
tag, ext = os.path.splitext(os.path.basename(filename))
title(tag)
keys = d.keys()
keys.sort()
keys.reverse()
for k in keys:
vlist = d[k] # list of 2-tuples
xs = [v[0] for v in vlist]
ys = [v[1] for v in vlist]
plot(xs, ys, style(k), label="%d us" % (k,))
x = legend(loc=2)
def make_plot(self, d, filename, first):
def style(k):
if first:
return self.markers[k]
else:
return 'k' + self.markers[k]
tag, ext = os.path.splitext(os.path.basename(filename))
keys = d.keys()
keys.sort()
keys.reverse()
for k in keys:
vlist = d[k] # list of 2-tuples
xs = [v[0] for v in vlist]
ys = [v[1] for v in vlist]
plot(xs, ys, style(k), label="%s %d us" % (tag, k))
x = legend(loc=2)
def main():
usage="%prog: [options] input_filename..."
description = "Plot R*.avg files from benchmark_nop.py"
parser = OptionParser(usage=usage, description=description)
parser.add_option('-o', '--output', default=None, metavar="FILE",
help="generate .png file")
(options, args) = parser.parse_args()
if len(args) < 1:
parser.print_help()
raise SystemExit, 1
filenames = args
dc = plot_data(filenames, options.output)
if __name__ == '__main__':
try:
main()
except KeyboardInterrupt:
pass
|