diff --git a/parse_session_stats.py b/parse_session_stats.py index 619e3b259..6220712e8 100755 --- a/parse_session_stats.py +++ b/parse_session_stats.py @@ -1,9 +1,12 @@ -#! /usr/bin/env python +#!/usr/bin/env python # Copyright Arvid Norberg 2008. Use, modification and distribution is # subject to the Boost Software License, Version 1.0. (See accompanying # file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) import os, sys, time, os +from multiprocessing.pool import ThreadPool + +thread_pool = ThreadPool(4) stat = open(sys.argv[1]) line = stat.readline() @@ -14,35 +17,69 @@ keys = line.strip().split(':')[1:] output_dir = 'session_stats_report' -def gen_report(name, unit, lines, short_unit, generation, log_file, histogram=False): +line_graph = 0 +histogram = 1 +stacked = 2 + +graph_colors = [] + +pattern = [[0,0,1], [0,1,0], [1,0,0], [1,0,1], [0,1,1], [1,1,0]] + +def process_color(c, op): + for i in range(3): + if op == 0: + c[i] = min(255, c[i] + 0xb0) + if op == 2: + c[i] = max(0, c[i] - 0x50) + return c + +for i in range(0,len(pattern) * 3): + + op = i / len(pattern) + + c = list(pattern[i % len(pattern)]) + for i in range(3): c[i] *= 0xff + c = process_color(c, op) + + c = '#%02x%02x%02x' % (c[0], c[1], c[2]) + graph_colors.append(c) + +line_colors = list(graph_colors) +line_colors.reverse() + +def plot_fun(script): + os.system('gnuplot "%s" 2>/dev/null' % script); + sys.stdout.write('.') + sys.stdout.flush() + +def gen_report(name, unit, lines, short_unit, generation, log_file, type=line_graph): try: os.mkdir(output_dir) except: pass - filename = os.path.join(output_dir, 'session_stats_%s_%04d.png' % (name, generation)) - thumb = os.path.join(output_dir, 'session_stats_%s_%04d_thumb.png' % (name, generation)) + filename = os.path.join(output_dir, '%s_%04d.png' % (name, generation)) + thumb = os.path.join(output_dir, '%s_%04d_thumb.png' % (name, generation)) # don't re-render a graph unless the logfile has changed try: dst1 = os.stat(filename) dst2 = os.stat(thumb) - src = os.stat(log_file) if dst1.st_mtime > src.st_mtime and dst2.st_mtime > src.st_mtime: sys.stdout.write('.') - return + return None except: pass - - out = open('session_stats.gnuplot', 'wb') + script = os.path.join(output_dir, '%s_%04d.gnuplot' % (name, generation)) + out = open(script, 'wb') print >>out, "set term png size 1200,700" print >>out, 'set output "%s"' % filename print >>out, 'set yrange [0:*]' print >>out, "set tics nomirror" print >>out, "set key box" - if histogram: + if type == histogram: binwidth = 0.005; print >>out, 'binwidth=%f' % binwidth @@ -63,6 +100,34 @@ def gen_report(name, unit, lines, short_unit, generation, log_file, histogram=Fa print >>out, '' print >>out, '' + elif type == stacked: + print >>out, 'set xrange [0:*]' + print >>out, 'set ylabel "%s"' % unit + print >>out, 'set xlabel "time (s)"' + print >>out, 'set format y "%%.1s%%c%s";' % short_unit + print >>out, 'set style fill solid 1.0 noborder' + print >>out, 'plot', + column = 2 + first = True + prev = '' + graph = '' + plot_expression = '' + color = 0 + for k in lines: + try: + column = keys.index(k) + 2 + except: + print '"%s" not found' % k + continue; + if not first: + plot_expression = ', ' + plot_expression + graph += '+' + axis = 'x1y1' + graph += '$%d' % column + plot_expression = ' "%s" using 1:(%s) title "%s" axes %s with filledcurves y1=0 lc rgb "%s"' % (log_file, graph, k, axis, graph_colors[color % len(graph_colors)]) + plot_expression + first = False + color += 1 + print >>out, plot_expression else: print >>out, 'set xrange [0:*]' print >>out, 'set ylabel "%s"' % unit @@ -71,6 +136,7 @@ def gen_report(name, unit, lines, short_unit, generation, log_file, histogram=Fa print >>out, 'plot', column = 2 first = True + color = 0 for k in lines: try: column = keys.index(k) + 2 @@ -79,9 +145,9 @@ def gen_report(name, unit, lines, short_unit, generation, log_file, histogram=Fa continue; if not first: print >>out, ', ', axis = 'x1y1' - print >>out, ' "%s" using 1:%d title "%s" axes %s with steps' % (log_file, column, k, axis), + print >>out, ' "%s" using 1:%d title "%s" axes %s with steps lc rgb "%s"' % (log_file, column, k, axis, line_colors[color % len(line_colors)]), first = False - column = column + 1 + color += 1 print >>out, '' print >>out, 'set term png size 150,100' @@ -99,9 +165,7 @@ def gen_report(name, unit, lines, short_unit, generation, log_file, histogram=Fa print >>out, 'set bmargin 0' print >>out, "replot" out.close() - os.system('gnuplot session_stats.gnuplot 2>/dev/null'); - sys.stdout.write('.') - sys.stdout.flush() + return script def gen_html(reports, generations): file = open(os.path.join(output_dir, 'index.html'), 'w+') @@ -117,14 +181,16 @@ def gen_html(reports, generations): for i in reports: print >>file, '