diff options
| author | bd <bdunahu@operationnull.com> | 2025-06-16 16:48:23 -0400 |
|---|---|---|
| committer | bd <bdunahu@operationnull.com> | 2025-06-16 16:48:23 -0400 |
| commit | cf684a625273d08b46a274706a3f70171ebf1749 (patch) | |
| tree | 983dc31516dee1678bc18c3520c5bd3ddd2419a1 /aergia | |
| parent | f04af4d6e012de6b0b8fb24446db9cba152585b6 (diff) | |
Do not return the currently running task while collecting frames
Diffstat (limited to 'aergia')
| -rwxr-xr-x | aergia | 18 |
1 files changed, 14 insertions, 4 deletions
@@ -111,14 +111,14 @@ class Aergia(object): @staticmethod def print_samples(): - '''Pretty-print profiling information.''' + '''Pretty-print profiling results.''' if Aergia.total_samples > 0: - print("Results") print("FILE\tFUNC\tPERC\tACTUAL+CALCULATED=SECONDS") for key in Aergia.sort_samples(Aergia.samples): Aergia.print_sample(key) else: - print("No samples were gathered. This is likely a bug.") + print("No samples were gathered. If you are using concurrency, " + "this is likely a bug and you may run the profiler again.") @staticmethod def print_sample(key): @@ -157,7 +157,7 @@ class Aergia(object): '''Collects all stack frames that Aergia actually processes.''' frames = [] if Aergia.is_event_loop_running(): - frames = [task.get_coro().cr_frame for task in asyncio.all_tasks()] + frames = Aergia.get_current_idle_tasks() # Process all the frames to remove ones we aren't going to track. new_frames = [] @@ -187,6 +187,16 @@ class Aergia(object): return new_frames @staticmethod + def get_current_idle_tasks(): + '''Obtains the stack of frames of all currently idle tasks.''' + curr_task = asyncio.current_task() + return [ + task.get_coro().cr_frame + for task in asyncio.all_tasks() + if task is not curr_task + ] + + @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.''' |
