I have a go binary, which uses cobra for subcommands. Each subcommand has it's own flags. I'd like to be able to create a CPU profile for a command with a specific set of parameters, like for example:
myBinary dryRun -c configs/config.json
However, if I try to run it, like this:
go tool pprof -pdf myBinary -- dryRun -c configs/config.json
I get the following error:
-: open --: no such file or directory
dryRun: open dryRun: no such file or directory
-c: open -c: no such file or directory
configs/config.json: parsing profile: unrecognized profile format
If I try to quote the entire command, it's also not working. Is there any way to get go tool pprof
to pass other command line arguments?
EDIT: This is how I'm trying to profile:
func main() {
defer profile.Start().Stop()
fmt.Println("running version", version, "built on", date)
fmt.Println()
cmd.Execute()
time.Sleep(2 * time.Second)
}