def add(self, duration): if Apdex.satisfying(duration): self.apdex_satisfied += 1 elif Apdex.tolerable(duration): self.apdex_tolerating += 1 else: self.apdex_frustrated += 1 self.count += 1
def renderSlowestRequests(self, number): """Render the n slowest requests of the best cycle.""" stats = self.stats self.append(rst_title("Slowest requests", 2)) cycle = self.getBestCycle() cycle_name = None if not (cycle and stats[cycle].has_key('response_step')): return steps = stats[cycle]['response_step'].keys() items = [] for step_name in steps: stat = stats[cycle]['response_step'][step_name] stat.finalize() items.append((stat.avg, stat.step, stat.type, stat.url, stat.description, stat.apdex_score)) if not cycle_name: cycle_name = stat.cvus items.sort() items.reverse() self.append('The %d slowest average response time during the ' 'best cycle with **%s** CUs:\n' % (number, cycle_name)) for item in items[:number]: self.append(LI + ' In page %s, Apdex rating: %s, avg response time: %3.2fs, %s: ``%s``\n' ' `%s`' % ( item[1], Apdex.get_label(item[5]), item[0], item[2], item[3], item[4]))
def render_stat(self): """Render rst stat.""" stats = self.stats stats.finalize() ret = [' ' * self.indent] ret.append(self.fmt_int % stats.cvus) ret.append(self.fmt_float % stats.apdex_score) ret.append(self.fmt_str % Apdex.get_label(stats.apdex_score)) ret.append(self.fmt_int % stats.count) ret.append(self.fmt_int % stats.success) ret.append(self.fmt_percent % stats.error_percent) ret.append(self.fmt_float % stats.min) ret.append(self.fmt_float % stats.avg) ret.append(self.fmt_float % stats.max) if self.with_percentiles: self._attach_percentiles(ret) ret = self.sep.join(ret) return ret
def getScore(self): return Apdex.score(self.apdex_satisfied, self.apdex_tolerating, self.apdex_frustrated)
def createPageChart(self): """Create the page chart.""" image_path = gnuplot_scriptpath(self.report_dir, 'pages_spps.png') image2_path = gnuplot_scriptpath(self.report_dir, 'pages.png') gplot_path = str(os.path.join(self.report_dir, 'pages.gplot')) data_path = gnuplot_scriptpath(self.report_dir, 'pages.data') stats = self.stats # data lines = ["CUs SPPS ERROR MIN AVG MAX P10 P50 P90 P95 APDEX E G F P U"] cvus = [] has_error = False for cycle in self.cycles: if not stats[cycle].has_key('page'): continue values = [] page = stats[cycle]['page'] values.append(str(page.cvus)) cvus.append(str(page.cvus)) values.append(str(page.rps)) error = page.error_percent if error: has_error = True values.append(str(error)) values.append(str(page.min)) values.append(str(page.avg)) values.append(str(page.max)) values.append(str(page.percentiles.perc10)) values.append(str(page.percentiles.perc50)) values.append(str(page.percentiles.perc90)) values.append(str(page.percentiles.perc95)) score = page.apdex_score values.append(str(score)) apdex = ['0', '0', '0', '0', '0'] score_cls = Apdex.get_score_class(score) score_classes = Apdex.score_classes[:] #copy #flip from worst-to-best to best-to-worst score_classes.reverse() index = score_classes.index(score_cls) apdex[index] = str(score) values = values + apdex lines.append(' '.join(values)) if len(lines) == 1: # No pages finished during a cycle return f = open(data_path, 'w') f.write('\n'.join(lines) + '\n') f.close() # script lines = ['set output "' + image_path +'"'] lines.append('set title "Successful Pages Per Second"') lines.append('set ylabel "Pages Per Second"') lines.append('set grid back') lines.append('set xrange ' + self.getXRange()) lines.append('set terminal png size ' + self.getChartSizeTmp(cvus)) lines.append('set format x ""') lines.append('set multiplot') lines.append('unset title') lines.append('unset xlabel') lines.append('set bmargin 0') lines.append('set lmargin 8') lines.append('set rmargin 9.5') lines.append('set key inside top') if has_error: lines.append('set size 1, 0.4') lines.append('set origin 0, 0.6') else: lines.append('set size 1, 0.6') lines.append('set origin 0, 0.4') lines.append('plot "%s" u 1:2 w linespoints lw 2 lt 2 t "SPPS"' % data_path) # apdex lines.append('set boxwidth 0.8') lines.append('set style fill solid .7') lines.append('set ylabel "Apdex %.1f" ' % Apdex.T) lines.append('set yrange [0:1]') lines.append('set key outside top') if has_error: lines.append('set origin 0.0, 0.3') lines.append('set size 1.0, 0.3') else: lines.append('set size 1.0, 0.4') lines.append('set bmargin 3') lines.append('set format x "% g"') lines.append('set xlabel "Concurrent Users"') lines.append('set origin 0.0, 0.0') lines.append('plot "%s" u 1:12 w boxes lw 2 lt rgb "#99CDFF" t "E", "" u 1:13 w boxes lw 2 lt rgb "#00FF01" t "G", "" u 1:14 w boxes lw 2 lt rgb "#FFFF00" t "F", "" u 1:15 w boxes lw 2 lt rgb "#FF7C81" t "P", "" u 1:16 w boxes lw 2 lt rgb "#C0C0C0" t "U"' % data_path) lines.append('unset boxwidth') lines.append('set key inside top') if has_error: lines.append('set bmargin 3') lines.append('set format x "% g"') lines.append('set xlabel "Concurrent Users"') lines.append('set origin 0.0, 0.0') lines.append('set size 1.0, 0.3') lines.append('set ylabel "% errors"') lines.append('set yrange [0:100]') lines.append('plot "%s" u 1:3 w boxes lt 1 lw 2 t "%% Errors"' % data_path) lines.append('unset yrange') lines.append('set autoscale y') lines.append('unset multiplot') lines.append('set size 1.0, 1.0') lines.append('unset rmargin') lines.append('set output "%s"' % image2_path) lines.append('set title "Pages Response time"') lines.append('set ylabel "Duration (s)"') lines.append('set bars 5.0') lines.append('set style fill solid .25') lines.append('plot "%s" u 1:8:8:10:9 t "med/p90/p95" w candlesticks lt 1 lw 1 whiskerbars 0.5, "" u 1:7:4:8:8 w candlesticks lt 2 lw 1 t "min/p10/med" whiskerbars 0.5, "" u 1:5 t "avg" w lines lt 3 lw 2' % data_path) f = open(gplot_path, 'w') lines = self.fixXLabels('\n'.join(lines) + '\n') f.write(lines) f.close() gnuplot(gplot_path)