Skip to content

Commit 77a6c67

Browse files
committed
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.
1 parent 00a1bfa commit 77a6c67

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

internal/debug/api.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,10 @@ func (l *pyroscopeLogger) Errorf(format string, v ...interface{}) {
148148
}
149149

150150
// StartPyroscopeProfiler starts the Pyroscope profiler for later use
151-
func (h *HandlerT) StartPyroscopeProfiler(server string) error {
151+
func (h *HandlerT) StartPyroscopeProfiler(
152+
server string,
153+
tags map[string]string,
154+
) error {
152155
h.mu.Lock()
153156
defer h.mu.Unlock()
154157
if h.profiler != nil {
@@ -160,7 +163,7 @@ func (h *HandlerT) StartPyroscopeProfiler(server string) error {
160163
ApplicationName: "geth",
161164
ServerAddress: server,
162165
Logger: &pyroscopeLogger{Logger: log.Root().With("module", "pyroscope")},
163-
// Tags: nil,
166+
Tags: tags,
164167
ProfileTypes: []pyroscope.ProfileType{
165168
// Enabling all profile types
166169
pyroscope.ProfileCPU,

internal/debug/flags.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"os"
2727
"path/filepath"
2828
"runtime"
29+
"strings"
2930

3031
"github.com/ethereum/go-ethereum/internal/flags"
3132
"github.com/ethereum/go-ethereum/log"
@@ -152,6 +153,12 @@ var (
152153
Value: "http://localhost:4040",
153154
Category: flags.LoggingCategory,
154155
}
156+
pyroscopeTagsFlag = &cli.StringFlag{
157+
Name: "pyroscope.tags",
158+
Usage: "Comma separated list of key=value tags to add to profiling data",
159+
Value: "",
160+
Category: flags.LoggingCategory,
161+
}
155162
)
156163

157164
// Flags holds all command-line flags required for debugging.
@@ -317,7 +324,17 @@ func Setup(ctx *cli.Context) error {
317324
if ctx.Bool(pyroscopeFlag.Name) {
318325
pyroscopeServer := ctx.String(pyroscopeServerFlag.Name)
319326

320-
Handler.StartPyroscopeProfiler(pyroscopeServer)
327+
rawTags := ctx.String(pyroscopeTagsFlag.Name)
328+
tags := make(map[string]string)
329+
for _, tag := range strings.Split(rawTags, ",") {
330+
kv := strings.Split(tag, "=")
331+
// Ignore invalid tags
332+
if len(kv) == 2 {
333+
tags[kv[0]] = kv[1]
334+
}
335+
}
336+
337+
Handler.StartPyroscopeProfiler(pyroscopeServer, tags)
321338
}
322339

323340
if len(logFile) > 0 || rotation {

0 commit comments

Comments
 (0)