mirror of
https://github.com/status-im/nim-codex.git
synced 2025-02-23 16:08:40 +00:00
add tests to main test suite, add global async profiler info collector
This commit is contained in:
parent
eab506949d
commit
c809af7dc7
@ -8,7 +8,7 @@ import metrics
|
|||||||
|
|
||||||
when defined(metrics):
|
when defined(metrics):
|
||||||
type
|
type
|
||||||
ProfilerInfo* = ref object of Gauge
|
AsyncProfilerInfo* = ref object of Gauge
|
||||||
perfSampler: PerfSampler
|
perfSampler: PerfSampler
|
||||||
k: int
|
k: int
|
||||||
|
|
||||||
@ -17,14 +17,14 @@ when defined(metrics):
|
|||||||
ProfilerMetric = (SrcLoc, OverallMetrics)
|
ProfilerMetric = (SrcLoc, OverallMetrics)
|
||||||
|
|
||||||
proc newCollector*(
|
proc newCollector*(
|
||||||
ProfilerInfo: typedesc,
|
AsyncProfilerInfo: typedesc,
|
||||||
name: string,
|
name: string,
|
||||||
help: string,
|
help: string,
|
||||||
perfSampler: PerfSampler,
|
perfSampler: PerfSampler,
|
||||||
k: int = 10,
|
k: int = 10,
|
||||||
registry: Registry = defaultRegistry,
|
registry: Registry = defaultRegistry,
|
||||||
): ProfilerInfo =
|
): AsyncProfilerInfo =
|
||||||
result = ProfilerInfo.newCollector(
|
result = AsyncProfilerInfo.newCollector(
|
||||||
name = name, help = help, registry = registry)
|
name = name, help = help, registry = registry)
|
||||||
result.perfSampler = perfSampler
|
result.perfSampler = perfSampler
|
||||||
result.k = k
|
result.k = k
|
||||||
@ -33,7 +33,7 @@ when defined(metrics):
|
|||||||
float64 = duration.nanoseconds.float64
|
float64 = duration.nanoseconds.float64
|
||||||
|
|
||||||
proc collectSlowestProcs(
|
proc collectSlowestProcs(
|
||||||
self: ProfilerInfo,
|
self: AsyncProfilerInfo,
|
||||||
profilerMetrics: seq[ProfilerMetric],
|
profilerMetrics: seq[ProfilerMetric],
|
||||||
prometheusMetrics: var Metrics,
|
prometheusMetrics: var Metrics,
|
||||||
timestampMillis: int64,
|
timestampMillis: int64,
|
||||||
@ -82,7 +82,7 @@ when defined(metrics):
|
|||||||
"max_single_exec_time", metrics.maxSingleTime, prometheusMetrics)
|
"max_single_exec_time", metrics.maxSingleTime, prometheusMetrics)
|
||||||
|
|
||||||
proc collectOutlierMetrics(
|
proc collectOutlierMetrics(
|
||||||
self: ProfilerInfo,
|
self: AsyncProfilerInfo,
|
||||||
profilerMetrics: seq[ProfilerMetric],
|
profilerMetrics: seq[ProfilerMetric],
|
||||||
prometheusMetrics: var Metrics,
|
prometheusMetrics: var Metrics,
|
||||||
timestampMillis: int64,
|
timestampMillis: int64,
|
||||||
@ -112,13 +112,12 @@ when defined(metrics):
|
|||||||
timestamp: timestampMillis,
|
timestamp: timestampMillis,
|
||||||
))
|
))
|
||||||
|
|
||||||
method collect*(self: ProfilerInfo): Metrics =
|
method collect*(self: AsyncProfilerInfo): Metrics =
|
||||||
let now = times.getTime().toMilliseconds()
|
let now = times.getTime().toMilliseconds()
|
||||||
|
|
||||||
var prometheusMetrics = Metrics()
|
var prometheusMetrics = Metrics()
|
||||||
prometheusMetrics[@[]] = newSeq[Metric]()
|
prometheusMetrics[@[]] = newSeq[Metric]()
|
||||||
|
|
||||||
# Samples the underlying metrics and orders pairs by total execution time.
|
|
||||||
var currentMetrics = self.
|
var currentMetrics = self.
|
||||||
perfSampler().
|
perfSampler().
|
||||||
pairs.
|
pairs.
|
||||||
@ -140,3 +139,7 @@ when defined(metrics):
|
|||||||
|
|
||||||
prometheusMetrics
|
prometheusMetrics
|
||||||
|
|
||||||
|
var asyncProfilerInfo* {.global.} = AsyncProfilerInfo.newCollector(
|
||||||
|
"async_profiler_info", "Async profiler info",
|
||||||
|
perfSampler = getFutureSummaryMetrics
|
||||||
|
)
|
||||||
|
@ -5,5 +5,6 @@ import ./utils/testasyncstatemachine
|
|||||||
import ./utils/testtimer
|
import ./utils/testtimer
|
||||||
import ./utils/testthen
|
import ./utils/testthen
|
||||||
import ./utils/testtrackedfutures
|
import ./utils/testtrackedfutures
|
||||||
|
import ./utils/testasyncprofiler
|
||||||
|
|
||||||
{.warning[UnusedImport]: off.}
|
{.warning[UnusedImport]: off.}
|
||||||
|
@ -52,7 +52,7 @@ checksuite "asyncprofiler metrics collector":
|
|||||||
|
|
||||||
test "should keep track of basic worst-case exec time stats":
|
test "should keep track of basic worst-case exec time stats":
|
||||||
var registry = newRegistry()
|
var registry = newRegistry()
|
||||||
var collector = ProfilerInfo.newCollector(
|
var collector = AsyncProfilerInfo.newCollector(
|
||||||
name = "profiling_metrics",
|
name = "profiling_metrics",
|
||||||
help = "Metrics from the profiler",
|
help = "Metrics from the profiler",
|
||||||
registry = registry,
|
registry = registry,
|
||||||
@ -64,7 +64,7 @@ checksuite "asyncprofiler metrics collector":
|
|||||||
|
|
||||||
test "should create labeled series for the k slowest procs in terms of totalExecTime":
|
test "should create labeled series for the k slowest procs in terms of totalExecTime":
|
||||||
var registry = newRegistry()
|
var registry = newRegistry()
|
||||||
var collector = ProfilerInfo.newCollector(
|
var collector = AsyncProfilerInfo.newCollector(
|
||||||
name = "profiling_metrics",
|
name = "profiling_metrics",
|
||||||
help = "Metrics from the profiler",
|
help = "Metrics from the profiler",
|
||||||
registry = registry,
|
registry = registry,
|
||||||
|
4
tests/codex/utils/testasyncprofiler.nim
Normal file
4
tests/codex/utils/testasyncprofiler.nim
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
import ./asyncprofiler/testserialization
|
||||||
|
import ./asyncprofiler/testmetricscollector
|
||||||
|
|
||||||
|
{.warning[UnusedImport]: off.}
|
Loading…
x
Reference in New Issue
Block a user