Skip to content

Instantly share code, notes, and snippets.

@andymckay
Created December 5, 2012 03:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andymckay/4211913 to your computer and use it in GitHub Desktop.
Save andymckay/4211913 to your computer and use it in GitHub Desktop.
Crude post processing of the nose-timing script
import datetime
import json
import os
import socket
from subprocess import Popen, PIPE
filehandle = open('times.in.html', 'rb').read()
url = 'https://github.com/mozilla/zamboni/blob/master/'
root = '/Users/andy/sandboxes/zamboni'
times = {'setup': json.load(open('setup.json', 'rb')),
'tests': json.load(open('tests.json', 'rb')),
}
def git(data):
files = data.get('file', {})
line = files.get('line', 0)
if not line:
return ''
if line:
p = Popen(['git', 'blame', '-L %s,%s' % (line, line),
'-p', files['name']], stdout=PIPE)
(child_stdin, child_stdout) = (p.stdin, p.stdout)
result = child_stdout.read()
if result.startswith('fatal:'):
return ''
data = result.split('\n')
fragment = files['name'][len(root)+1:]
try:
return '<a href="%s%s#L%s">%s, %s</a>' % (
url, fragment, line, data[0][:6], data[1][7:])
except IndexError:
return ''
def format_data(data, prefix):
result = []
data = sorted([(v['total'], k, v) for k, v in data.items()])
data.reverse()
count = 1
for total, k, v in data:
if count > 10:
result.append('<tr style="display: none">')
else:
result.append('<tr>')
result.append(' <td><a name="%s-%s">%s</td>' % (prefix, count, count))
result.append(' <td>%s</td>' % k)
result.append(' <td>%s</td>' % total)
result.append(' <td>%s</td>' % git(v))
result.append('</tr>')
count += 1
return '\n'.join(result)
for k, v in times.items():
times[k] = format_data(v, prefix=k)
times['time'] = datetime.datetime.now()
times['on'] = socket.gethostname()
open('times.out.html', 'w').write(filehandle % times)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment