Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable CPU Profiling via CLI flag #4973

Merged
merged 5 commits into from
Aug 30, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions server/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package server

import (
"fmt"
"os"
"runtime/pprof"

"github.com/spf13/cobra"
"github.com/spf13/viper"
Expand All @@ -22,6 +24,7 @@ const (
flagAddress = "address"
flagTraceStore = "trace-store"
flagPruning = "pruning"
flagCPUProfile = "cpu-profile"
FlagMinGasPrices = "minimum-gas-prices"
FlagHaltHeight = "halt-height"
)
Expand All @@ -38,6 +41,20 @@ func StartCmd(ctx *Context, appCreator AppCreator) *cobra.Command {
return startStandAlone(ctx, appCreator)
}

if cpuProfile := viper.GetString(flagCPUProfile); cpuProfile != "" {
f, err := os.Create(cpuProfile)
if err != nil {
return err
}

ctx.Logger.Info("Starting CPU profiler (%s)\n", cpuProfile)
alexanderbez marked this conversation as resolved.
Show resolved Hide resolved
if err := pprof.StartCPUProfile(f); err != nil {
return err
}

defer pprof.StopCPUProfile()
}

ctx.Logger.Info("Starting ABCI with Tendermint")

_, err := startInProcess(ctx, appCreator)
Expand All @@ -55,6 +72,7 @@ func StartCmd(ctx *Context, appCreator AppCreator) *cobra.Command {
"Minimum gas prices to accept for transactions; Any fee in a tx must meet this minimum (e.g. 0.01photino;0.0001stake)",
)
cmd.Flags().Uint64(FlagHaltHeight, 0, "Height at which to gracefully halt the chain and shutdown the node")
cmd.Flags().String(flagCPUProfile, "", "Enable CPU profiling and write to the provided file")

// add support for all Tendermint-specific command line options
tcmd.AddNodeFlags(cmd)
Expand Down