Skip to content

Commit 550d1aa

Browse files
committed
Add API reset_stats
1 parent 61afe6e commit 550d1aa

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

line_profiler/_line_profiler.pyx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,15 @@ cdef class LineProfiler:
360360
self._c_last_time[threading.get_ident()].clear()
361361
unset_trace()
362362

363+
def reset_stats(self):
364+
"""
365+
Reset the currently accumulated timings information.
366+
"""
367+
it = self._c_code_map.begin()
368+
while it != self._c_code_map.end():
369+
cython.operator.dereference(it).second.clear()
370+
cython.operator.preincrement(it)
371+
363372
def get_stats(self):
364373
"""
365374
Return a LineStats object containing the timings.

tests/test_explicit_profile.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ def func(a):
2525
print(f'profiler.code_hash_map={profiler.code_hash_map}')
2626
profiler.print_stats()
2727

28+
profiler.reset_stats()
29+
for code in profiler.code_hash_map:
30+
for entry in profiler.code_hash_map[code]:
31+
assert entry in profiler.c_code_map
32+
assert len(profiler.c_code_map[entry]) == 0
33+
2834

2935
def _demo_explicit_profile_script():
3036
return ub.codeblock(

0 commit comments

Comments
 (0)