diff options
author | baude <bbaude@redhat.com> | 2017-11-09 09:29:15 -0600 |
---|---|---|
committer | Atomic Bot <atomic-devel@projectatomic.io> | 2017-11-09 17:36:11 +0000 |
commit | 55c9cfb80e066713f009547f7df7dddd2da35eb8 (patch) | |
tree | fd32384bcd947ccb4b21feafb1b92a5bfb6b7b8f | |
parent | a0476f6529f2a4c00b91bb0cce353c73d5c4d4d4 (diff) | |
download | podman-55c9cfb80e066713f009547f7df7dddd2da35eb8.tar.gz podman-55c9cfb80e066713f009547f7df7dddd2da35eb8.tar.bz2 podman-55c9cfb80e066713f009547f7df7dddd2da35eb8.zip |
Add cpu-profiling to kpod
Add a global flag for cpu-profiling to allow us to
profile kpod for performance issues.
To parse its results, use:
go tool pprof --text <profile_path>
Signed-off-by: baude <bbaude@redhat.com>
Closes: #36
Approved by: mheon
-rw-r--r-- | cmd/kpod/main.go | 20 | ||||
-rw-r--r-- | completions/bash/kpod | 1 | ||||
-rw-r--r-- | docs/kpod.1.md | 3 |
3 files changed, 23 insertions, 1 deletions
diff --git a/cmd/kpod/main.go b/cmd/kpod/main.go index ab95995fe..97d942a3c 100644 --- a/cmd/kpod/main.go +++ b/cmd/kpod/main.go @@ -3,8 +3,10 @@ package main import ( "fmt" "os" + "runtime/pprof" "github.com/containers/storage/pkg/reexec" + "github.com/pkg/errors" "github.com/sirupsen/logrus" "github.com/urfave/cli" ) @@ -15,6 +17,7 @@ var kpodVersion = "" func main() { debug := false + cpuProfile := false if reexec.Init() { return @@ -77,12 +80,23 @@ func main() { debug = true } - + if c.GlobalIsSet("cpu-profile") { + f, err := os.Create(c.GlobalString("cpu-profile")) + if err != nil { + return errors.Wrapf(err, "unable to create cpu profiling file %s", + c.GlobalString("cpu-profile")) + } + cpuProfile = true + pprof.StartCPUProfile(f) + } return nil } app.After = func(*cli.Context) error { // called by Run() when the command handler succeeds shutdownStores() + if cpuProfile { + pprof.StopCPUProfile() + } return nil } cli.OsExiter = func(code int) { @@ -100,6 +114,10 @@ func main() { Usage: "path of the conmon binary", }, cli.StringFlag{ + Name: "cpu-profile", + Usage: "path for the cpu profiling results", + }, + cli.StringFlag{ Name: "log-level", Usage: "log messages above specified level: debug, info, warn, error (default), fatal or panic", Value: "error", diff --git a/completions/bash/kpod b/completions/bash/kpod index 2387228cb..c13e64379 100644 --- a/completions/bash/kpod +++ b/completions/bash/kpod @@ -1410,6 +1410,7 @@ _kpod_logout() { _kpod_kpod() { local options_with_args=" --config -c + --cpu-profile --root --runroot --storage-driver diff --git a/docs/kpod.1.md b/docs/kpod.1.md index 408ad3877..f1b74b58f 100644 --- a/docs/kpod.1.md +++ b/docs/kpod.1.md @@ -26,6 +26,9 @@ has the capability to debug pods/images created by crio. **--config value, -c**=**"config.file"** Path of a config file detailing container server configuration options +**--cpu-profile** + Path to where the cpu performance results should be written + **--log-level** log messages above specified level: debug, info, warn, error (default), fatal or panic |