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.
This commit is contained in:
Carlos Bermudez Porto 2025-11-24 15:53:02 -03:00 committed by Felix Lange
parent 6c4abe90a2
commit 6c02ef5586
2 changed files with 23 additions and 3 deletions

View file

@ -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,

View file

@ -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 {