From 12cb161e92a62dd7752c0c3336939d010fca0741 Mon Sep 17 00:00:00 2001 From: bd Date: Mon, 14 Jul 2025 13:44:37 -0600 Subject: Sample by extracting frame summaries out of TimerHandler objects --- aergia | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/aergia b/aergia index 2474351..00da292 100755 --- a/aergia +++ b/aergia @@ -164,7 +164,7 @@ class Aergia(object): frames = Aergia.get_frames_from_loops(Aergia.get_event_loops()) return [ f for f in frames - if f is not None and Aergia.should_trace(f.f_code.co_filename) + if f is not None and Aergia.should_trace(f.filename) ] @staticmethod @@ -202,20 +202,19 @@ class Aergia(object): @staticmethod def get_frames_from_loops(loops): - '''Given LOOPS, returns a flat list of tasks.''' + '''Given LOOPS, returns a flat list of frames.''' return [ - task for loop in loops - for task in Aergia.get_idle_task_frames(loop) + frames for loop in loops + for frames in Aergia.get_idle_task_frames(loop) ] @staticmethod def frame_to_string(frame): '''Pretty-prints a frame as a function/file name and a line number. Additionally used as a key for tallying lines.''' - co = frame.f_code - func_name = co.co_name - line_no = frame.f_lineno - filename = co.co_filename + func_name = frame.name + line_no = frame.lineno + filename = frame.filename return filename + ':' + str(line_no) + '\t' + func_name @staticmethod @@ -245,17 +244,9 @@ class Aergia(object): def get_idle_task_frames(loop): '''Given an asyncio event loop, returns the list of idle task frames. A task is considered 'idle' if it is not currently executing.''' - curr_task = asyncio.current_task(loop) - if curr_task: - curr_task.print_stack() idle = [] - for task in asyncio.all_tasks(loop): - if task is not curr_task: - # according to docs, the frames are always ordered from oldest - # to newest - # task.print_stack() - # https://stackoverflow.com/questions/73657828/how-to-tell-where-an-asyncio-task-is-waiting - idle.append(task.get_stack()[0]) + for th in loop._scheduled: + idle += th._source_traceback return idle @staticmethod -- cgit v1.2.3