Compare commits

...

1 Commits

Author SHA1 Message Date
Manu NALEPA
891e65d81d Add Pyroscope continuous profiling 2026-03-05 11:07:26 +01:00
8 changed files with 79 additions and 0 deletions

View File

@@ -0,0 +1,3 @@
### Added
- Pyroscope continuous profiling support for the beacon node via `--pyroscope`, `--pyroscope-server`, and `--pyroscope-app-name` flags.

View File

@@ -132,6 +132,9 @@ var appFlags = []cli.Flag{
debug.MemProfileRateFlag,
debug.BlockProfileRateFlag,
debug.MutexProfileFractionFlag,
debug.PyroscopeFlag,
debug.PyroscopeServerFlag,
debug.PyroscopeAppNameFlag,
cmd.LogFileName,
cmd.EnableUPnPFlag,
cmd.ConfigFileFlag,

View File

@@ -231,6 +231,9 @@ var appHelpFlagGroups = []flagGroup{
debug.PProfAddrFlag,
debug.PProfFlag,
debug.PProfPortFlag,
debug.PyroscopeFlag,
debug.PyroscopeServerFlag,
debug.PyroscopeAppNameFlag,
flags.SetGCPercent,
},
},

View File

@@ -1349,6 +1349,18 @@ def prysm_deps():
sum = "h1:d2/eIbH9XjD1fFwD5SHv8x168fjbQ9PB8hvs8DSEC08=",
version = "v0.3.1-0.20210208050101-bfb5c8eec0e4",
)
go_repository(
name = "com_github_grafana_pyroscope_go",
importpath = "github.com/grafana/pyroscope-go",
sum = "h1:VWBBlqxjyR0Cwk2W6UrE8CdcdD80GOFNutj0Kb1T8ac=",
version = "v1.2.7",
)
go_repository(
name = "com_github_grafana_pyroscope_go_godeltaprof",
importpath = "github.com/grafana/pyroscope-go/godeltaprof",
sum = "h1:c1Us8i6eSmkW+Ez05d3co8kasnuOY813tbMN8i/a3Og=",
version = "v0.1.9",
)
go_repository(
name = "com_github_graph_gophers_graphql_go",
importpath = "github.com/graph-gophers/graphql-go",

2
go.mod
View File

@@ -28,6 +28,7 @@ require (
github.com/google/gofuzz v1.2.0
github.com/google/uuid v1.6.0
github.com/gostaticanalysis/comment v1.4.2
github.com/grafana/pyroscope-go v1.2.7
github.com/grpc-ecosystem/go-grpc-middleware v1.2.2
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0
github.com/hashicorp/golang-lru v0.5.5-0.20210104140557-80c98217689d
@@ -154,6 +155,7 @@ require (
github.com/google/gopacket v1.1.19 // indirect
github.com/google/pprof v0.0.0-20250202011525-fc3143867406 // indirect
github.com/gorilla/websocket v1.5.3 // indirect
github.com/grafana/pyroscope-go/godeltaprof v0.1.9 // indirect
github.com/graph-gophers/graphql-go v1.3.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.25.1 // indirect
github.com/hashicorp/go-bexpr v0.1.10 // indirect

4
go.sum
View File

@@ -440,6 +440,10 @@ github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/ad
github.com/gostaticanalysis/comment v1.4.2 h1:hlnx5+S2fY9Zo9ePo4AhgYsYHbM2+eAv8m/s1JiCd6Q=
github.com/gostaticanalysis/comment v1.4.2/go.mod h1:KLUTGDv6HOCotCH8h2erHKmpci2ZoR8VPu34YA2uzdM=
github.com/gostaticanalysis/testutil v0.3.1-0.20210208050101-bfb5c8eec0e4/go.mod h1:D+FIZ+7OahH3ePw/izIEeH5I06eKs1IKI4Xr64/Am3M=
github.com/grafana/pyroscope-go v1.2.7 h1:VWBBlqxjyR0Cwk2W6UrE8CdcdD80GOFNutj0Kb1T8ac=
github.com/grafana/pyroscope-go v1.2.7/go.mod h1:o/bpSLiJYYP6HQtvcoVKiE9s5RiNgjYTj1DhiddP2Pc=
github.com/grafana/pyroscope-go/godeltaprof v0.1.9 h1:c1Us8i6eSmkW+Ez05d3co8kasnuOY813tbMN8i/a3Og=
github.com/grafana/pyroscope-go/godeltaprof v0.1.9/go.mod h1:2+l7K7twW49Ct4wFluZD3tZ6e0SjanjcUUBPVD/UuGU=
github.com/graph-gophers/graphql-go v1.3.0 h1:Eb9x/q6MFpCLz7jBCiP/WTxjSDrYLR1QY41SORZyNJ0=
github.com/graph-gophers/graphql-go v1.3.0/go.mod h1:9CQHMSxwO4MprSdzoIEobiHpoLtHm77vfxsvsIN5Vuc=
github.com/gregjones/httpcache v0.0.0-20170920190843-316c5e0ff04e/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA=

View File

@@ -18,6 +18,7 @@ go_library(
importpath = "github.com/OffchainLabs/prysm/v7/runtime/debug",
visibility = ["//visibility:public"],
deps = [
"@com_github_grafana_pyroscope_go//:go_default_library",
"@com_github_prometheus_client_golang//prometheus:go_default_library",
"@com_github_prometheus_client_golang//prometheus/promauto:go_default_library",
"@com_github_sirupsen_logrus//:go_default_library",

View File

@@ -37,6 +37,7 @@ import (
"sync"
"time"
"github.com/grafana/pyroscope-go"
log "github.com/sirupsen/logrus"
"github.com/urfave/cli/v2"
)
@@ -78,6 +79,23 @@ var (
Name: "blockprofilerate",
Usage: "Turns on block profiling with the given rate.",
}
// PyroscopeFlag to enable Pyroscope continuous profiling.
PyroscopeFlag = &cli.BoolFlag{
Name: "pyroscope",
Usage: "Enables Pyroscope continuous profiling.",
}
// PyroscopeServerFlag to specify the Pyroscope server URL.
PyroscopeServerFlag = &cli.StringFlag{
Name: "pyroscope-server",
Usage: "Pyroscope server URL for continuous profiling.",
Value: "http://localhost:4040",
}
// PyroscopeAppNameFlag to specify the application name tag.
PyroscopeAppNameFlag = &cli.StringFlag{
Name: "pyroscope-app-name",
Usage: "Application name tag for Pyroscope profiling.",
Value: "prysm.beacon-chain",
}
)
// HandlerT implements the debugging API.
@@ -323,9 +341,42 @@ func Setup(ctx *cli.Context) error {
address := fmt.Sprintf("%s:%d", ctx.String(PProfAddrFlag.Name), ctx.Int(PProfPortFlag.Name))
startPProf(address)
}
// Pyroscope continuous profiling
if ctx.Bool(PyroscopeFlag.Name) {
startPyroscope(ctx)
}
return nil
}
func startPyroscope(ctx *cli.Context) {
serverAddress := ctx.String(PyroscopeServerFlag.Name)
appName := ctx.String(PyroscopeAppNameFlag.Name)
_, err := pyroscope.Start(pyroscope.Config{
ApplicationName: appName,
ServerAddress: serverAddress,
DisableGCRuns: true,
ProfileTypes: []pyroscope.ProfileType{
pyroscope.ProfileCPU,
pyroscope.ProfileAllocObjects,
pyroscope.ProfileAllocSpace,
pyroscope.ProfileInuseObjects,
pyroscope.ProfileInuseSpace,
pyroscope.ProfileGoroutines,
pyroscope.ProfileMutexCount,
pyroscope.ProfileMutexDuration,
pyroscope.ProfileBlockCount,
pyroscope.ProfileBlockDuration,
},
})
if err != nil {
log.WithError(err).Error("Failed to start Pyroscope profiling")
return
}
log.WithField("server", serverAddress).WithField("app", appName).Info("Started Pyroscope continuous profiling")
}
func startPProf(address string) {
log.WithField("addr", fmt.Sprintf("http://%s/debug/pprof", address)).Info("Starting pprof server")
go func() {