Embedded profiler now records only samples over the past 10 seconds.

Makes live profiling more responsive.
This commit is contained in:
David Vierra 2015-07-20 19:43:00 -10:00
parent 3b6d6d6b39
commit b05b923466

View File

@ -18,6 +18,7 @@ ENABLE_PROFILER = True
class Profiler(object):
sampleLimit = 100000
sampleTimeLimit = 10.000
def __init__(self):
self.nameStack = deque(["root"])
@ -99,6 +100,9 @@ class Profiler(object):
def recordSample(self, entry=False):
self.samples.append(('/'.join(self.nameStack), time.time(), entry))
if self.sampleTimeLimit is not None:
while len(self.samples) and self.samples[-1][1] - self.samples[0][1] > self.sampleTimeLimit:
self.samples.popleft()
def analyze(self):
times = defaultdict(float)