From b05b92346672ad6885e783a0083a36e9fa476568 Mon Sep 17 00:00:00 2001 From: David Vierra Date: Mon, 20 Jul 2015 19:43:00 -1000 Subject: [PATCH] Embedded profiler now records only samples over the past 10 seconds. Makes live profiling more responsive. --- src/mcedit2/util/profiler.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/mcedit2/util/profiler.py b/src/mcedit2/util/profiler.py index cdf3fdd..59a7ed4 100644 --- a/src/mcedit2/util/profiler.py +++ b/src/mcedit2/util/profiler.py @@ -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)