forked from nuxeo/FunkLoad
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReportRenderDiff.py
More file actions
308 lines (269 loc) · 10.5 KB
/
Copy pathReportRenderDiff.py
File metadata and controls
308 lines (269 loc) · 10.5 KB
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
# (C) Copyright 2008 Nuxeo SAS <http://nuxeo.com>
# Author: bdelbosc@nuxeo.com
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as published
# by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
# 02111-1307, USA.
#
"""Classes that render a differential report
$Id$
"""
from __future__ import print_function
from __future__ import absolute_import
import os
from .ReportRenderRst import rst_title
from .ReportRenderHtmlBase import RenderHtmlBase
from .ReportRenderHtmlGnuPlot import gnuplot
def getReadableDiffReportName(a, b):
"""Return a readeable diff report name using 2 reports"""
a = os.path.basename(a)
b = os.path.basename(b)
if a == b:
return "diff_" + a + "_vs_idem"
for i in range(min(len(a), len(b))):
if a[i] != b[i]:
break
for i in range(i, 0, -1):
# try to keep numbers
if a[i] not in "_-0123456789":
i += 1
break
r = b[:i] + "_" + b[i:] + "_vs_" + a[i:]
if r.startswith('test_'):
r = r[5:]
r = r.replace('-_', '_')
r = r.replace('_-', '_')
r = r.replace('__', '_')
return "diff_" + r
def getRPath(a, b):
"""Return a relative path of b from a."""
a_path = a.split('/')
b_path = b.split('/')
for i in range(min(len(a_path), len(b_path))):
if a_path[i] != b_path[i]:
break
return '../' * len(a_path[i:]) + '/'.join(b_path[i:])
class RenderDiff(RenderHtmlBase):
"""Differential report."""
report_dir1 = None
report_dir2 = None
header = None
sep = ', '
data_file = None
output_dir = None
script_file = None
def __init__(self, report_dir1, report_dir2, options, css_file=None):
# Swap windows path separator backslashes for forward slashes
# Windows accepts '/' but some file formats like rest treat the
# backslash specially.
self.report_dir1 = os.path.abspath(report_dir1).replace('\\', '/')
self.report_dir2 = os.path.abspath(report_dir2).replace('\\', '/')
self.options = options
self.css_file = css_file
self.quiet = options.quiet
def generateReportDirectory(self, output_dir):
"""Generate a directory name for a report."""
output_dir = os.path.abspath(output_dir)
report_dir = os.path.join(output_dir, getReadableDiffReportName(
self.report_dir1, self.report_dir2))
if not os.access(report_dir, os.W_OK):
os.mkdir(report_dir, 0o775)
return report_dir
def createCharts(self):
"""Render stats."""
self.createGnuplotData()
self.createGnuplotScript()
gnuplot(self.script_file)
def createRstFile(self):
"""Create the ReST file."""
rst_path = os.path.join(self.report_dir, 'index.rst')
lines = []
b1 = os.path.basename(self.report_dir1)
b2 = os.path.basename(self.report_dir2)
# Swap windows path separator backslashes for forward slashes
b1_rpath = getRPath(self.report_dir.replace('\\', '/'),
os.path.join(self.report_dir1,
'index.html').replace('\\', '/'))
b2_rpath = getRPath(self.report_dir.replace('\\', '/'),
os.path.join(self.report_dir2,
'index.html').replace('\\', '/'))
if b1 == b2:
b2 = b2 +"(2)"
lines.append(rst_title("FunkLoad_ differential report", level=0))
lines.append("")
lines.append(".. sectnum:: :depth: 2")
lines.append("")
lines.append(rst_title("%s vs %s" % (b2, b1), level=1))
lines.append(" * Reference bench report **B1**: `" +
b1 + " <" + b1_rpath + ">`_ [#]_")
lines.append(" * Challenger bench report **B2**: `" +
b2 + " <" + b2_rpath + ">`_ [#]_")
lines.append("")
lines.append(rst_title("Requests", level=2))
lines.append(" .. image:: rps_diff.png")
lines.append(" .. image:: request.png")
lines.append(rst_title("Pages", level=2))
lines.append(" .. image:: spps_diff.png")
escapeReportDir = lambda rd: rd.replace('\\', '/').replace('_', '\\_')
lines.append(" .. [#] B1 path: " + escapeReportDir(self.report_dir1))
lines.append(" .. [#] B2 path: " + escapeReportDir(self.report_dir2))
lines.append(" .. _FunkLoad: http://funkload.nuxeo.org/")
lines.append("")
f = open(rst_path, 'w')
f.write('\n'.join(lines))
f.close()
self.rst_path = rst_path
def copyXmlResult(self):
pass
def __repr__(self):
return self.render()
def extract_stat(self, tag, report_dir):
"""Extract stat from the ReST index file."""
lines = open(os.path.join(report_dir, "index.rst")).readlines()
try:
idx = lines.index("%s stats\n" % tag)
except ValueError:
print("ERROR tag %s not found in rst report %s" % (tag, report_dir))
return []
delim = 0
ret = []
for line in lines[idx:]:
if line.startswith(" ====="):
delim += 1
continue
if delim == 1:
self.header = line.strip().split()
if delim < 2:
continue
if delim == 3:
break
ret.append([x.replace("%","") for x in line.strip().split()])
return ret
def createGnuplotData(self):
"""Render rst stat."""
def output_stat(tag, rep):
stat = self.extract_stat(tag, rep)
text = []
text.append('# ' + tag + " stat for: " + rep)
text.append('# ' + ' '.join(self.header))
for line in stat:
text.append(' '.join(line))
return '\n'.join(text)
def output_stat_diff(tag, rep1, rep2):
stat1 = self.extract_stat(tag, rep1)
stat2 = self.extract_stat(tag, rep2)
text = []
text.append('# ' + tag + " stat for: " + rep1 + " and " + rep2)
text.append('# ' + ' '.join(self.header) + ' ' +
' '.join([x+ "-2" for x in self.header]))
for s1 in stat1:
for s2 in stat2:
if s1[0] == s2[0]:
text.append(' '.join(s1) + ' ' + ' '.join(s2))
break
if s1[0] != s2[0]:
text.append(' '.join(s1))
return '\n'.join(text)
rep1 = self.report_dir1
rep2 = self.report_dir2
data_file = os.path.join(self.report_dir, 'diffbench.dat')
self.data_file = data_file
f = open(data_file, 'w')
f.write('# ' + rep1 + ' vs ' + rep2 + '\n')
for tag, rep in (('Page', rep1), ('Page', rep2),
('Request', rep1), ('Request', rep2)):
f.write(output_stat(tag, rep) + '\n\n\n')
f.write(output_stat_diff('Page', rep1, rep2) + '\n\n\n')
f.write(output_stat_diff('Request', rep1, rep2))
f.close()
def createGnuplotScript(self):
"""Build gnuplot script"""
script_file = os.path.join(self.report_dir, 'script.gplot')
self.script_file = script_file
f = open(script_file, 'w')
rep1 = self.report_dir1
rep2 = self.report_dir2
f.write('# ' + rep1 + ' vs ' + rep2 + '\n')
f.write('''# COMMON SETTINGS
set grid back
set xlabel "Concurrent Users"
set boxwidth 0.9 relative
set style fill solid 1
# SPPS
set output "spps_diff.png"
set terminal png size 640,380
set title "Successful Pages Per Second"
set ylabel "SPPS"
plot "diffbench.dat" i 4 u 1:4:19 w filledcurves above t "B2<B1", "" i 4 u 1:4:19 w filledcurves below t "B2>B1", "" i 4 u 1:4 w lines lw 2 t "B1", "" i 4 u 1:19 w lines lw 2 t "B2"
# RPS
set output "rps_diff.png"
set terminal png size 640,380
set multiplot title "Requests Per Second (Scalability)"
set title "Requests Per Second" offset 0, -2
set size 1, 0.67
set origin 0, 0.3
set ylabel ""
set format x ""
set xlabel ""
plot "diffbench.dat" i 5 u 1:4:19 w filledcurves above t "B2<B1", "" i 5 u 1:4:19 w filledcurves below t "B2>B1", "" i 5 u 1:4 w lines lw 2 t "B1", "" i 5 u 1:19 w lines lw 2 t "B2"
# % RPS
set title "RPS B2/B1 %" offset 0, -2
set size 1, 0.33
set origin 0, 0
set format y "% g%%"
set format x "% g"
set xlabel "Concurrent Users"
plot "diffbench.dat" i 5 u 1:($19<$4?((($19*100)/$4) - 100): 0) w boxes notitle, "" i 5 u 1:($19>=$4?((($19*100)/$4)-100): 0) w boxes notitle
unset multiplot
# RESPONSE TIMES
set output "request.png"
set terminal png size 640,640
set multiplot title "Request Response time (Velocity)"
# AVG
set title "Average" offset 0, -2
set size 0.5, 0.67
set origin 0, 0.30
set ylabel ""
set format y "% gs"
set xlabel ""
set format x ""
plot "diffbench.dat" i 5 u 1:25:10 w filledcurves above t "B2<B1", "" i 5 u 1:25:10 w filledcurves below t "B2>B1", "" i 5 u 1:10 w lines lw 2 t "B1", "" i 5 u 1:25 w lines lw 2 t "B2
# % AVG
set title "Average B1/B2 %" offset 0, -2
set size 0.5, 0.31
set origin 0, 0
set format y "% g%%"
set format x "% g"
set xlabel "Concurrent Users"
plot "diffbench.dat" i 5 u 1:($25>$10?((($10*100)/$25) - 100): 0) w boxes notitle, "" i 5 u 1:($25<=$10?((($10*100)/$25) - 100): 0) w boxes notitle
# MEDIAN
set size 0.5, 0.31
set format y "% gs"
set xlabel ""
set format x ""
set title "Median"
set origin 0.5, 0.66
plot "diffbench.dat" i 5 u 1:28:13 w filledcurves above notitle, "" i 5 u 1:28:13 w filledcurves below notitle, "" i 5 u 1:13 w lines lw 2 notitle, "" i 5 u 1:28 w lines lw 2 notitle
# P90
set title "p90"
set origin 0.5, 0.33
plot "diffbench.dat" i 5 u 1:29:14 w filledcurves above notitle, "" i 5 u 1:29:14 w filledcurves below notitle, "" i 5 u 1:14 w lines lw 2 notitle, "" i 5 u 1:29 w lines lw 2 notitle
# MAX
set title "Max"
set origin 0.5, 0
set format x "% g"
set xlabel "Concurrent Users"
plot "diffbench.dat" i 5 u 1:26:11 w filledcurves above notitle, "" i 5 u 1:26:11 w filledcurves below notitle, "" i 5 u 1:11 w lines lw 2 notitle, "" i 5 u 1:26 w lines lw 2 notitle
unset multiplot
''')
f.close()