サブコマンドに cobra を使用する go バイナリがあります。各サブコマンドには独自のフラグがあります。たとえば、次のような特定のパラメーター セットを使用して、コマンドの 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)
}