Skip to content

Commit

Permalink
add tests to main test suite, add global async profiler info collector
Browse files Browse the repository at this point in the history
  • Loading branch information
gmega committed Nov 6, 2023
1 parent 1b2ff0e commit acbd13b
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
19 changes: 11 additions & 8 deletions codex/utils/asyncprofiler/metricscollector.nim
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import metrics

when defined(metrics):
type
ProfilerInfo* = ref object of Gauge
AsyncProfilerInfo* = ref object of Gauge
perfSampler: PerfSampler
k: int

Expand All @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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.
Expand All @@ -140,3 +139,7 @@ when defined(metrics):

prometheusMetrics

var asyncProfilerInfo* {.global.} = AsyncProfilerInfo.newCollector(
"async_profiler_info", "Async profiler info",
perfSampler = getFutureSummaryMetrics
)
1 change: 1 addition & 0 deletions tests/codex/testutils.nim
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ import ./utils/testasyncstatemachine
import ./utils/testtimer
import ./utils/testthen
import ./utils/testtrackedfutures
import ./utils/testasyncprofiler

{.warning[UnusedImport]: off.}
4 changes: 2 additions & 2 deletions tests/codex/utils/asyncprofiler/testmetricscollector.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions tests/codex/utils/testasyncprofiler.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import ./asyncprofiler/testserialization
import ./asyncprofiler/testmetricscollector

{.warning[UnusedImport]: off.}

0 comments on commit acbd13b

Please sign in to comment.