feat: enable chronos profiling

This commit is contained in:
gmega 2025-02-20 18:13:54 -03:00
parent 44981d24d0
commit 3fde92b120
No known key found for this signature in database
GPG Key ID: 6290D34EAD824B18
6 changed files with 28 additions and 2 deletions

5
.gitmodules vendored
View File

@ -77,7 +77,7 @@
path = vendor/nim-chronos
url = https://github.com/status-im/nim-chronos.git
ignore = untracked
branch = master
branch = feature/profiler-v4
[submodule "vendor/nim-faststreams"]
path = vendor/nim-faststreams
url = https://github.com/status-im/nim-faststreams.git
@ -221,3 +221,6 @@
[submodule "vendor/nph"]
path = vendor/nph
url = https://github.com/arnetheduck/nph.git
[submodule "vendor/nim-chroprof"]
path = vendor/nim-chroprof
url = git@github.com:codex-storage/nim-chroprof.git

View File

@ -20,6 +20,7 @@ import std/strutils
import std/typetraits
import pkg/chronos
import pkg/chronos/config
import pkg/chronicles/helpers
import pkg/chronicles/topics_registry
import pkg/confutils/defs
@ -35,6 +36,10 @@ import pkg/ethers
import pkg/questionable
import pkg/questionable/results
when chronosProfiling:
import pkg/chroprof
import pkg/chroprof/collector
import ./codextypes
import ./discovery
import ./logutils
@ -144,6 +149,12 @@ type
name: "data-dir"
.}: OutDir
profilerMaxMetrics* {.
desc: "Maximum number of metrics to export to Prometheus.",
defaultValue: 100,
name: "profiler-max-metrics"
.}: int
listenAddrs* {.
desc: "Multi Addresses to listen on",
defaultValue:
@ -777,11 +788,17 @@ proc setupLogging*(conf: CodexConf) =
quit QuitFailure
proc setupMetrics*(config: CodexConf) =
when chronosProfiling:
enableProfiling()
if config.metricsEnabled:
let metricsAddress = config.metricsAddress
notice "Starting metrics HTTP server",
url = "http://" & $metricsAddress & ":" & $config.metricsPort & "/metrics"
try:
when chronosProfiling:
enableProfilerMetrics(k = config.profilerMaxMetrics)
startMetricsHttpServer($metricsAddress, config.metricsPort)
except CatchableError as exc:
raiseAssert exc.msg

View File

@ -149,6 +149,8 @@ switch("define", "nimOldCaseObjects")
# Enable compat mode for Chronos V4
switch("define", "chronosHandleException")
switch("define", "chronosProfiling")
# begin Nimble config (version 1)
when system.fileExists("nimble.paths"):
include "nimble.paths"

View File

@ -12,3 +12,6 @@ when not defined(chronicles_log_level):
"chronicles_sinks:textlines[dynamic]" # allow logs to be filtered at runtime
--"import":
"logging" # ensure that logging is ignored at runtime
--undef:
chronosProfiling

2
vendor/nim-chronos vendored

@ -1 +1 @@
Subproject commit c04576d829b8a0a1b12baaa8bc92037501b3a4a0
Subproject commit f85a3b43c2606d8966bb1eb6e36de10c7b4aab94

1
vendor/nim-chroprof vendored Submodule

@ -0,0 +1 @@
Subproject commit 95da0353d276f688926926d796439b24874ccf44