From dde01fce0a9c1ca7d09280dd19157c102967ae3e Mon Sep 17 00:00:00 2001 From: Gokcehan Date: Thu, 1 Sep 2016 23:49:56 +0300 Subject: [PATCH] add command line option for profiling --- main.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/main.go b/main.go index e49158f..ffae501 100644 --- a/main.go +++ b/main.go @@ -7,6 +7,7 @@ import ( "os" "os/exec" "path" + "runtime/pprof" ) var ( @@ -63,11 +64,23 @@ func startServer() { func main() { serverMode := flag.Bool("server", false, "start server (automatic)") + cpuprofile := flag.String("cpuprofile", "", "path to the file to write the cpu profile") flag.StringVar(&gLastDirPath, "last-dir-path", "", "path to the file to write the last dir on exit (to use for cd)") flag.StringVar(&gSelectionPath, "selection-path", "", "path to the file to write selected files on exit (to use as open file dialog)") flag.Parse() + if *cpuprofile != "" { + f, err := os.Create(*cpuprofile) + if err != nil { + log.Fatal("could not create CPU profile: ", err) + } + if err := pprof.StartCPUProfile(f); err != nil { + log.Fatal("could not start CPU profile: ", err) + } + defer pprof.StopCPUProfile() + } + if *serverMode { serve() } else {