diff options
| author | bd <bdunahu@operationnull.com> | 2025-08-17 21:18:12 -0400 |
|---|---|---|
| committer | bd <bdunahu@operationnull.com> | 2025-08-17 21:18:12 -0400 |
| commit | 92c2270a29ee3bba762fd7cd4c8fb80ca5a10178 (patch) | |
| tree | d29f2fb0d7efae38de519cf00cebb9757db92340 /aergia/aergia.py | |
| parent | c77f7674bd6e68e03bc8f1f14ab0789f66af42d5 (diff) | |
Diffstat (limited to 'aergia/aergia.py')
| -rwxr-xr-x | aergia/aergia.py | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/aergia/aergia.py b/aergia/aergia.py index fcff1c7..df323b0 100755 --- a/aergia/aergia.py +++ b/aergia/aergia.py @@ -96,6 +96,8 @@ class Aergia(object): total_samples = 0 # the (ideal) interval between samples signal_interval = 0.0 + # the timestamp which the last sample was taken + last_sample = None # the current task for the loop being processed current_task = None @@ -117,6 +119,7 @@ class Aergia(object): in `Aergia._get_idle_task_frames'. The TimerHandler object otherwise does not keep track of a _source_traceback. ''' + Aergia.last_sample = time.perf_counter() signal.signal(signal.SIGALRM, Aergia._idle_signal_handler) signal.setitimer(signal.ITIMER_REAL, @@ -143,7 +146,7 @@ class Aergia(object): '''Pretty-print profiling results.''' if Aergia.total_samples > 0: print(f"{'FILE':<30} {'FUNC':<30}" - f" {'PERC':<8} {'(ACTUAL -> SEC)':<10}") + f" {'PERC':<8} {'SEC':<10}") for key in Aergia._sort_samples(Aergia.samples): Aergia.print_sample(key) else: @@ -156,15 +159,18 @@ class Aergia(object): sig_intv = Aergia.signal_interval value = Aergia.samples[key] print(f"{Aergia._tuple_to_string(key)} {value * 100 / Aergia.total_samples:.3f}% " - f" ({value:.3f} -> {value*sig_intv:.6f})") + f" {value*sig_intv:.6f}") @staticmethod def _idle_signal_handler(sig, frame): '''Obtains and records which lines are currently being waited on.''' + curr_sample = time.perf_counter() + passed_time = curr_sample - Aergia.last_sample keys = Aergia._compute_frames_to_record() for key in keys: - Aergia.samples[Aergia._frame_to_tuple(key)] += 1 - Aergia.total_samples += 1 + Aergia.samples[Aergia._frame_to_tuple(key)] += passed_time + Aergia.total_samples += passed_time + Aergia.last_sample = curr_sample @staticmethod def _compute_frames_to_record(): @@ -318,7 +324,11 @@ class Aergia(object): if any( Aergia._task_is_valid(task) for task in tasks - ): + ) or (tasks and all( + # if all the tasks are done, + getattr(task, '_state', None) == "FINISHED" + for task in tasks + )): return None return deepest_frame @@ -396,11 +406,6 @@ class Aergia(object): return False return True - @staticmethod - def _gettime(): - '''returns the wallclock time''' - return time.process_time() - the_globals = { '__name__': '__main__', |
