diff options
| author | bd <bdunahu@operationnull.com> | 2025-07-14 13:44:37 -0600 |
|---|---|---|
| committer | bd <bdunahu@operationnull.com> | 2025-07-14 13:44:37 -0600 |
| commit | 12cb161e92a62dd7752c0c3336939d010fca0741 (patch) | |
| tree | 2d06f02f64fb84ae9269452b22f16e37ed03d356 | |
| parent | d695f4d78dfd4e0bc2f22f85b15f521f7639150e (diff) | |
Sample by extracting frame summaries out of TimerHandler objects
| -rwxr-xr-x | aergia | 27 |
1 files changed, 9 insertions, 18 deletions
@@ -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 |
