diff options
Diffstat (limited to 'plot_pm2.py')
-rwxr-xr-x | plot_pm2.py | 154 |
1 files changed, 154 insertions, 0 deletions
diff --git a/plot_pm2.py b/plot_pm2.py new file mode 100755 index 0000000..d53a6da --- /dev/null +++ b/plot_pm2.py | |||
@@ -0,0 +1,154 @@ | |||
1 | #!/usr/bin/env python | ||
2 | import defapp | ||
3 | from os.path import splitext, basename | ||
4 | from optparse import make_option as o | ||
5 | from tempfile import NamedTemporaryFile as Tmp | ||
6 | |||
7 | import csv | ||
8 | |||
9 | from plot import decode | ||
10 | from gnuplot import gnuplot, FORMATS | ||
11 | |||
12 | |||
13 | MACHINE_TOPOLOGY = { | ||
14 | 'jupiter-cs' : (4, [('preempt', lambda x, y: x == y), ('mem', lambda x, y: x != y)]) | ||
15 | } | ||
16 | |||
17 | PMO_PARAM = { | ||
18 | 'wss' : 'WSS', | ||
19 | 'host' : 'host', | ||
20 | 'wcycle' : 'write-cycle' | ||
21 | } | ||
22 | |||
23 | PMO_MEM = { | ||
24 | 'mem' : 'a migration through main memory', | ||
25 | 'preempt' : 'a preemption', | ||
26 | 'all' : 'either a migration or preemption', | ||
27 | } | ||
28 | |||
29 | PMO_SUBPLOTS = [ | ||
30 | # x, y, y-delta, split according to mem-hierarchy? | ||
31 | (0, 6, None, False), | ||
32 | (0, 7, None, False), | ||
33 | (0, 8, None, False), | ||
34 | (0, 9, None, False), | ||
35 | (0, 10, None, True), | ||
36 | (3, 10, None, True), | ||
37 | (0, 10, 9, True), | ||
38 | (3, 10, 9, True), | ||
39 | ] | ||
40 | |||
41 | PMO_COL_LABEL = [('measurement', 'sample', 'index'), | ||
42 | ('write cycles', 'wcycle', 'every nth access'), | ||
43 | ('WSS', 'wcc', 'kilobytes'), | ||
44 | ('suspension length', 'delay', 'microseconds'), | ||
45 | ('CPU (preempted on)', 'from', 'processor'), | ||
46 | ('CPU (resumed on)', 'to', 'processor'), | ||
47 | ('cold access', 'cold', 'cycles'), | ||
48 | ('first hot access', 'hot1', 'cycles'), | ||
49 | ('second hot access', 'hot2', 'cycles'), | ||
50 | ('third hot access', 'hot3', 'cycles'), | ||
51 | ('access after resuming', 'after', 'cycles') | ||
52 | ] | ||
53 | |||
54 | PMO_FROM_CPU = 4 | ||
55 | PMO_TO_CPU = 5 | ||
56 | |||
57 | options = [ | ||
58 | o('-f', '--format', action='store', dest='format', type='choice', | ||
59 | choices=FORMATS, help='output format'), | ||
60 | o(None, '--paper', action='store_true', dest='paper'), | ||
61 | o(None, '--wide', action='store_true', dest='wide'), | ||
62 | o(None, '--split', action='store_true', dest='split'), | ||
63 | ] | ||
64 | |||
65 | defaults = { | ||
66 | 'format' : 'show', | ||
67 | 'paper' : False, | ||
68 | 'split' : False, | ||
69 | 'wide' : False, | ||
70 | } | ||
71 | |||
72 | def extract_cols(data, xcol, ycol1, ycol2, cast=int, cpu_filter=lambda x, y: True): | ||
73 | for row in data: | ||
74 | fcpu = int(row[PMO_FROM_CPU]) | ||
75 | tcpu = int(row[PMO_TO_CPU]) | ||
76 | if cpu_filter(fcpu, tcpu): | ||
77 | if ycol2 is None: | ||
78 | yield (row[xcol], cast(row[ycol1])) | ||
79 | else: | ||
80 | yield (row[xcol], cast(row[ycol1]) - cast(row[ycol2])) | ||
81 | |||
82 | class CyclePlotter(defapp.App): | ||
83 | def __init__(self): | ||
84 | defapp.App.__init__(self, options, defaults, no_std_opts=True) | ||
85 | |||
86 | def setup_pmo_graphs(self, datafile, conf): | ||
87 | host = conf['host'] | ||
88 | if host in MACHINE_TOPOLOGY: | ||
89 | (cpus, hier) = MACHINE_TOPOLOGY[host] | ||
90 | plots = [] | ||
91 | data = list(csv.reader(open(datafile))) | ||
92 | for (xcol, ycol, yminus, by_mem_hierarchy) in PMO_SUBPLOTS: | ||
93 | sub = [('all', lambda x, y: True)] | ||
94 | if by_mem_hierarchy: | ||
95 | sub += hier | ||
96 | for tag, test in sub: | ||
97 | tmp = Tmp() | ||
98 | for row in extract_cols(data, | ||
99 | xcol, ycol, yminus, | ||
100 | cpu_filter=test): | ||
101 | tmp.write("%s, %s\n" % row) | ||
102 | tmp.flush() | ||
103 | plots.append((tmp, xcol, ycol, yminus, tag)) | ||
104 | return plots | ||
105 | else: | ||
106 | self.err('Unkown host: %s' % host) | ||
107 | return None | ||
108 | |||
109 | def plot_preempt_migrate(self, datafile, name, conf): | ||
110 | plots = self.setup_pmo_graphs(datafile, conf) | ||
111 | for (tmp, xcol, ycol, yminus, tag) in plots: | ||
112 | xtag = PMO_COL_LABEL[xcol][1] | ||
113 | ytag = PMO_COL_LABEL[ycol][1] | ||
114 | dtag = "-delta-%s" % PMO_COL_LABEL[yminus][1] if not yminus is None else "" | ||
115 | figname = "%s_%s%s-vs-%s_%s" % (name, ytag, dtag, xtag, tag) | ||
116 | xunit = PMO_COL_LABEL[xcol][2] | ||
117 | yunit = PMO_COL_LABEL[ycol][2] | ||
118 | ylabel = PMO_COL_LABEL[ycol][0] | ||
119 | xlabel = PMO_COL_LABEL[xcol][0] | ||
120 | title = "%s" % ylabel | ||
121 | if ycol == 10: | ||
122 | title += " from %s" % PMO_MEM[tag] | ||
123 | for key in conf: | ||
124 | if key in PMO_PARAM: | ||
125 | title += " %s=%s" % (PMO_PARAM[key], conf[key]) | ||
126 | gnuplot([(tmp.name, 1, 2, ylabel)], | ||
127 | xlabel="%s (%s)" % (xlabel, xunit), | ||
128 | ylabel="%s (%s)" % ("access cost" if yminus is None | ||
129 | else "delta to %s" % PMO_COL_LABEL[yminus][0], | ||
130 | yunit), | ||
131 | title=title, | ||
132 | style='points', | ||
133 | format=self.options.format, | ||
134 | fname=figname) | ||
135 | |||
136 | def plot_file(self, datafile): | ||
137 | bname = basename(datafile) | ||
138 | name, ext = splitext(bname) | ||
139 | if ext != '.csv': | ||
140 | self.err("Warning: '%s' doesn't look like a CSV file." | ||
141 | % bname) | ||
142 | conf = decode(name) | ||
143 | if 'pmo' in conf: | ||
144 | self.plot_preempt_migrate(datafile, name, conf) | ||
145 | else: | ||
146 | self.err("Skipped '%s'; unkown experiment type." | ||
147 | % bname) | ||
148 | |||
149 | def default(self, _): | ||
150 | for datafile in self.args: | ||
151 | self.plot_file(datafile) | ||
152 | |||
153 | if __name__ == "__main__": | ||
154 | CyclePlotter().launch() | ||