From 5cd1554f2774bc25f83adc60198349fb766e5441 Mon Sep 17 00:00:00 2001 From: Oliver Steele Date: Sun, 9 Jul 2017 15:55:12 -0400 Subject: [PATCH] Restore profiling --- CONTRIBUTING.md | 3 ++- cmd/gojekyll/main.go | 13 +++++-------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 24985f0..92f79f0 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -53,5 +53,6 @@ gojekyll -s path/to/site variables site.twitter.name # print a specific site va ### Profiling ```bash -gojekyll -s path/to/site benchmark && go tool pprof gojekyll gojekyll.prof +gojekyll -s path/to/site benchmark +go tool pprof --web gojekyll gojekyll.prof ``` diff --git a/cmd/gojekyll/main.go b/cmd/gojekyll/main.go index db7334c..240936f 100644 --- a/cmd/gojekyll/main.go +++ b/cmd/gojekyll/main.go @@ -77,9 +77,6 @@ func parseAndRun(args []string) { if buildOptions.DryRun { buildOptions.Verbose = true } - if cmd == benchmark.FullCommand() { - profile = true - } app.FatalIfError(run(cmd), "") } @@ -88,8 +85,8 @@ func printVersion() { } func run(cmd string) error { // nolint: gocyclo - if profile { - setupProfiling() + if profile || cmd == benchmark.FullCommand() { + defer setupProfiling()() } if *versionFlag { printVersion() @@ -148,17 +145,17 @@ func loadSite(source string, flags config.Flags) (*site.Site, error) { return site, err } -func setupProfiling() { +func setupProfiling() func() { profilePath := "gojekyll.prof" logger.label("Profiling...", "") f, err := os.Create(profilePath) app.FatalIfError(err, "") err = pprof.StartCPUProfile(f) app.FatalIfError(err, "") - defer func() { + return func() { pprof.StopCPUProfile() err = f.Close() app.FatalIfError(err, "") logger.Info("Wrote", profilePath) - }() + } }