Skip to content

Instantly share code, notes, and snippets.

@Olshansk
Last active February 17, 2020 19:20
Show Gist options
  • Save Olshansk/f34671bf3cb569796acff30bfb4ea178 to your computer and use it in GitHub Desktop.
Save Olshansk/f34671bf3cb569796acff30bfb4ea178 to your computer and use it in GitHub Desktop.
A short script that aggregates all the timestamped & logged stats profiles
from collections import Counter
import itertools
TIME_SLICE = 10 # Aggregate logs every 10 seconds
def time_to_bucket(time):
return (time-START_TIME) // TIME_SLICE
def bucket_to_time(bucket):
return bucket * TIME_SLICE + START_TIME
time_sliced_counters = []
headers = set()
for bucket, grp in itertools.groupby(timestamped_stats_profiles,key=lambda timestamped_stats_profile:time_to_bucket(timestamped_stats_profile[0])):
time_slice_counter = Counter()
for (timestamp, stats_profile) in grp:
for f_name, f_profile in stats_profile.func_profiles.items():
f_name = f_name.lstrip("_") # matplotlib can't allow legend values to start with an underscore
headers.add(f_name)
time_slice_counter[f_name] += f_profile.cumtime
time_sliced_counters.append((bucket_to_time(bucket), time_slice_counter))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment