Commit 1ee6db5b authored by Kevin Modzelewski's avatar Kevin Modzelewski

add argument parsing to process_stackmap.py

parent bf75c321
......@@ -2611,7 +2611,7 @@ public:
#if ENABLE_SAMPLING_PROFILER
auto stmt = block->body[i];
if (stmt->type != AST_TYPE::Assign) // could be a landingpad
if (!(i == 0 && stmt->type == AST_TYPE::Assign) && stmt->lineno > 0) // could be a landingpad
doSafePoint(block->body[i]);
#endif
......
import argparse
import sys
if __name__ == "__main__":
fn = sys.argv[1]
parser = argparse.ArgumentParser()
parser.add_argument("tracebacks_file", action="store", default=None)
parser.add_argument("--num-display", action="store", default=6, type=int)
parser.add_argument("--dedup-frames", action="store", default=None, type=int)
parser.add_argument("--dedup-file", action="store_true")
parser.add_argument("--dedup-function", action="store_true")
args = parser.parse_args()
num_display = args.num_display
key_func = None
def traceback_locations(t):
return [l for l in t.split('\n') if l.startswith(" File")]
if args.dedup_frames:
assert not key_func
key_func = lambda t: '\n'.join(t.split('\n')[-2 * args.dedup_frames:]) # last 4 stack frames
if args.dedup_file:
assert not key_func
key_func = lambda t: traceback_locations(t)[-1].split('"')[1]
if args.dedup_function:
assert not key_func
def key_func(t):
locations = traceback_locations(t)
last_file = locations[-1].split('"')[1]
last_function = locations[-1].split()[-1][:-1]
return "%s::%s()" % (last_file, last_function)
if not key_func:
key_func = lambda t: t
tracebacks = []
cur_traceback = []
with open(fn) as f:
with open(args.tracebacks_file) as f:
for l in f:
if l.startswith("Traceback"):
if cur_traceback:
......@@ -22,36 +50,24 @@ if __name__ == "__main__":
counts = {}
for t in tracebacks:
locations = [l for l in t.split('\n') if l.startswith(" File")]
last_file = locations[-1].split('"')[1]
last_function = locations[-1].split()[-1][:-1]
# dedupe on:
# key = t # full traceback
# key = '\n'.join(t.split('\n')[-8:]) # last 4 stack frames
# key = '\n'.join(t.split('\n')[-4:]) # last 2 stack frames
# key = '\n'.join(t.split('\n')[-2:]) # last stack frame
# key = last_file, last_function
key = last_file
key = key_func(t)
counts[key] = counts.get(key, 0) + 1
n = len(tracebacks)
NUM_DISPLAY = 6
entries = sorted(counts.items(), key=lambda (k, v): v)
if len(counts) > NUM_DISPLAY:
if len(counts) > num_display:
num_hidden = 0
counts_hidden = 0
for k, v in entries[:-NUM_DISPLAY]:
for k, v in entries[:-num_display]:
num_hidden += 1
counts_hidden += v
print "Hiding %d entries that occurred %d (%.1f%%) times" % (num_hidden, counts_hidden, 100.0 * counts_hidden / n)
for k, v in sorted(counts.items(), key=lambda (k, v): v)[-NUM_DISPLAY:]:
for k, v in sorted(counts.items(), key=lambda (k, v): v)[-num_display:]:
print
print "Occurs %d (%.1f%%) times:" % (v, 100.0 * v / n)
print k
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment