allow configuration of profiler output volume from CLI option

This commit is contained in:
gmega 2023-11-09 12:42:15 -03:00
parent e70c40cb45
commit 3c6ef3019f
No known key found for this signature in database
GPG Key ID: FFD8DAF00660270F
4 changed files with 18 additions and 20 deletions

View File

@ -19,13 +19,11 @@ import pkg/confutils/toml/std/uri as confTomlUri
import pkg/toml_serialization
import pkg/libp2p
when defined(chronosFuturesInstrumentation):
import ./codex/utils/asyncprofiler
import ./codex/conf
import ./codex/codex
import ./codex/units
import ./codex/utils/keyutils
import ./codex/utils/asyncprofiler
export codex, conf, libp2p, chronos, chronicles
@ -57,6 +55,11 @@ when isMainModule:
config.setupLogging()
config.setupMetrics()
# TODO this should not be here, but currently can't have it in setupMetrics
# or we get a circular import.
when chronosFuturesInstrumentation:
AsyncProfilerInfo.initDefault(k = config.profilerMaxMetrics)
case config.cmd:
of StartUpCommand.noCommand:
@ -109,18 +112,6 @@ when isMainModule:
notice "Stopping Codex"
when defined(chronosFuturesInstrumentation):
let metrics = getFutureSummaryMetrics()
for (k,v) in metrics.pairs():
let count = v.count
if count > 0:
echo ""
echo "metric: ", $k
echo "count: ", count
echo "avg execTime:\t", v.totalExecTime div count, "\ttotal: ", v.totalExecTime
echo "avg wallTime:\t", v.totalWallTime div count, "\ttotal: ", v.totalWallTime
echo "avg runTime:\t", v.totalRunTime div count, "\ttotal: ", v.totalRunTime
try:
setControlCHook(controlCHandler)
except Exception as exc: # TODO Exception

View File

@ -106,6 +106,11 @@ type
abbr: "d"
name: "data-dir" }: OutDir
profilerMaxMetrics* {.
desc: "Maximum number of metrics to export to Prometheus."
defaultValue: 100
name: "profiler-max-metrics" }: int
case cmd* {.
command
defaultValue: noCommand }: StartUpCommand

View File

@ -181,12 +181,15 @@ when defined(metrics):
resetMetric(chronos_largest_exec_time_total)
resetMetric(chronos_largest_exec_time_max)
var asyncProfilerInfo* {.global.}: AsyncProfilerInfo = AsyncProfilerInfo.newCollector(
var asyncProfilerInfo* {.global.}: AsyncProfilerInfo
proc initDefault*(AsyncProfilerInfo: typedesc, k: int) =
asyncProfilerInfo = AsyncProfilerInfo.newCollector(
perfSampler = getFutureSummaryMetrics,
k = 10,
k = k,
# We want to collect metrics every 5 seconds.
sampleInterval = initDuration(seconds = 5),
clock = proc (): Time = getTime(),
)
setChangeCallback(proc (): void = asyncProfilerInfo.collect())
setChangeCallback(proc (): void = asyncProfilerInfo.collect())

View File

@ -16,9 +16,8 @@ import pkg/codex/chunker
import pkg/codex/discovery
import pkg/codex/blocktype
import pkg/codex/utils/asyncheapqueue
import pkg/codex/utils/asyncprofiler
when defined(chronosFuturesInstrumentation):
import pkg/codex/utils/asyncprofiler
import ../../helpers
import ../../examples