summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xaergia39
1 files changed, 14 insertions, 25 deletions
diff --git a/aergia b/aergia
index 00da292..598509c 100755
--- a/aergia
+++ b/aergia
@@ -42,10 +42,9 @@ Code:
'''
from collections import defaultdict
-from typing import List, Optional, Tuple
+from typing import Optional
import argparse
import asyncio
-import selectors
import signal
import sys
import time
@@ -84,7 +83,7 @@ class Aergia(object):
# a key-value pair where keys represent frame metadata (see
# Aergia.frame_to_string) and values represent number of times
# sampled.
- samples = defaultdict(lambda: [0, 0])
+ samples = defaultdict(lambda: 0)
# number of times samples have been collected
total_samples = 0
@@ -113,7 +112,7 @@ class Aergia(object):
def print_samples():
'''Pretty-print profiling results.'''
if Aergia.total_samples > 0:
- print("FILE\tFUNC\tPERC\tACTUAL+CALCULATED=SECONDS")
+ print("FILE\tFUNC\tPERC\t(ACTUAL -> SECONDS)")
for key in Aergia.sort_samples(Aergia.samples):
Aergia.print_sample(key)
else:
@@ -125,10 +124,9 @@ class Aergia(object):
'''Pretty-print a single sample.'''
sig_intv = Aergia.signal_interval
value = Aergia.samples[key]
- tot = Aergia.sum_sample(value)
- print(f"{key} :\t{tot * 100 / Aergia.total_samples:.3f}%"
- f"\t({value[0]:.3f} + {value[1]:.3f} ="
- f" {tot*sig_intv:.6f} seconds)")
+ print(f"{key} :\t{value / Aergia.total_samples:.3f}%"
+ f"\t({value:.3f} ->"
+ f" {value*sig_intv:.6f} seconds)")
@staticmethod
def disable_signals():
@@ -139,13 +137,10 @@ class Aergia(object):
sig_intv = Aergia.signal_interval
elapsed_since_last_signal = Aergia.gettime() - \
Aergia.last_signal_time
- c_time_norm = (elapsed_since_last_signal - sig_intv) / \
- sig_intv
-
keys = Aergia.compute_frames_to_record()
+
for key in keys:
- Aergia.samples[Aergia.frame_to_string(key)][0] += 1
- # Aergia.samples[Aergia.frame_to_string(key)][1] += c_time_norm
+ Aergia.samples[Aergia.frame_to_string(key)] += 1
Aergia.total_samples += elapsed_since_last_signal / \
sig_intv
Aergia.last_signal_time = Aergia.gettime()
@@ -161,7 +156,8 @@ class Aergia(object):
Luckily, the event loop and asyncio.all_tasks keeps track of
what is running for us.'''
- frames = Aergia.get_frames_from_loops(Aergia.get_event_loops())
+ loops = Aergia.get_event_loops()
+ frames = Aergia.get_frames_from_loops(loops)
return [
f for f in frames
if f is not None and Aergia.should_trace(f.filename)
@@ -236,8 +232,7 @@ class Aergia(object):
def sort_samples(sample_dict):
'''Returns SAMPLE_DICT in descending order by number of samples.'''
return {k: v for k, v in sorted(sample_dict.items(),
- key=lambda item: Aergia.sum_sample(
- item[1]),
+ key=lambda item: item[1],
reverse=True)}
@staticmethod
@@ -246,18 +241,12 @@ class Aergia(object):
A task is considered 'idle' if it is not currently executing.'''
idle = []
for th in loop._scheduled:
- idle += th._source_traceback
+ st = th._source_traceback
+ if st:
+ idle += st
return idle
@staticmethod
- def sum_sample(sample):
- '''Sums the total samples taken from a line.
- The indices represent both observed and calculated
- samples. This is equivalent to native/python time
- in SCALENE.'''
- return sample[0] + sample[1]
-
- @staticmethod
def gettime():
'''returns the wallclock time'''
return time.process_time()