summaryrefslogtreecommitdiff
path: root/nemesis/nemesis.py
diff options
context:
space:
mode:
authorbd <bdunahu@operationnull.com>2025-09-08 14:50:40 -0400
committerbd <bdunahu@operationnull.com>2025-09-08 14:50:40 -0400
commit98924f4ac0a07cd9d4bb74322364347493e73159 (patch)
tree8a36ba97ab02ae3176e85e59aa5c50323b9f4263 /nemesis/nemesis.py
parentba1c72cedb56512f52c48ee947a2b11fa8a90c4d (diff)
Improve reporting format, separate samples based on tident
Diffstat (limited to 'nemesis/nemesis.py')
-rwxr-xr-xnemesis/nemesis.py34
1 files changed, 29 insertions, 5 deletions
diff --git a/nemesis/nemesis.py b/nemesis/nemesis.py
index 69d0c2b..c20d68d 100755
--- a/nemesis/nemesis.py
+++ b/nemesis/nemesis.py
@@ -25,7 +25,6 @@ Commentary:
Code:
'''
-from asyncio.base_events import _format_handle
from collections import defaultdict
from experiment import Experiment
import argparse
@@ -128,12 +127,21 @@ class Nemesis(object):
def _get_waiting_handles(loop):
handles = []
for handle in loop._ready:
- if (fmt_handle := _format_handle(handle)) is not None \
- and fmt_handle not in handles:
- # no duplicates
- handles.append(fmt_handle)
+ # no duplicates
+ handle_info = Nemesis._parse_handle(handle)
+ if handle_info not in handles:
+ handles.append(handle_info)
return handles
+ def _parse_handle(handle):
+ cb = handle._callback
+ if isinstance(getattr(cb, '__self__', None), asyncio.tasks.Task):
+ task = cb.__self__
+ coro = task.get_coro()
+ return [task.get_name(), Nemesis.get_coro_name(coro)]
+ else:
+ return [str(type(handle).__name__), cb.__name__]
+
def _get_current_coro(loop):
tid = loop._thread_id
assert tid, f"{loop} is not running, yet we attempted to sample it!"
@@ -173,6 +181,22 @@ class Nemesis(object):
return False
return True
+ def get_coro_name(coro):
+ '''
+ Stolen from _format_coroutine in cpython/Lib/asyncio/coroutines.py
+ '''
+ # Coroutines compiled with Cython sometimes don't have
+ # proper __qualname__ or __name__. While that is a bug
+ # in Cython, asyncio shouldn't crash with an AttributeError
+ # in its __repr__ functions.
+ if hasattr(coro, '__qualname__') and coro.__qualname__:
+ coro_name = coro.__qualname__
+ elif hasattr(coro, '__name__') and coro.__name__:
+ coro_name = coro.__name__
+ else:
+ # Stop masking Cython bugs, expose them in a friendly way.
+ coro_name = f'<{type(coro).__name__} without __name__>'
+ return f'{coro_name}()'
the_globals = {
'__name__': '__main__',