diff --git a/cmd/util/cmd/execution-state-extract/cmd.go b/cmd/util/cmd/execution-state-extract/cmd.go index f9701e503c3..b8920226a4a 100644 --- a/cmd/util/cmd/execution-state-extract/cmd.go +++ b/cmd/util/cmd/execution-state-extract/cmd.go @@ -5,6 +5,7 @@ import ( "fmt" "os" "path" + "runtime/pprof" "strings" "github.com/rs/zerolog/log" @@ -178,6 +179,20 @@ func init() { } func run(*cobra.Command, []string) { + if flagCPUProfile != "" { + f, err := os.Create(flagCPUProfile) + if err != nil { + log.Fatal().Err(err).Msg("could not create CPU profile") + } + + err = pprof.StartCPUProfile(f) + if err != nil { + log.Fatal().Err(err).Msg("could not start CPU profile") + } + + defer pprof.StopCPUProfile() + } + var stateCommitment flow.StateCommitment if len(flagBlockHash) > 0 && len(flagStateCommitment) > 0 { diff --git a/cmd/util/cmd/execution-state-extract/execution_state_extract.go b/cmd/util/cmd/execution-state-extract/execution_state_extract.go index 319f5fc057e..f53b53167c3 100644 --- a/cmd/util/cmd/execution-state-extract/execution_state_extract.go +++ b/cmd/util/cmd/execution-state-extract/execution_state_extract.go @@ -6,7 +6,6 @@ import ( "fmt" "math" "os" - "runtime/pprof" syncAtomic "sync/atomic" "time" @@ -325,19 +324,6 @@ func newMigration( nWorker int, ) ledger.Migration { return func(payloads []*ledger.Payload) ([]*ledger.Payload, error) { - if flagCPUProfile != "" { - f, err := os.Create(flagCPUProfile) - if err != nil { - logger.Fatal().Err(err).Msg("could not create CPU profile") - } - - err = pprof.StartCPUProfile(f) - if err != nil { - logger.Fatal().Err(err).Msg("could not start CPU profile") - } - - defer pprof.StopCPUProfile() - } if len(migrations) == 0 { return payloads, nil