mirror of
https://github.com/status-im/nim-chronos.git
synced 2025-01-21 00:39:32 +00:00
Sets up the callback duration metric
This commit is contained in:
parent
466241aa95
commit
e07f0dc049
@ -15,6 +15,12 @@ import std/[tables, strutils, heapqueue, deques]
|
||||
import stew/results
|
||||
import "."/[config, futures, osdefs, oserrno, osutils, timer]
|
||||
|
||||
when defined(chronosEnableCallbackDurationMetric):
|
||||
import std/monotimes
|
||||
import pkg/metrics
|
||||
|
||||
declareGauge(chronosCallbackDuration, "chronos callback duration")
|
||||
|
||||
export Port
|
||||
export futures, timer, results
|
||||
|
||||
@ -260,8 +266,15 @@ template processCallbacks(loop: untyped) =
|
||||
if isSentinel(callable):
|
||||
break
|
||||
if not(isNil(callable.function)):
|
||||
when defined(chronosEnableCallbackDurationMetric):
|
||||
let startTime = getMonoTime().ticks
|
||||
|
||||
callable.function(callable.udata)
|
||||
|
||||
when defined(chronosEnableCallbackDurationMetric):
|
||||
let durationUs = (getMonoTime().ticks - startTime) div 1000
|
||||
chronosCallbackDuration.set(durationNs)
|
||||
|
||||
proc raiseAsDefect*(exc: ref Exception, msg: string) {.noreturn, noinline.} =
|
||||
# Reraise an exception as a Defect, where it's unexpected and can't be handled
|
||||
# We include the stack trace in the message because otherwise, it's easily
|
||||
|
@ -70,6 +70,10 @@ when (NimMajor, NimMinor) >= (1, 4):
|
||||
""
|
||||
## OS polling engine type which is going to be used by chronos.
|
||||
|
||||
chronosEnableCallbackDurationMetric {.booldefine.} = false
|
||||
## At the cost of some performance, produce a 'chronosCallbackDuration' metric.
|
||||
## Useful for detecting application stalling/blocking.
|
||||
|
||||
else:
|
||||
# 1.2 doesn't support `booldefine` in `when` properly
|
||||
const
|
||||
|
Loading…
x
Reference in New Issue
Block a user