Commit 5c83d17e by John Eskew

Fix module-wide nest_level var

parent 152f7d86
...@@ -3,7 +3,12 @@ from timeit import default_timer ...@@ -3,7 +3,12 @@ from timeit import default_timer
from .storage import TimingDataStorage from .storage import TimingDataStorage
nest_level = 0 class Globals(object):
pass
__m = Globals()
__m.nest_level = 0
class CodeBlockTimer(object): class CodeBlockTimer(object):
def __init__(self, block_desc, verbose=False): def __init__(self, block_desc, verbose=False):
...@@ -14,9 +19,9 @@ class CodeBlockTimer(object): ...@@ -14,9 +19,9 @@ class CodeBlockTimer(object):
self.run_id = None self.run_id = None
def __enter__(self): def __enter__(self):
if nest_level == 0: if __m.nest_level == 0:
self.run_id = self.data_store.run_id() self.run_id = self.data_store.run_id()
nest_level += 1 __m.nest_level += 1
self.start = self.timer() self.start = self.timer()
return self return self
...@@ -25,8 +30,8 @@ class CodeBlockTimer(object): ...@@ -25,8 +30,8 @@ class CodeBlockTimer(object):
self.elapsed_secs = end - self.start self.elapsed_secs = end - self.start
self.elapsed = self.elapsed_secs * 1000 # millisecs self.elapsed = self.elapsed_secs * 1000 # millisecs
self.data_store.store(self.run_id, self.block_desc, self.elapsed) self.data_store.store(self.run_id, self.block_desc, self.elapsed)
nest_level -= 1 __m.nest_level -= 1
if nest_level == 0: if __m.nest_level == 0:
self.run_id = None self.run_id = None
if self.verbose: if self.verbose:
print '{}: elapsed time: {} ms'.format(self.block_desc, self.elapsed) print '{}: elapsed time: {} ms'.format(self.block_desc, self.elapsed)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment