revert threadvars and add initialization to collector global instance

This commit is contained in:
gmega 2023-11-08 19:53:26 -03:00
parent f048404cb7
commit b795d8a3f5
No known key found for this signature in database
GPG Key ID: FFD8DAF00660270F
2 changed files with 9 additions and 12 deletions

View File

@ -33,9 +33,9 @@ type
ChangeListener* = proc (): void {.raises: [].}
var
perFutureMetrics {.threadvar.}: Table[uint, FutureMetrics]
futureSummaryMetrics {.threadvar.}: MetricsSummary
onChange {.threadvar.}: ChangeListener
perFutureMetrics: Table[uint, FutureMetrics]
futureSummaryMetrics: MetricsSummary
onChange: ChangeListener
proc getFutureSummaryMetrics*(): MetricsSummary {.gcsafe.} =
## get a copy of the table of summary metrics for all futures.

View File

@ -19,7 +19,7 @@ when defined(metrics):
PerfSampler = proc (): MetricsSummary {.raises: [].}
Clock = proc(): Time {.raises: [].}
Clock = proc (): Time {.raises: [].}
ProfilerMetric = (SrcLoc, OverallMetrics)
@ -181,15 +181,12 @@ when defined(metrics):
resetMetric(chronos_largest_exec_time_total)
resetMetric(chronos_largest_exec_time_max)
var asyncProfilerInfo* {.threadvar.}: AsyncProfilerInfo
proc initDefault(AsyncProfilerInfo: typedesc): void =
asyncProfilerInfo = AsyncProfilerInfo.newCollector(
perfSampler = asyncprofiler.getFutureSummaryMetrics,
var asyncProfilerInfo* {.global.}: AsyncProfilerInfo = AsyncProfilerInfo.newCollector(
perfSampler = getFutureSummaryMetrics,
k = 10,
# We want to collect metrics every 5 seconds.
sampleInterval = times.milliseconds(5 * 1000),
clock = proc (): Time = time.getTime(),
sampleInterval = initDuration(seconds = 5),
clock = proc (): Time = getTime(),
)
setChangeCallback(asyncProfilerInfo)
setChangeCallback(proc (): void = asyncProfilerInfo.collect())