From 88b6a68aaac8f8330c3cb70e3c06ef1ce0950ec3 Mon Sep 17 00:00:00 2001 From: jonny rhea <5555162+jrhea@users.noreply.github.com> Date: Sun, 10 May 2026 14:00:52 -0500 Subject: [PATCH] cmd/geth: add pprof --- cmd/geth/snapshot.go | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/cmd/geth/snapshot.go b/cmd/geth/snapshot.go index e45be54ca3..08454f579e 100644 --- a/cmd/geth/snapshot.go +++ b/cmd/geth/snapshot.go @@ -22,9 +22,12 @@ import ( "encoding/json" "errors" "fmt" + "net/http" + _ "net/http/pprof" "os" "os/signal" "path/filepath" + "runtime" "slices" "sort" "syscall" @@ -101,17 +104,17 @@ In other words, this command does the snapshot to trie conversion. Name: "keep", Usage: "Keep the checkpoint directory after the run (debugging)", }, + &cli.BoolFlag{ + Name: "pprof", + Usage: "Serve pprof profiles on localhost:6060 (block + mutex profiles enabled)", + }, }), Description: ` geth snapshot generate-trie [] -Takes a pebble checkpoint of the chaindata (hard-linked SST files, near-zero -disk usage and near-instant) and runs triedb.GenerateTrie against the -checkpoint. The source datadir is opened read-only for the checkpoint and -never written to. The checkpoint is removed on exit unless --keep is set, -including on Ctrl-C. - -If is not given, the head block's root is used. +Runs triedb.GenerateTrie against a hard-linked pebble checkpoint of the +chaindata. Checkpoint is removed on exit unless --keep is set. Defaults +to the snapshot root if is not given. `, }, { @@ -327,6 +330,17 @@ func benchGenerateTrie(ctx *cli.Context) error { stack, _ := makeConfigNode(ctx) defer stack.Close() + if ctx.Bool("pprof") { + runtime.SetBlockProfileRate(1) + runtime.SetMutexProfileFraction(1) + go func() { + log.Info("pprof listening", "addr", ":6060") + if err := http.ListenAndServe(":6060", nil); err != nil { + log.Warn("pprof server stopped", "err", err) + } + }() + } + // Resolve source chaindata path (handles network-specific subdirs). srcDir := stack.ResolvePath("chaindata") if fi, err := os.Stat(srcDir); err != nil {