Last active
October 5, 2016 09:50
-
-
Save nvdv/cb05ab7c86ff00b8144c6d7e4284a306 to your computer and use it in GitHub Desktop.
How profilers work - stat
This file contains 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
def print_summary(stats, total_time): | |
total_samples = sum(stats.values()) | |
print('Total time: %f s' % total_time) | |
print('Total samples: %s' % total_samples) | |
for curr_stack, sample_count in stats.items(): | |
num_samples = sample_count | |
children = [ | |
stack for stack in stats | |
if len(stack) > len(curr_stack) and curr_stack in stack] | |
# Number of samples for function is number of samples caught by | |
# the function plus sum of samples of children. | |
if children: | |
num_samples += sum(stats[child] for child in children) | |
sample_percent= 100.0 * num_samples / total_samples | |
print('Function: %s, sample count: %d, percentage: %f %%' % ( | |
curr_stack, num_samples, sample_percent)) | |
print_summary(stats, end_time - start_time) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment