add tests to main test suite, add global async profiler info collector

This commit is contained in:
gmega 2023-11-06 18:44:08 -03:00
parent eab506949d
commit c809af7dc7
No known key found for this signature in database
GPG Key ID: FFD8DAF00660270F
4 changed files with 18 additions and 10 deletions

View File

@ -8,7 +8,7 @@ import metrics
when defined(metrics):
type
ProfilerInfo* = ref object of Gauge
AsyncProfilerInfo* = ref object of Gauge
perfSampler: PerfSampler
k: int
@ -17,14 +17,14 @@ when defined(metrics):
ProfilerMetric = (SrcLoc, OverallMetrics)
proc newCollector*(
ProfilerInfo: typedesc,
AsyncProfilerInfo: typedesc,
name: string,
help: string,
perfSampler: PerfSampler,
k: int = 10,
registry: Registry = defaultRegistry,
): ProfilerInfo =
result = ProfilerInfo.newCollector(
): AsyncProfilerInfo =
result = AsyncProfilerInfo.newCollector(
name = name, help = help, registry = registry)
result.perfSampler = perfSampler
result.k = k
@ -33,7 +33,7 @@ when defined(metrics):
float64 = duration.nanoseconds.float64
proc collectSlowestProcs(
self: ProfilerInfo,
self: AsyncProfilerInfo,
profilerMetrics: seq[ProfilerMetric],
prometheusMetrics: var Metrics,
timestampMillis: int64,
@ -82,7 +82,7 @@ when defined(metrics):
"max_single_exec_time", metrics.maxSingleTime, prometheusMetrics)
proc collectOutlierMetrics(
self: ProfilerInfo,
self: AsyncProfilerInfo,
profilerMetrics: seq[ProfilerMetric],
prometheusMetrics: var Metrics,
timestampMillis: int64,
@ -112,13 +112,12 @@ when defined(metrics):
timestamp: timestampMillis,
))
method collect*(self: ProfilerInfo): Metrics =
method collect*(self: AsyncProfilerInfo): Metrics =
let now = times.getTime().toMilliseconds()
var prometheusMetrics = Metrics()
prometheusMetrics[@[]] = newSeq[Metric]()
# Samples the underlying metrics and orders pairs by total execution time.
var currentMetrics = self.
perfSampler().
pairs.
@ -140,3 +139,7 @@ when defined(metrics):
prometheusMetrics
var asyncProfilerInfo* {.global.} = AsyncProfilerInfo.newCollector(
"async_profiler_info", "Async profiler info",
perfSampler = getFutureSummaryMetrics
)

View File

@ -5,5 +5,6 @@ import ./utils/testasyncstatemachine
import ./utils/testtimer
import ./utils/testthen
import ./utils/testtrackedfutures
import ./utils/testasyncprofiler
{.warning[UnusedImport]: off.}

View File

@ -52,7 +52,7 @@ checksuite "asyncprofiler metrics collector":
test "should keep track of basic worst-case exec time stats":
var registry = newRegistry()
var collector = ProfilerInfo.newCollector(
var collector = AsyncProfilerInfo.newCollector(
name = "profiling_metrics",
help = "Metrics from the profiler",
registry = registry,
@ -64,7 +64,7 @@ checksuite "asyncprofiler metrics collector":
test "should create labeled series for the k slowest procs in terms of totalExecTime":
var registry = newRegistry()
var collector = ProfilerInfo.newCollector(
var collector = AsyncProfilerInfo.newCollector(
name = "profiling_metrics",
help = "Metrics from the profiler",
registry = registry,

View File

@ -0,0 +1,4 @@
import ./asyncprofiler/testserialization
import ./asyncprofiler/testmetricscollector
{.warning[UnusedImport]: off.}