diff --git a/cmd/kubeconform/main.go b/cmd/kubeconform/main.go index 4a6367f..c9564c0 100644 --- a/cmd/kubeconform/main.go +++ b/cmd/kubeconform/main.go @@ -3,7 +3,9 @@ package main import ( "context" "fmt" + "log" "os" + "runtime/pprof" "sync" "github.com/yannh/kubeconform/pkg/config" @@ -51,6 +53,18 @@ func realMain() int { return 1 } + if cfg.CPUProfileFile != "" { + f, err := os.Create(cfg.CPUProfileFile) + if err != nil { + log.Fatal("could not create CPU profile: ", err) + } + defer f.Close() + if err := pprof.StartCPUProfile(f); err != nil { + log.Fatal("could not start CPU profile: ", err) + } + defer pprof.StopCPUProfile() + } + // Detect whether we have data being piped through stdin stat, _ := os.Stdin.Stat() isStdin := (stat.Mode() & os.ModeCharDevice) == 0 diff --git a/pkg/config/config.go b/pkg/config/config.go index 6b1232b..09ca557 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -9,6 +9,7 @@ import ( ) type Config struct { + CPUProfileFile string ExitOnError bool Files []string SchemaLocations []string @@ -74,6 +75,7 @@ func FromFlags(progName string, args []string) (Config, string, error) { flags.StringVar(&c.OutputFormat, "output", "text", "output format - json, tap, text") flags.BoolVar(&c.Verbose, "verbose", false, "print results for all resources") flags.BoolVar(&c.SkipTLS, "insecure-skip-tls-verify", false, "disable verification of the server's SSL certificate. This will make your HTTPS connections insecure") + flags.StringVar(&c.CPUProfileFile, "cpu-prof", "", "debug - log CPU profiling to file") flags.BoolVar(&c.Help, "h", false, "show help information") flags.Usage = func() { fmt.Fprintf(os.Stderr, "Usage: %s [OPTION]... [FILE OR FOLDER]...\n", progName)