Skip to content

Commit

Permalink
enable CPU profiling
Browse files Browse the repository at this point in the history
  • Loading branch information
lugu committed Apr 24, 2020
1 parent a206d8b commit 3eec115
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"io/ioutil"
"log"
"os"
"runtime/pprof"
"time"

"github.com/lugu/qiloop/app"
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit 3eec115

Please sign in to comment.