mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-25 16:25:16 +00:00
cmd: fix cpu profile starter
This commit is contained in:
parent
ba7b6f82e2
commit
4e4ffe83e5
|
@ -62,15 +62,15 @@ var RootCmd = &cobra.Command{
|
|||
}
|
||||
|
||||
if cpuProfile != "" {
|
||||
log.Infof("starting cpu profiler...")
|
||||
log.Infof("starting cpu profiler, recording at %s", cpuProfile)
|
||||
|
||||
cpuProfileFile, err = os.Create(cpuProfile)
|
||||
if err != nil {
|
||||
log.Fatal("could not create CPU profile: ", err)
|
||||
return errors.Wrap(err, "can not create file for CPU profile")
|
||||
}
|
||||
|
||||
if err := pprof.StartCPUProfile(cpuProfileFile); err != nil {
|
||||
log.Fatal("could not start CPU profile: ", err)
|
||||
return errors.Wrap(err, "can not start CPU profile")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,6 @@ import (
|
|||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"runtime/pprof"
|
||||
"syscall"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
@ -244,11 +243,6 @@ func run(cmd *cobra.Command, args []string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
cpuProfile, err := cmd.Flags().GetString("cpu-profile")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if !setup {
|
||||
// if it's not setup, then the config file option is required.
|
||||
if len(configFile) == 0 {
|
||||
|
@ -280,20 +274,6 @@ func run(cmd *cobra.Command, args []string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
if cpuProfile != "" {
|
||||
f, err := os.Create(cpuProfile)
|
||||
if err != nil {
|
||||
log.Fatal("could not create CPU profile: ", err)
|
||||
}
|
||||
defer f.Close() // error handling omitted for example
|
||||
|
||||
if err := pprof.StartCPUProfile(f); err != nil {
|
||||
log.Fatal("could not start CPU profile: ", err)
|
||||
}
|
||||
|
||||
defer pprof.StopCPUProfile()
|
||||
}
|
||||
|
||||
return runConfig(ctx, cmd, userConfig)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user