Skip to content

Commit

Permalink
Do not recalculate if the trace invocation was from `threading.Thread…
Browse files Browse the repository at this point in the history
….run`
  • Loading branch information
lucamuscat committed Dec 28, 2024
1 parent e9571ee commit d682fa1
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions perfsephone/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ def __call__(
) -> Any:
frame.f_trace_lines = False

if (
event == "call"
and frame.f_code.co_name == "run"
and frame.f_code.co_filename == threading.__file__
):
is_frame_from_thread_run: bool = (
frame.f_code.co_name == "run" and frame.f_code.co_filename == threading.__file__
)

if event == "call" and is_frame_from_thread_run:
if getattr(self.thread_local, "run_stack_depth", 0) == 0:
profiler = pyinstrument.Profiler(async_mode="disabled")
self.thread_local.profiler = profiler
Expand All @@ -69,11 +69,7 @@ def __call__(
self.thread_local.run_stack_depth += 1
return self.__call__

if (
event == "return"
and frame.f_code.co_name == "run"
and frame.f_code.co_filename == threading.__file__
):
if event == "return" and is_frame_from_thread_run:
self.thread_local.run_stack_depth -= 1
if self.thread_local.run_stack_depth == 0:
assert hasattr(
Expand Down

0 comments on commit d682fa1

Please sign in to comment.