From ac6c22c51ac4466c6f633c56887c3f8a680034a1 Mon Sep 17 00:00:00 2001 From: Jaremy Creechley Date: Thu, 26 Oct 2023 15:23:13 -0700 Subject: [PATCH] futures profiling instrumentation --- chronos/asyncfutures2.nim | 3 +++ tests/testutils.nim | 1 + 2 files changed, 4 insertions(+) diff --git a/chronos/asyncfutures2.nim b/chronos/asyncfutures2.nim index 34920c0..82ccd44 100644 --- a/chronos/asyncfutures2.nim +++ b/chronos/asyncfutures2.nim @@ -319,6 +319,9 @@ proc futureContinue*(fut: FutureBase) {.raises: [], gcsafe.} = var next: FutureBase template iterate = while true: + when chronosFuturesInstrumentation: + if not(isNil(onFutureRunning)): + onFutureRunning(fut) # Call closure to make progress on `fut` until it reaches `yield` (inside # `await` typically) or completes / fails / is cancelled next = fut.internalClosure(fut) diff --git a/tests/testutils.nim b/tests/testutils.nim index e3ee1b8..72800d3 100644 --- a/tests/testutils.nim +++ b/tests/testutils.nim @@ -247,6 +247,7 @@ suite "Asynchronous utilities test suite": echo "avg wallTime:\t", v.totalWallTime div count, "\ttotal: ", v.totalWallTime echo "avg runTime:\t", v.totalRunTime div count, "\ttotal: ", v.totalRunTime if k.procedure == "simpleAsync1": + echo "v: ", v check v.totalExecTime >= 150.milliseconds() check v.totalExecTime <= 180.milliseconds()