mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-03 05:28:38 +00:00
cmd/geth: add pprof
This commit is contained in:
parent
ac46d51483
commit
88b6a68aaa
1 changed files with 21 additions and 7 deletions
|
|
@ -22,9 +22,12 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
_ "net/http/pprof"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"runtime"
|
||||||
"slices"
|
"slices"
|
||||||
"sort"
|
"sort"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
@ -101,17 +104,17 @@ In other words, this command does the snapshot to trie conversion.
|
||||||
Name: "keep",
|
Name: "keep",
|
||||||
Usage: "Keep the checkpoint directory after the run (debugging)",
|
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: `
|
Description: `
|
||||||
geth snapshot generate-trie [<root>]
|
geth snapshot generate-trie [<root>]
|
||||||
|
|
||||||
Takes a pebble checkpoint of the chaindata (hard-linked SST files, near-zero
|
Runs triedb.GenerateTrie against a hard-linked pebble checkpoint of the
|
||||||
disk usage and near-instant) and runs triedb.GenerateTrie against the
|
chaindata. Checkpoint is removed on exit unless --keep is set. Defaults
|
||||||
checkpoint. The source datadir is opened read-only for the checkpoint and
|
to the snapshot root if <root> is not given.
|
||||||
never written to. The checkpoint is removed on exit unless --keep is set,
|
|
||||||
including on Ctrl-C.
|
|
||||||
|
|
||||||
If <root> is not given, the head block's root is used.
|
|
||||||
`,
|
`,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
@ -327,6 +330,17 @@ func benchGenerateTrie(ctx *cli.Context) error {
|
||||||
stack, _ := makeConfigNode(ctx)
|
stack, _ := makeConfigNode(ctx)
|
||||||
defer stack.Close()
|
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).
|
// Resolve source chaindata path (handles network-specific subdirs).
|
||||||
srcDir := stack.ResolvePath("chaindata")
|
srcDir := stack.ResolvePath("chaindata")
|
||||||
if fi, err := os.Stat(srcDir); err != nil {
|
if fi, err := os.Stat(srcDir); err != nil {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue