5
5
# found in the LICENSE file.
6
6
7
7
import argparse
8
+ import csv
8
9
import json
9
10
import sys
10
11
import matplotlib .pyplot as plt
@@ -20,6 +21,7 @@ def __init__(self, name, backend, timeUnit, drawCallCount):
20
21
self .yLimit = 200
21
22
self .timeUnit = timeUnit
22
23
self .drawCallCount = drawCallCount
24
+ self .optionalValues = {}
23
25
24
26
def __repr__ (self ):
25
27
return 'Name: % s\n Backend: % s\n Series: % s\n SeriesLabels: % s\n ' % (self .name , self .backend , self .series , self .seriesLabels )
@@ -34,6 +36,12 @@ def addDataPoint(self, family, x, y):
34
36
if y > self .yLimit :
35
37
self .largeYValues = True
36
38
39
+ def addOptionalValue (self , name , x , y ):
40
+ if name not in self .optionalValues :
41
+ self .optionalValues [name ] = {}
42
+
43
+ self .optionalValues [name ][x ] = y
44
+
37
45
def setFamilyLabel (self , family , label ):
38
46
# I'm not keying the main series dict off the family label
39
47
# just in case we get data where the two aren't a 1:1 mapping
@@ -93,17 +101,41 @@ def plot(self):
93
101
94
102
return figures
95
103
104
+ def writeCSV (self , writer ):
105
+ # For now assume that all our series have the same x values
106
+ # this is true for now, but may differ in the future with benchmark changes
107
+ x_values = []
108
+ y_values = []
109
+ for family in self .series :
110
+ x_values = ['x' ] + self .series [family ]['x' ]
111
+ y_values .append ([self .seriesLabels [family ]] + self .series [family ]['y' ])
112
+
113
+ for name in self .optionalValues :
114
+ column = [name ]
115
+ for key in self .optionalValues [name ]:
116
+ column .append (self .optionalValues [name ][key ])
117
+ y_values .append (column )
118
+
119
+ writer .writerow ([self .name , self .drawCallCount ])
120
+ for line in range (len (x_values )):
121
+ row = [x_values [line ]]
122
+ for series in range (len (y_values )):
123
+ row .append (y_values [series ][line ])
124
+ writer .writerow (row )
125
+
96
126
def main ():
97
127
parser = argparse .ArgumentParser ()
98
128
99
129
parser .add_argument ('filename' , action = 'store' ,
100
130
help = 'Path to the JSON output from Google Benchmark' )
101
131
parser .add_argument ('-o' , '--output-pdf' , dest = 'outputPDF' , action = 'store' , default = 'output.pdf' ,
102
132
help = 'Filename to output the PDF of graphs to.' )
133
+ parser .add_argument ('-c' , '--output-csv' , dest = 'outputCSV' , action = 'store' , default = 'output.csv' ,
134
+ help = 'Filename to output the CSV data to.' )
103
135
104
136
args = parser .parse_args ()
105
137
jsonData = parseJSON (args .filename )
106
- return processBenchmarkData (jsonData , args .outputPDF )
138
+ return processBenchmarkData (jsonData , args .outputPDF , args . outputCSV )
107
139
108
140
def error (message ):
109
141
print (message )
@@ -127,7 +159,7 @@ def extractAttributesLabel(benchmarkResult):
127
159
128
160
return label [:- 2 ]
129
161
130
- def processBenchmarkData (benchmarkJSON , outputPDF ):
162
+ def processBenchmarkData (benchmarkJSON , outputPDF , outputCSV ):
131
163
benchmarkResultsData = {}
132
164
133
165
for benchmarkResult in benchmarkJSON :
@@ -169,18 +201,28 @@ def processBenchmarkData(benchmarkJSON, outputPDF):
169
201
else :
170
202
benchmarkDrawCallCount = - 1
171
203
204
+ optional_keys = ['DrawCallCount_Varies' , 'VerbCount' , 'PointCount' , 'VertexCount' , 'GlyphCount' ]
205
+
172
206
if benchmarkName not in benchmarkResultsData :
173
207
benchmarkResultsData [benchmarkName ] = BenchmarkResult (benchmarkName , benchmarkBackend , benchmarkUnit , benchmarkDrawCallCount )
174
208
209
+ for key in optional_keys :
210
+ if key in benchmarkResult :
211
+ benchmarkResultsData [benchmarkName ].addOptionalValue (key , benchmarkSeededValue , benchmarkResult [key ])
212
+
175
213
benchmarkResultsData [benchmarkName ].addDataPoint (benchmarkFamilyIndex , benchmarkSeededValue , benchmarkRealTime )
176
214
benchmarkResultsData [benchmarkName ].setFamilyLabel (benchmarkFamilyIndex , benchmarkFamilyLabel )
177
215
178
216
pp = pdfp (outputPDF )
179
217
218
+ csv_file = open (outputCSV , 'w' )
219
+ csv_writer = csv .writer (csv_file )
220
+
180
221
for benchmark in benchmarkResultsData :
181
222
figures = benchmarkResultsData [benchmark ].plot ()
182
223
for fig in figures :
183
224
pp .savefig (fig )
225
+ benchmarkResultsData [benchmark ].writeCSV (csv_writer )
184
226
pp .close ()
185
227
186
228
0 commit comments