Skip to content

Instantly share code, notes, and snippets.

@Olshansk
Last active February 17, 2020 15:20
Show Gist options
  • Save Olshansk/867a1ec17e3cc470d051c41d62c94896 to your computer and use it in GitHub Desktop.
Save Olshansk/867a1ec17e3cc470d051c41d62c94896 to your computer and use it in GitHub Desktop.
A short script that simulates stats profile logging at regular time intervals
import cProfile, pstats
import time
from random import randint
START_TIME = int(time.time())
timestamped_stats_profiles = []
def sleep1():
time.sleep(0.1)
def sleep2():
time.sleep(0.2)
def sleep3():
time.sleep(0.3)
for _ in range(10):
pr = cProfile.Profile()
pr.enable()
for _ in range(randint(1, 10)):
sleep1()
for _ in range(randint(1, 10)):
sleep2()
for _ in range(randint(1, 10)):
sleep3()
pr.create_stats()
ps = pstats.Stats(pr)
stats_profile = get_stats_profile(ps)
timestamped_stats_profiles.append((int(time.time()), stats_profile))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment