debugging metrics

This commit is contained in:
benbierens 2023-07-11 15:36:24 +02:00
parent ce6483e328
commit e664591596
No known key found for this signature in database
GPG Key ID: FE44815D96D0A1AA
2 changed files with 7 additions and 9 deletions

View File

@ -23,6 +23,8 @@ when defined(chronosDurationThreshold):
import pkg/metrics
declareGauge(chronosCallbackDuration, "chronos callback duration")
declareGauge(chronosConstant, "chronos constant")
declareCounter(chronosCallbackCounter, "chronos callback counter")
export Port, SocketFlag
export timer
@ -226,9 +228,6 @@ type
const chronosDurationThreshold {.intdefine.} = 0
template newAsyncCallback*(cbFunc: CallbackFunc, udataPtr: pointer = nil): AsyncCallback =
# when defined(chronosDurationThreshold):
# AsyncCallback(function: cbFunc, udata: udataPtr, location: getStackTrace())
# else:
AsyncCallback(function: cbFunc, udata: udataPtr)
when defined(chronosDurationThreshold):
@ -337,7 +336,10 @@ template processCallbacks(loop: untyped) =
durationNs = getMonoTime().ticks - startTime
durationUs = durationNs div 1000
chronosCallbackDuration.set(durationUs.int64)
chronosCallbackDuration.set(durationNs)
chronosConstant.set(123)
chronosCallbackCounter.inc()
if durationUs > chronosDurationThreshold:
# callable.location*: array[2, ptr SrcLoc]

View File

@ -17,7 +17,6 @@ type
procedure*: cstring
file*: cstring
line*: int
trace*: cstring
proc `$`*(loc: ptr SrcLoc): string =
var res = $loc.file
@ -29,15 +28,12 @@ proc `$`*(loc: ptr SrcLoc): string =
res.add("[unspecified]")
else:
res.add($loc.procedure)
res.add("[")
res.add($loc.trace)
res.add("]")
res
proc srcLocImpl(procedure: static string,
file: static string, line: static int): ptr SrcLoc =
var loc {.global.} = SrcLoc(
file: cstring(file), line: line, procedure: procedure, trace: "a"
file: cstring(file), line: line, procedure: procedure
)
return addr(loc)