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
This commit is contained in:
baude 2017-11-09 09:29:15 -06:00 committed by Atomic Bot
parent a0476f6529
commit 55c9cfb80e
3 changed files with 23 additions and 1 deletions

View File

@ -3,8 +3,10 @@ package main
import ( import (
"fmt" "fmt"
"os" "os"
"runtime/pprof"
"github.com/containers/storage/pkg/reexec" "github.com/containers/storage/pkg/reexec"
"github.com/pkg/errors"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"github.com/urfave/cli" "github.com/urfave/cli"
) )
@ -15,6 +17,7 @@ var kpodVersion = ""
func main() { func main() {
debug := false debug := false
cpuProfile := false
if reexec.Init() { if reexec.Init() {
return return
@ -77,12 +80,23 @@ func main() {
debug = true 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 return nil
} }
app.After = func(*cli.Context) error { app.After = func(*cli.Context) error {
// called by Run() when the command handler succeeds // called by Run() when the command handler succeeds
shutdownStores() shutdownStores()
if cpuProfile {
pprof.StopCPUProfile()
}
return nil return nil
} }
cli.OsExiter = func(code int) { cli.OsExiter = func(code int) {
@ -99,6 +113,10 @@ func main() {
Name: "conmon", Name: "conmon",
Usage: "path of the conmon binary", Usage: "path of the conmon binary",
}, },
cli.StringFlag{
Name: "cpu-profile",
Usage: "path for the cpu profiling results",
},
cli.StringFlag{ cli.StringFlag{
Name: "log-level", Name: "log-level",
Usage: "log messages above specified level: debug, info, warn, error (default), fatal or panic", Usage: "log messages above specified level: debug, info, warn, error (default), fatal or panic",

View File

@ -1410,6 +1410,7 @@ _kpod_logout() {
_kpod_kpod() { _kpod_kpod() {
local options_with_args=" local options_with_args="
--config -c --config -c
--cpu-profile
--root --root
--runroot --runroot
--storage-driver --storage-driver

View File

@ -26,6 +26,9 @@ has the capability to debug pods/images created by crio.
**--config value, -c**=**"config.file"** **--config value, -c**=**"config.file"**
Path of a config file detailing container server configuration options 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-level**
log messages above specified level: debug, info, warn, error (default), fatal or panic log messages above specified level: debug, info, warn, error (default), fatal or panic