2024-02-29 17:55:45 -03:00
|
|
|
import ./[profiler, events]
|
|
|
|
|
|
2024-03-01 13:44:06 -03:00
|
|
|
export
|
|
|
|
|
Event, ExtendedFutureState, ProfilerState, MetricsTotals, AggregateMetrics,
|
|
|
|
|
FutureType, execTimeWithChildren
|
2024-02-29 20:54:00 -03:00
|
|
|
|
2024-02-29 17:55:45 -03:00
|
|
|
var profilerInstance {.threadvar.}: ProfilerState
|
|
|
|
|
|
2024-03-01 13:44:06 -03:00
|
|
|
proc getMetrics*(): MetricsTotals =
|
2024-02-29 17:55:45 -03:00
|
|
|
## Returns the `MetricsTotals` for the event loop running in the
|
|
|
|
|
## current thread.
|
|
|
|
|
result = profilerInstance.metrics
|
|
|
|
|
|
2024-03-07 14:34:13 -03:00
|
|
|
template enableProfiling*(callback: EventCallback) =
|
2024-02-29 17:55:45 -03:00
|
|
|
## Enables profiling for the the event loop running in the current thread.
|
2024-03-01 09:08:48 -03:00
|
|
|
## The client may optionally supply a callback to be notified of `Future`
|
|
|
|
|
## events.
|
2024-03-01 14:22:19 -03:00
|
|
|
attachMonitoring(
|
2024-03-07 14:34:13 -03:00
|
|
|
proc(e: Event) {.nimcall, gcsafe, raises: [].} =
|
2024-03-01 09:08:48 -03:00
|
|
|
profilerInstance.processEvent(e)
|
|
|
|
|
callback(e)
|
|
|
|
|
)
|
2024-03-07 14:34:13 -03:00
|
|
|
|
|
|
|
|
template enableProfiling*() =
|
|
|
|
|
attachMonitoring(
|
|
|
|
|
proc(e: Event) {.nimcall, gcsafe, raises: [].} =
|
|
|
|
|
profilerInstance.processEvent(e)
|
|
|
|
|
)
|