From 6c02ef55863e2a75ca70095f0512273caa354801 Mon Sep 17 00:00:00 2001 From: Carlos Bermudez Porto Date: Mon, 24 Nov 2025 15:53:02 -0300 Subject: [PATCH] internal/debug: enhance pyroscope profiler with tag support - Updated StartPyroscopeProfiler to accept a map of tags for profiling data. - Introduced a new command-line flag for specifying comma-separated key=value tags. - Modified Setup function to parse and pass tags to the profiler, improving profiling data granularity. --- internal/debug/api.go | 7 +++++-- internal/debug/flags.go | 19 ++++++++++++++++++- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/internal/debug/api.go b/internal/debug/api.go index 14dbe71c7a..af02d6f03e 100644 --- a/internal/debug/api.go +++ b/internal/debug/api.go @@ -148,7 +148,10 @@ func (l *pyroscopeLogger) Errorf(format string, v ...interface{}) { } // StartPyroscopeProfiler starts the Pyroscope profiler for later use -func (h *HandlerT) StartPyroscopeProfiler(server string) error { +func (h *HandlerT) StartPyroscopeProfiler( + server string, + tags map[string]string, +) error { h.mu.Lock() defer h.mu.Unlock() if h.profiler != nil { @@ -160,7 +163,7 @@ func (h *HandlerT) StartPyroscopeProfiler(server string) error { ApplicationName: "geth", ServerAddress: server, Logger: &pyroscopeLogger{Logger: log.Root().With("module", "pyroscope")}, - // Tags: nil, + Tags: tags, ProfileTypes: []pyroscope.ProfileType{ // Enabling all profile types pyroscope.ProfileCPU, diff --git a/internal/debug/flags.go b/internal/debug/flags.go index 98de5565c2..850acbdedf 100644 --- a/internal/debug/flags.go +++ b/internal/debug/flags.go @@ -26,6 +26,7 @@ import ( "os" "path/filepath" "runtime" + "strings" "github.com/ethereum/go-ethereum/internal/flags" "github.com/ethereum/go-ethereum/log" @@ -152,6 +153,12 @@ var ( Value: "http://localhost:4040", Category: flags.LoggingCategory, } + pyroscopeTagsFlag = &cli.StringFlag{ + Name: "pyroscope.tags", + Usage: "Comma separated list of key=value tags to add to profiling data", + Value: "", + Category: flags.LoggingCategory, + } ) // Flags holds all command-line flags required for debugging. @@ -317,7 +324,17 @@ func Setup(ctx *cli.Context) error { if ctx.Bool(pyroscopeFlag.Name) { pyroscopeServer := ctx.String(pyroscopeServerFlag.Name) - Handler.StartPyroscopeProfiler(pyroscopeServer) + rawTags := ctx.String(pyroscopeTagsFlag.Name) + tags := make(map[string]string) + for _, tag := range strings.Split(rawTags, ",") { + kv := strings.Split(tag, "=") + // Ignore invalid tags + if len(kv) == 2 { + tags[kv[0]] = kv[1] + } + } + + Handler.StartPyroscopeProfiler(pyroscopeServer, tags) } if len(logFile) > 0 || rotation {