forked from nuxeo/FunkLoad
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReportStats.py
More file actions
329 lines (300 loc) · 11 KB
/
Copy pathReportStats.py
File metadata and controls
329 lines (300 loc) · 11 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
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
# (C) Copyright 2005 Nuxeo SAS <http://nuxeo.com>
# Author: [email protected]
#
# 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 collect statistics submitted by the result parser.
$Id: ReportStats.py 24737 2005-08-31 09:00:16Z bdelbosc $
"""
class MonitorStat:
"""Collect system monitor info."""
def __init__(self, attrs):
for key, value in attrs.items():
setattr(self, key, value)
class ErrorStat:
"""Collect Error or Failure stats."""
def __init__(self, cycle, step, number, code, header, body, traceback):
self.cycle = cycle
self.step = step
self.number = number
self.code = code
self.header = header and header.copy() or {}
self.body = body or None
self.traceback = traceback
class Percentiles:
""" Calculate Percentiles with the given stepsize. """
def __init__(self, stepsize=10, name ="UNKNOWN", results=None):
self.stepsize = stepsize
self.name = name
if results is None:
self.results = []
else:
self.results = results
def addResult(self, newresult):
"""Add a new result."""
self.results.append(newresult)
def calcPercentiles(self):
"""Compute percentiles."""
results = self.results
results.sort()
len_results = len(results)
old_value = -1
for perc in range(0, 100, self.stepsize):
index = int(perc / 100.0 * len_results)
try:
value = results[index]
except IndexError:
value = -1.0
setattr(self, "perc%02d" % perc, float(value))
old_value = value
def __str__(self):
self.calcPercentiles()
fmt_string = ["Percentiles: %s" % self.name]
for perc in range(0, 100, self.stepsize):
name = "perc%02d" % perc
fmt_string.append("%s=%s" % (name, getattr(self, name)))
return ", ".join(fmt_string)
def __repr__(self):
return "Percentiles(stepsize=%r, name=%r, results=%r)" % (
self.stepsize, self.name, self.results)
class AllResponseStat:
"""Collect stat for all response in a cycle."""
def __init__(self, cycle, cycle_duration, cvus):
self.cycle = cycle
self.cycle_duration = cycle_duration
self.cvus = int(cvus)
self.per_second = {}
self.max = 0
self.min = 999999999
self.avg = 0
self.total = 0
self.count = 0
self.success = 0
self.error = 0
self.error_percent = 0
self.rps = 0
self.rps_min = 0
self.rps_max = 0
self.finalized = False
self.percentiles = Percentiles(stepsize = 5, name = cycle)
def add(self, date, result, duration):
"""Add a new response to stat."""
date_s = int(float(date))
self.per_second [date_s] = self.per_second.setdefault(
int(date_s), 0) + 1
self.count += 1
if result == 'Successful':
self.success += 1
else:
self.error += 1
self.max = max(self.max, float(duration))
self.min = min(self.min, float(duration))
self.total += float(duration)
self.finalized = False
self.percentiles.addResult(float(duration))
def finalize(self):
"""Compute avg times."""
if self.finalized:
return
if self.count:
self.avg = self.total / float(self.count)
self.min = min(self.max, self.min)
if self.error:
self.error_percent = 100.0 * self.error / float(self.count)
rps_min = rps_max = 0
for date in self.per_second.keys():
rps_max = max(rps_max, self.per_second[date])
rps_min = min(rps_min, self.per_second[date])
if self.cycle_duration:
rps = self.count / float(self.cycle_duration)
if rps < 1:
# average is lower than 1 this means that sometime there was
# no request during one second
rps_min = 0
self.rps = rps
self.rps_max = rps_max
self.rps_min = rps_min
self.percentiles.calcPercentiles()
self.finalized = True
class SinglePageStat:
"""Collect stat for a single page."""
def __init__(self, step):
self.step = step
self.count = 0
self.date_s = None
self.duration = 0.0
self.result = 'Successful'
def addResponse(self, date, result, duration):
"""Add a response to a page."""
self.count += 1
if self.date_s is None:
self.date_s = int(float(date))
self.duration += float(duration)
if result != 'Successful':
self.result = result
def __repr__(self):
"""Representation."""
return 'page %s %s %ss' % (self.step,
self.result, self.duration)
class PageStat(AllResponseStat):
"""Collect stat for asked pages in a cycle."""
def __init__(self, cycle, cycle_duration, cvus):
AllResponseStat.__init__(self, cycle, cycle_duration, cvus)
self.threads = {}
def add(self, thread, step, date, result, duration, rtype):
"""Add a new response to stat."""
thread = self.threads.setdefault(thread, {'count': 0,
'pages': {}})
if str(rtype) in ('post', 'get', 'xmlrpc'):
new_page = True
else:
new_page = False
if new_page:
thread['count'] += 1
self.count += 1
if not thread['count']:
# don't take into account request that belongs to a staging up page
return
stat = thread['pages'].setdefault(thread['count'],
SinglePageStat(step))
stat.addResponse(date, result, duration)
self.finalized = False
def finalize(self):
"""Compute avg times."""
if self.finalized:
return
for thread in self.threads.keys():
for page in self.threads[thread]['pages'].values():
if str(page.result) == 'Successful':
if page.date_s:
count = self.per_second.setdefault(page.date_s, 0) + 1
self.per_second[page.date_s] = count
self.success += 1
self.total += page.duration
self.percentiles.addResult(page.duration)
else:
self.error += 1
continue
duration = page.duration
self.max = max(self.max, duration)
self.min = min(self.min, duration)
AllResponseStat.finalize(self)
if self.cycle_duration:
# override rps to srps
self.rps = self.success / float(self.cycle_duration)
self.percentiles.calcPercentiles()
self.finalized = True
class ResponseStat:
"""Collect stat a specific response in a cycle."""
def __init__(self, step, number, cvus):
self.step = step
self.number = number
self.cvus = int(cvus)
self.max = 0
self.min = 999999999
self.avg = 0
self.total = 0
self.count = 0
self.success = 0
self.error = 0
self.error_percent = 0
self.url = '?'
self.description = ''
self.type = '?'
self.finalized = False
self.percentiles = Percentiles(stepsize=5, name=step)
def add(self, rtype, result, url, duration, description=None):
"""Add a new response to stat."""
self.count += 1
if result == 'Successful':
self.success += 1
else:
self.error += 1
self.max = max(self.max, float(duration))
self.min = min(self.min, float(duration))
self.total += float(duration)
self.percentiles.addResult(float(duration))
self.url = url
self.type = rtype
if description is not None:
self.description = description
self.finalized = False
def finalize(self):
"""Compute avg times."""
if self.finalized:
return
if self.total:
self.avg = self.total / float(self.count)
self.min = min(self.max, self.min)
if self.error:
self.error_percent = 100.0 * self.error / float(self.count)
self.percentiles.calcPercentiles()
self.finalized = True
class TestStat:
"""Collect test stat for a cycle.
Stat on successful test case.
"""
def __init__(self, cycle, cycle_duration, cvus):
self.cycle = cycle
self.cycle_duration = float(cycle_duration)
self.cvus = int(cvus)
self.max = 0
self.min = 999999999
self.avg = 0
self.total = 0
self.count = 0
self.success = 0
self.error = 0
self.error_percent = 0
self.traceback = []
self.pages = self.images = self.redirects = self.links = 0
self.xmlrpc = 0
self.tps = 0
self.finalized = False
self.percentiles = Percentiles(stepsize=5, name=cycle)
def add(self, result, pages, xmlrpc, redirects, images, links,
duration, traceback=None):
"""Add a new response to stat."""
self.finalized = False
self.count += 1
if traceback is not None:
self.traceback.append(traceback)
if result == 'Successful':
self.success += 1
else:
self.error += 1
return
self.max = max(self.max, float(duration))
self.min = min(self.min, float(duration))
self.total += float(duration)
self.pages = max(self.pages, int(pages))
self.xmlrpc = max(self.xmlrpc, int(xmlrpc))
self.redirects = max(self.redirects, int(redirects))
self.images = max(self.images, int(images))
self.links = max(self.links, int(links))
self.percentiles.addResult(float(duration))
def finalize(self):
"""Compute avg times."""
if self.finalized:
return
if self.success:
self.avg = self.total / float(self.success)
self.min = min(self.max, self.min)
if self.error:
self.error_percent = 100.0 * self.error / float(self.count)
if self.cycle_duration:
self.tps = self.success / float(self.cycle_duration)
self.percentiles.calcPercentiles()
self.finalized = True