attempt to wire up threshold

This commit is contained in:
ThatBen 2025-05-07 17:00:24 +02:00
parent cd4a3adfb1
commit f12bded51e
No known key found for this signature in database
GPG Key ID: E020A7DDCD52E1AB
3 changed files with 16 additions and 19 deletions

View File

@ -11,22 +11,18 @@ proc getMetrics*(): MetricsTotals =
## current thread.
result = profilerInstance.metrics
template enableProfiling*(callback: EventCallback, maxExecThreshold: Duration) =
template enableProfiling*(callback: EventCallback, threshold: Duration) =
## Enables profiling for the the event loop running in the current thread.
## The client may optionally supply a callback to be notified of `Future`
## events.
attachMonitoring(
proc(e: Event) {.nimcall, gcsafe, raises: [].} =
profilerInstance.processEvent(e)
callback(e)
,
maxExecThreshold = maxExecThreshold
)
profilerInstance.maxExecThreshold = threshold
proc onProfilerEvent(e: Event) {.nimcall, gcsafe, raises: [].} =
profilerInstance.processEvent(e)
callback(e)
attachMonitoring(onProfilerEvent)
template enableProfiling*(maxExecThreshold: Duration) =
attachMonitoring(
proc(e: Event) {.nimcall, gcsafe, raises: [].} =
profilerInstance.processEvent(e)
,
maxExecThreshold = maxExecThreshold
)
template enableProfiling*(threshold: Duration) =
profilerInstance.maxExecThreshold = threshold
proc onProfilerEvent(e: Event) {.nimcall, gcsafe, raises: [].} =
profilerInstance.processEvent(e)
attachMonitoring(onProfilerEvent)

View File

@ -173,7 +173,7 @@ when defined(metrics):
var asyncProfilerInfo* {.global.}: ChronosProfilerInfo
proc enableProfilerMetrics*(k: int, maxExecThreshold: Duration) =
proc enableProfilerMetrics*(k: int, maxExecThreshold: timer.Duration) =
assert threadId() == moduleInitThread,
"You cannot call enableProfilerMetrics() from a thread other than" &
" the one that initialized the metricscolletor module."
@ -194,5 +194,5 @@ when defined(metrics):
if e.newState == ExtendedFutureState.Completed:
asyncProfilerInfo.collect()
,
maxExecThreshold = maxExecThreshold
maxExecThreshold
)

View File

@ -70,6 +70,7 @@ type
MetricsTotals* = Table[FutureType, AggregateMetrics]
ProfilerState* = object
maxExecThreshold*: Duration
callStack: seq[uint]
partials: Table[uint, PartialMetrics]
metrics*: MetricsTotals
@ -142,9 +143,9 @@ proc aggregatePartial(
self.metrics.withValue(metrics.futureType, aggMetrics):
let execTime = metrics.partialExecTime - metrics.partialChildrenExecOverlap
if execTime > threshold:
if execTime > self.maxExecThreshold:
raiseAssert("Execution time of future is too high (" &
$metrics.futureType & ")" & $execTime)
$metrics.futureType & ") time: " & $execTime & " threshold: " & $self.maxExecThreshold)
aggMetrics.callCount.inc()
aggMetrics.execTime += execTime