#! /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 stat = open(sys.argv[1]) line = stat.readline() while not 'second:' in line: line = stat.readline() keys = line.strip().split(':')[1:] output_dir = 'session_stats_report' def gen_report(name, unit, lines, short_unit, generation, log_file, histogram=False): 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)) # 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 except: pass out = open('session_stats.gnuplot', '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: binwidth = 0.005; print >>out, 'binwidth=%f' % binwidth print >>out, 'set boxwidth binwidth' print >>out, 'bin(x,width)=width*floor(x/width) + binwidth/2' print >>out, 'set xrange [0:%f]' % (binwidth * 100) print >>out, 'set xlabel "%s"' % unit print >>out, 'set ylabel "number"' k = lines[0] try: column = keys.index(k) + 2 except: print '"%s" not found' % k return print >>out, 'plot "%s" using (bin($%d,binwidth)):(1.0) smooth freq with boxes' % (log_file, column) print >>out, '' print >>out, '' print >>out, '' else: 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, 'plot', column = 2 first = True for k in lines: try: column = keys.index(k) + 2 except: print '"%s" not found' % k 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), first = False column = column + 1 print >>out, '' print >>out, 'set term png size 150,100' print >>out, 'set output "%s"' % thumb print >>out, 'set key off' print >>out, 'unset tics' print >>out, 'set format x ""' print >>out, 'set format y ""' print >>out, 'set xlabel ""' print >>out, 'set ylabel ""' print >>out, 'set y2label ""' print >>out, 'set rmargin 0' print >>out, 'set lmargin 0' print >>out, 'set tmargin 0' 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() def gen_html(reports, generations): file = open(os.path.join(output_dir, 'index.html'), 'w+') css = '''img { margin: 0} #head { display: block } #graphs { white-space:nowrap; } h1 { line-height: 1; display: inline } h2 { line-height: 1; display: inline; font-size: 1em; font-weight: normal};''' print >>file, '
' % css for i in reports: print >>file, '