我有一个 go 二进制文件,它使用 cobra 作为子命令。每个子命令都有自己的标志。我希望能够为具有一组特定参数的命令创建 CPU 配置文件,例如:
myBinary dryRun -c configs/config.json
但是,如果我尝试运行它,如下所示:
go tool pprof -pdf myBinary -- dryRun -c configs/config.json
我收到以下错误:
-: 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
如果我尝试引用整个命令,它也不起作用。有没有办法go tool pprof
传递其他命令行参数?
编辑:这就是我试图描述的方式:
func main() {
defer profile.Start().Stop()
fmt.Println("running version", version, "built on", date)
fmt.Println()
cmd.Execute()
time.Sleep(2 * time.Second)
}