ref: 5df85770fca6184e4230e9cb4fddeb841087563f
parent: f8704c1bf23d22530ff417e0f48ee487a167a0f7
author: bep <bjorn.erik.pedersen@gmail.com>
date: Thu Feb 5 10:48:09 EST 2015
Add memprofile to pprof benchmark
--- a/commands/benchmark.go
+++ b/commands/benchmark.go
@@ -20,6 +20,7 @@
)
var cpuProfilefile string
+var memProfilefile string
var benchmarkTimes int
var benchmark = &cobra.Command{@@ -34,21 +35,41 @@
}
func init() {- benchmark.Flags().StringVar(&cpuProfilefile, "outputfile", "/tmp/hugo-cpuprofile", "path/filename for the profile file")
+ benchmark.Flags().StringVar(&cpuProfilefile, "cpuprofile", "", "path/filename for the CPU profile file")
+ benchmark.Flags().StringVar(&memProfilefile, "memprofile", "", "path/filename for the memory profile file")
+
benchmark.Flags().IntVarP(&benchmarkTimes, "count", "n", 13, "number of times to build the site")
}
func bench(cmd *cobra.Command, args []string) {- f, err := os.Create(cpuProfilefile)
- if err != nil {- panic(err)
- }
+ if memProfilefile != "" {+ f, err := os.Create(memProfilefile)
- pprof.StartCPUProfile(f)
- defer pprof.StopCPUProfile()
+ if err != nil {+ panic(err)
+ }
+ for i := 0; i < benchmarkTimes; i++ {+ _ = buildSite()
+ }
+ pprof.WriteHeapProfile(f)
+ f.Close()
- for i := 0; i < benchmarkTimes; i++ {- _ = buildSite()
+ } else {+ if cpuProfilefile == "" {+ cpuProfilefile = "/tmp/hugo-cpuprofile"
+ }
+ f, err := os.Create(cpuProfilefile)
+
+ if err != nil {+ panic(err)
+ }
+
+ pprof.StartCPUProfile(f)
+ defer pprof.StopCPUProfile()
+ for i := 0; i < benchmarkTimes; i++ {+ _ = buildSite()
+ }
}
+
}
--
⑨