Skip to content

Commit

Permalink
Script to generate latency reports
Browse files Browse the repository at this point in the history
  • Loading branch information
ctiller committed Oct 8, 2015
1 parent 86253ca commit dd25694
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 8 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@ cache.mk

# Temporary test reports
report.xml
latency_trace.txt

# port server log
portlog.txt

# gyp generated make files
*-gyp.mk
out
out
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env python2.7
import argparse
import collections
import hashlib
import itertools
Expand All @@ -15,6 +16,11 @@
TIME_TO_STACK_END = object()


argp = argparse.ArgumentParser(description='Process output of basic_prof builds')
argp.add_argument('--source', default='latency_trace.txt', type=str)
argp.add_argument('--fmt', choices=tabulate.tabulate_formats, default='simple')
args = argp.parse_args()

class LineItem(object):

def __init__(self, line, indent):
Expand Down Expand Up @@ -117,10 +123,9 @@ def finish(self):
builder = collections.defaultdict(CallStackBuilder)
call_stacks = collections.defaultdict(CallStack)

print 'Loading...'
lines = 0
start = time.time()
with open('latency_trace.txt') as f:
with open(args.source) as f:
for line in f:
lines += 1
inf = json.loads(line)
Expand All @@ -133,14 +138,13 @@ def finish(self):
call_stacks[cs.signature] = CallStack(cs)
del builder[thd]
time_taken = time.time() - start
print 'Read %d lines in %f seconds (%f lines/sec)' % (lines, time_taken, lines / time_taken)

print 'Analyzing...'
call_stacks = sorted(call_stacks.values(), key=lambda cs: cs.count, reverse=True)
total_stacks = 0
for cs in call_stacks:
total_stacks += cs.count
cs.finish()

print 'Writing report...'
def percentile(N, percent, key=lambda x:x):
"""
Find the percentile of a list of values.
Expand Down Expand Up @@ -191,13 +195,35 @@ def ent(line, idx=idx):
('TO_SCOPE_END', time_format(TIME_TO_SCOPE_END)),
]

BANNER = {
'simple': 'Count: %(count)d',
'html': '<h1>Count: %(count)d</h1>'
}

if args.fmt == 'html':
print '<html>'
print '<head>'
print '<title>Profile Report</title>'
print '</head>'

accounted_for = 0
for cs in call_stacks:
print cs.count
if args.fmt in BANNER:
print BANNER[args.fmt] % {
'count': cs.count,
}
header, _ = zip(*FORMAT)
table = []
for line in cs.lines:
fields = []
for _, fn in FORMAT:
fields.append(fn(line))
table.append(fields)
print tabulate.tabulate(table, header, tablefmt="simple")
print tabulate.tabulate(table, header, tablefmt=args.fmt)
accounted_for += cs.count
if accounted_for > .99 * total_stacks:
break

if args.fmt == 'html':
print '</html>'

29 changes: 29 additions & 0 deletions tools/profiling/latency_profile/run_latency_profile.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash

set -ex

cd $(dirname $0)/../../..

BINS="sync_unary_ping_pong_test sync_streaming_ping_pong_test"
CPUS=`python -c 'import multiprocessing; print multiprocessing.cpu_count()'`

make CONFIG=basicprof -j$CPUS $BINS

mkdir -p reports

echo '<html><head></head><body>' > reports/index.html
for bin in $BINS
do
bins/basicprof/$bin
mv latency_trace.txt $bin.trace
echo "<a href='$bin.txt'>$bin</a><br/>" >> reports/index.html
done
for bin in $BINS
do
tools/profiling/latency_profile/profile_analyzer.py \
--source=$bin.trace --fmt=simple > reports/$bin.txt &
done
echo '</body></html>' >> reports/index.html

wait

0 comments on commit dd25694

Please sign in to comment.