From ac2fabedf73647d51c822df9f6cdff8eac861969 Mon Sep 17 00:00:00 2001 From: benbierens Date: Tue, 8 Aug 2023 09:59:42 +0200 Subject: [PATCH] Applies chronos conventions --- chronos/asyncloop.nim | 8 ++++---- chronos/config.nim | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/chronos/asyncloop.nim b/chronos/asyncloop.nim index be095b2fb..955e3e9bd 100644 --- a/chronos/asyncloop.nim +++ b/chronos/asyncloop.nim @@ -15,7 +15,7 @@ import std/[tables, strutils, heapqueue, deques] import stew/results import "."/[config, futures, osdefs, oserrno, osutils, timer] -when defined(chronosEnableCallbackDurationMetric): +when chronosEnableCallbackDurationMetric: import std/monotimes import pkg/metrics @@ -266,14 +266,14 @@ template processCallbacks(loop: untyped) = if isSentinel(callable): break if not(isNil(callable.function)): - when defined(chronosEnableCallbackDurationMetric): + when chronosEnableCallbackDurationMetric: let startTime = getMonoTime().ticks callable.function(callable.udata) - when defined(chronosEnableCallbackDurationMetric): + when chronosEnableCallbackDurationMetric: let durationUs = (getMonoTime().ticks - startTime) div 1000 - chronosCallbackDuration.set(durationNs) + chronosCallbackDuration.set(durationUs) proc raiseAsDefect*(exc: ref Exception, msg: string) {.noreturn, noinline.} = # Reraise an exception as a Defect, where it's unexpected and can't be handled diff --git a/chronos/config.nim b/chronos/config.nim index 6a8720f1c..63da54055 100644 --- a/chronos/config.nim +++ b/chronos/config.nim @@ -70,7 +70,7 @@ when (NimMajor, NimMinor) >= (1, 4): "" ## OS polling engine type which is going to be used by chronos. - chronosEnableCallbackDurationMetric {.booldefine.} = false + chronosEnableCallbackDurationMetric* {.booldefine.} = defined(chronosEnableCallbackDurationMetric) ## At the cost of some performance, produce a 'chronosCallbackDuration' metric. ## Useful for detecting application stalling/blocking.