From 9691ed64bd22820199275492792fa0a6b50bc95f Mon Sep 17 00:00:00 2001 From: bd Date: Sun, 27 Jul 2025 18:17:28 -0600 Subject: Fix bug where duplicate frames would get added (current tasks) --- aergia/aergia.py | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) (limited to 'aergia/aergia.py') diff --git a/aergia/aergia.py b/aergia/aergia.py index d3c525d..be7da35 100755 --- a/aergia/aergia.py +++ b/aergia/aergia.py @@ -157,13 +157,13 @@ class Aergia(object): @staticmethod def _idle_signal_handler(sig, frame): '''Obtains and records which lines are currently being waited on.''' - keys = Aergia._compute_frames_to_record(frame) + keys = Aergia._compute_frames_to_record() for key in keys: Aergia.samples[Aergia._frame_to_tuple(key)] += 1 Aergia.total_samples += 1 @staticmethod - def _compute_frames_to_record(frame): + def _compute_frames_to_record(): '''Collects all stack frames which are currently being awaited on during a given timestamp, as well as those which are currently executing. @@ -179,7 +179,7 @@ class Aergia(object): frames = Aergia._get_frames_from_loops(loops) # current running frames if Aergia.do_profile_current: - frames += Aergia._get_frames_from_threads(frame) + frames += Aergia._get_frames_from_threads() return frames @staticmethod @@ -219,27 +219,26 @@ class Aergia(object): ] @staticmethod - def _get_frames_from_threads(frame): - frames = [frame] - frames += [sys._current_frames().get(t.ident, None) + def _get_frames_from_threads(): + frames = [sys._current_frames().get(t.ident, None) for t in threading.enumerate()] # process frames to remove those we do not track new_frames = [] for f in frames: if f is None: continue - fname = frame.f_code.co_filename + fname = f.f_code.co_filename while not Aergia._should_trace(fname): # walk the stack backwards until we hit a frame that is one # we should trace. - if frame: - frame = frame.f_back + if f: + f = f.f_back else: break - if frame: - fname = frame.f_code.co_filename - if frame: - new_frames.append(frame) + if f: + fname = f.f_code.co_filename + if f: + new_frames.append(f) return new_frames @staticmethod -- cgit v1.2.3