mirror of
https://github.com/logos-storage/nim-chroprof.git
synced 2026-01-25 00:33:08 +00:00
attempt to wire up threshold
This commit is contained in:
parent
cd4a3adfb1
commit
f12bded51e
@ -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)
|
||||
|
||||
@ -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
|
||||
)
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user