summaryrefslogtreecommitdiff
path: root/nemesis/causal_event_loop.py
diff options
context:
space:
mode:
authorbd <bdunahu@operationnull.com>2025-11-10 20:03:08 -0500
committerbd <bdunahu@operationnull.com>2025-11-10 20:03:08 -0500
commitdf45e4380bd325c333ccdd48771b4ceaf36ff4c4 (patch)
tree038082f9d63cf779e82c200597ff0789013175fd /nemesis/causal_event_loop.py
parentc2c3701804c7b57ceb4e1bfaae157b7bb000becc (diff)
Profile all function frames
Diffstat (limited to 'nemesis/causal_event_loop.py')
-rw-r--r--nemesis/causal_event_loop.py36
1 files changed, 18 insertions, 18 deletions
diff --git a/nemesis/causal_event_loop.py b/nemesis/causal_event_loop.py
index 22ec65c..6d18dbc 100644
--- a/nemesis/causal_event_loop.py
+++ b/nemesis/causal_event_loop.py
@@ -103,16 +103,14 @@ class CausalEventLoop(asyncio.SelectorEventLoop):
_time_entered_coro = None
_ready_events = []
# the time this experiment started
- _start_time = None
+ _start_time = float("inf")
def __init__(self) -> None:
super().__init__()
def set_speedup(self, speedup):
# print(self._coro_intervals)
- # we want to delay the start time if we are starting a new experiment
- # during the old experiment's interval
- self._start_time = self.time() if not self._time_entered_coro else None
+ self._start_time = self.time()
self._speedup = speedup
# reset experiment counters
@@ -142,10 +140,7 @@ class CausalEventLoop(asyncio.SelectorEventLoop):
except AssertionError as e:
print(f"Assertion failed: {e}")
sys.exit(1)
- if self._start_time:
- self._coro_intervals.add((self._time_entered_coro, self.time()))
- else:
- self._start_time = self.time()
+ self._coro_intervals.add((self._time_entered_coro, self.time()))
self._time_entered_coro = None
def collect_ready_events(self, timeout=0):
@@ -275,16 +270,21 @@ class CausalEventLoop(asyncio.SelectorEventLoop):
logger.warning('Executing %s took %.3f seconds',
_format_handle(handle), dt)
- time_interval = (handle._when, process_start_time)
- pause_time = self._get_pause_time(time_interval)
- adjusted_start_time = process_start_time - pause_time
- wait_time = adjusted_start_time - handle._when
- try:
- assert wait_time >= -0.0001, f"wait time on {_format_handle(handle)} was found to be {wait_time:.4f}!"
- except AssertionError as e:
- print(f"Assertion failed: {e}")
- sys.exit(1)
- self._completed_coros.append((_format_handle(handle), wait_time))
+ # do not record coroutines which left I/O during the previous experiment
+ # the time held in the pause buffer would have also been incorrect for
+ # this experiment, but there is nothing we can do about it.
+ if handle._when > self._start_time:
+ time_interval = (handle._when, process_start_time)
+ pause_time = self._get_pause_time(time_interval)
+ adjusted_start_time = process_start_time - pause_time
+ wait_time = adjusted_start_time - handle._when
+ try:
+ assert wait_time >= -0.0001, f"wait time on {_format_handle(handle)} was found to be {wait_time:.4f}!"
+ except AssertionError as e:
+ print(f"Assertion failed: {e}")
+ sys.exit(1)
+ self._completed_coros.append((_format_handle(handle), wait_time))
+
except Exception:
traceback.print_exc()
finally: