From 3eec1157d21b9bf42cc6505fa686387c66a73bb0 Mon Sep 17 00:00:00 2001 From: Ludovic Guegan Date: Fri, 24 Apr 2020 23:41:53 +0200 Subject: [PATCH] enable CPU profiling --- main.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/main.go b/main.go index b9d6ca5..df5e47f 100644 --- a/main.go +++ b/main.go @@ -7,6 +7,7 @@ import ( "io/ioutil" "log" "os" + "runtime/pprof" "time" "github.com/lugu/qiloop/app" @@ -60,6 +61,7 @@ var ( logFile = flag.String("log-file", "", "file where to write qitop logs") level = flag.Int("log-level", 4, "log level, 1:fatal, 2:error, 3:warning, 4:info, 5:verbose, 6:debug") + cpuprofile = flag.String("cpuprofile", "", "write cpu profile to file") ) // widgets holds the widgets used by this demo. @@ -367,6 +369,14 @@ func run() (err error) { func main() { flag.Parse() + if *cpuprofile != "" { + f, err := os.Create(*cpuprofile) + if err != nil { + log.Fatal(err) + } + pprof.StartCPUProfile(f) + defer pprof.StopCPUProfile() + } if err := run(); err != nil { log.Fatal(err) }