diff --git a/.gitmodules b/.gitmodules index ece88749..d7382f6c 100644 --- a/.gitmodules +++ b/.gitmodules @@ -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 diff --git a/codex/conf.nim b/codex/conf.nim index 2a859efb..65d2c328 100644 --- a/codex/conf.nim +++ b/codex/conf.nim @@ -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 diff --git a/config.nims b/config.nims index 05a31fff..c5a4a744 100644 --- a/config.nims +++ b/config.nims @@ -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" diff --git a/tests/config.nims b/tests/config.nims index 8ae00806..81a89944 100644 --- a/tests/config.nims +++ b/tests/config.nims @@ -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 diff --git a/vendor/nim-chronos b/vendor/nim-chronos index c04576d8..f85a3b43 160000 --- a/vendor/nim-chronos +++ b/vendor/nim-chronos @@ -1 +1 @@ -Subproject commit c04576d829b8a0a1b12baaa8bc92037501b3a4a0 +Subproject commit f85a3b43c2606d8966bb1eb6e36de10c7b4aab94 diff --git a/vendor/nim-chroprof b/vendor/nim-chroprof new file mode 160000 index 00000000..95da0353 --- /dev/null +++ b/vendor/nim-chroprof @@ -0,0 +1 @@ +Subproject commit 95da0353d276f688926926d796439b24874ccf44