mirror of
https://github.com/danog/gojekyll.git
synced 2024-11-26 23:34:47 +01:00
Restore profiling
This commit is contained in:
parent
2401199fa7
commit
5cd1554f27
@ -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
|
||||
```
|
||||
|
@ -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)
|
||||
}()
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user