From c809af7dc7d5cf93a1e1d8cd7a4c34bb2e9bd880 Mon Sep 17 00:00:00 2001 From: gmega Date: Mon, 6 Nov 2023 18:44:08 -0300 Subject: [PATCH] add tests to main test suite, add global async profiler info collector --- .../utils/asyncprofiler/metricscollector.nim | 19 +++++++++++-------- tests/codex/testutils.nim | 1 + .../asyncprofiler/testmetricscollector.nim | 4 ++-- tests/codex/utils/testasyncprofiler.nim | 4 ++++ 4 files changed, 18 insertions(+), 10 deletions(-) create mode 100644 tests/codex/utils/testasyncprofiler.nim diff --git a/codex/utils/asyncprofiler/metricscollector.nim b/codex/utils/asyncprofiler/metricscollector.nim index 3a6f4f5c..1333b3ff 100644 --- a/codex/utils/asyncprofiler/metricscollector.nim +++ b/codex/utils/asyncprofiler/metricscollector.nim @@ -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 + ) diff --git a/tests/codex/testutils.nim b/tests/codex/testutils.nim index 937a6e86..b7d8b4a3 100644 --- a/tests/codex/testutils.nim +++ b/tests/codex/testutils.nim @@ -5,5 +5,6 @@ import ./utils/testasyncstatemachine import ./utils/testtimer import ./utils/testthen import ./utils/testtrackedfutures +import ./utils/testasyncprofiler {.warning[UnusedImport]: off.} diff --git a/tests/codex/utils/asyncprofiler/testmetricscollector.nim b/tests/codex/utils/asyncprofiler/testmetricscollector.nim index d62fd130..8cc5e7c1 100644 --- a/tests/codex/utils/asyncprofiler/testmetricscollector.nim +++ b/tests/codex/utils/asyncprofiler/testmetricscollector.nim @@ -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, diff --git a/tests/codex/utils/testasyncprofiler.nim b/tests/codex/utils/testasyncprofiler.nim new file mode 100644 index 00000000..a29c14ff --- /dev/null +++ b/tests/codex/utils/testasyncprofiler.nim @@ -0,0 +1,4 @@ +import ./asyncprofiler/testserialization +import ./asyncprofiler/testmetricscollector + +{.warning[UnusedImport]: off.}