From a2a23d91caa19ffffe488fd83f807b1d1b6853db Mon Sep 17 00:00:00 2001 From: Wei Fu Date: Wed, 10 Oct 2018 22:49:50 +0800 Subject: [PATCH] enhance: support specific duration for profile collection The default duration of cpu profile collection in net/http/pprof is 30 seconds. User should have chance to set the specific duration for the collection. Signed-off-by: Wei Fu --- cmd/ctr/commands/pprof/pprof.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/cmd/ctr/commands/pprof/pprof.go b/cmd/ctr/commands/pprof/pprof.go index 80cbb33cc..acaf2f908 100644 --- a/cmd/ctr/commands/pprof/pprof.go +++ b/cmd/ctr/commands/pprof/pprof.go @@ -89,10 +89,18 @@ var pprofHeapCommand = cli.Command{ var pprofProfileCommand = cli.Command{ Name: "profile", Usage: "CPU profile", + Flags: []cli.Flag{ + cli.DurationFlag{ + Name: "seconds,s", + Usage: "duration for collection (seconds)", + Value: 30 * time.Second, + }, + }, Action: func(context *cli.Context) error { client := getPProfClient(context) - output, err := httpGetRequest(client, "/debug/pprof/profile") + seconds := context.Duration("seconds").Seconds() + output, err := httpGetRequest(client, fmt.Sprintf("/debug/pprof/profile?seconds=%v", seconds)) if err != nil { return err }