From dc50bce2ed15c5744af36a58c761f797d61fae11 Mon Sep 17 00:00:00 2001 From: Chris Cummer Date: Tue, 17 Jul 2018 10:17:35 -0700 Subject: [PATCH] Add -p/--profile flag to enable cpu/memory profiling 1. Compile the binary with the profiling flag in it. 2. Run the binary with profiling enabled: ./wtf -p 3. Run the go profiling tool against the resulting *.pprof file: go tool pprof --pdf /path/to/wtfbinary /var/path/to/cpu.pprof > profile.pdf 4. View pretty PDF file --- .gitignore | 2 ++ flags/flags.go | 1 + wtf.go | 5 +++++ 3 files changed, 8 insertions(+) diff --git a/.gitignore b/.gitignore index 2d038a3c..6dde8d37 100644 --- a/.gitignore +++ b/.gitignore @@ -16,6 +16,8 @@ .DS_Store gcal/client_secret.json gspreadsheets/client_secret.json +profile.pdf + #intellij idea .idea/ diff --git a/flags/flags.go b/flags/flags.go index 62c86aed..11327e09 100644 --- a/flags/flags.go +++ b/flags/flags.go @@ -13,6 +13,7 @@ import ( type Flags struct { Config string `short:"c" long:"config" optional:"yes" description:"Path to config file"` Module string `short:"m" long:"module" optional:"yes" description:"Display info about a specific module, i.e.: 'wtf -m=todo'"` + Profile bool `short:"p" long:"profile" optional:"yes" description:"Profile application memory usage"` Version bool `short:"v" long:"version" description:"Show version info"` } diff --git a/wtf.go b/wtf.go index c7709776..4d285251 100644 --- a/wtf.go +++ b/wtf.go @@ -8,6 +8,7 @@ import ( "github.com/gdamore/tcell" "github.com/olebedev/config" + "github.com/pkg/profile" "github.com/radovskyb/watcher" "github.com/rivo/tview" "github.com/senorprogrammer/wtf/bamboohr" @@ -253,6 +254,10 @@ func main() { cfg.CreateConfigFile() loadConfigFile(flags.ConfigFilePath()) + if flags.Profile { + defer profile.Start(profile.MemProfile).Stop() + } + setTerm() app := tview.NewApplication()