26 lines
822 B
Nim
Raw Normal View History

2024-02-29 17:55:45 -03:00
import ./[profiler, events]
2024-02-29 20:54:00 -03:00
export Event, ExtendedFutureState, ProfilerState, MetricsTotals,
AggregateMetrics, FutureType, execTimeWithChildren
2024-02-29 17:55:45 -03:00
var profilerInstance {.threadvar.}: ProfilerState
proc getMetrics*(): MetricsTotals =
## Returns the `MetricsTotals` for the event loop running in the
## current thread.
result = profilerInstance.metrics
proc enableProfiling*(callback: EventCallback = nil) =
2024-02-29 17:55:45 -03:00
## 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.
enableMonitoring(
if (isNil(callback)):
proc(e: Event) {.nimcall.} =
profilerInstance.processEvent(e)
else:
proc (e: Event) {.nimcall.} =
profilerInstance.processEvent(e)
callback(e)
)