From 35ef74cb96167a100b1a208a5c8dfbe3d0a266a8 Mon Sep 17 00:00:00 2001 From: Valentin Staykov <79150443+V-Staykov@users.noreply.github.com> Date: Wed, 30 Oct 2024 16:02:29 +0200 Subject: [PATCH] fix: enable pprof (#1380) --- cmd/cdk-erigon/main.go | 2 +- turbo/app/make_app_zkevm.go | 66 +++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 turbo/app/make_app_zkevm.go diff --git a/cmd/cdk-erigon/main.go b/cmd/cdk-erigon/main.go index b740856eae9..91364260c23 100644 --- a/cmd/cdk-erigon/main.go +++ b/cmd/cdk-erigon/main.go @@ -35,7 +35,7 @@ func main() { */ }() - app := erigonapp.MakeApp("cdk-erigon", runErigon, erigoncli.DefaultFlags) + app := erigonapp.MakeApp_zkEvm("cdk-erigon", runErigon, erigoncli.DefaultFlags) if err := app.Run(os.Args); err != nil { _, printErr := fmt.Fprintln(os.Stderr, err) if printErr != nil { diff --git a/turbo/app/make_app_zkevm.go b/turbo/app/make_app_zkevm.go new file mode 100644 index 00000000000..190b54b845f --- /dev/null +++ b/turbo/app/make_app_zkevm.go @@ -0,0 +1,66 @@ +// Package app contains framework for building a command-line based Erigon node. +package app + +import ( + "fmt" + + "github.com/ledgerwatch/log/v3" + "github.com/urfave/cli/v2" + + "github.com/ledgerwatch/erigon/cmd/utils" + "github.com/ledgerwatch/erigon/params" + cli2 "github.com/ledgerwatch/erigon/turbo/cli" + "github.com/ledgerwatch/erigon/turbo/debug" +) + +// MakeApp creates a cli application (based on `github.com/urlfave/cli` package). +// The application exits when `action` returns. +// Parameters: +// * action: the main function for the application. receives `*cli.Context` with parsed command-line flags. +// * cliFlags: the list of flags `cli.Flag` that the app should set and parse. By default, use `DefaultFlags()`. If you want to specify your own flag, use `append(DefaultFlags(), myFlag)` for this parameter. +func MakeApp_zkEvm(name string, action cli.ActionFunc, cliFlags []cli.Flag) *cli.App { + app := cli2.NewApp(params.GitCommit, "erigon") + app.Name = name + app.UsageText = app.Name + ` [command] [flags]` + app.Action = func(context *cli.Context) error { + // handle case: unknown sub-command + if context.Args().Present() { + var goodNames []string + for _, c := range app.VisibleCommands() { + goodNames = append(goodNames, c.Name) + } + log.Error(fmt.Sprintf("Command '%s' not found. Available commands: %s", context.Args().First(), goodNames)) + cli.ShowAppHelpAndExit(context, 1) + } + + // handle case: config flag + configFilePath := context.String(utils.ConfigFlag.Name) + if configFilePath != "" { + if err := cli2.SetFlagsFromConfigFile(context, configFilePath); err != nil { + log.Error("failed setting config flags from yaml/toml file", "err", err) + return err + } + } + + // run default action + return action(context) + } + + app.Flags = appFlags(cliFlags) + app.Before = func(ctx *cli.Context) error { + _, _, _, err := debug.Setup(ctx, true) + return err + } + app.After = func(ctx *cli.Context) error { + debug.Exit() + return nil + } + app.Commands = []*cli.Command{ + &initCommand, + &importCommand, + &snapshotCommand, + &supportCommand, + //&backupCommand, + } + return app +}