Created
April 20, 2015 18:38
-
-
Save donkirkby/947e8ab9187845d04e62 to your computer and use it in GitHub Desktop.
Record all different call stacks that arrive at a method
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import Counter | |
import traceback | |
stack_counts = Counter() | |
def record(limit=10): | |
stack = traceback.extract_stack(limit=limit+1)[:-1] | |
stack_report = '\n'.join(map(str, stack)) | |
stack_counts[stack_report] += 1 | |
def print_report(): | |
# negative count to display highest count first | |
entries = [(-count, stack_report) | |
for stack_report, count in stack_counts.iteritems()] | |
entries.sort() | |
print '== {} stack traces =='.format(sum(stack_counts.values())) | |
for count, stack_report in entries: | |
print '=== {} times ==='.format(-count) | |
print stack_report | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment