cmd/main.go: add flag -cpuprofile to enable runtime/pprof profiling

This commit is contained in:
Michael Teichgräber 2011-06-29 20:01:24 +02:00
parent 13fca5aaab
commit ec93c2ee28

View File

@ -7,8 +7,12 @@ import (
"os" "os"
"bufio" "bufio"
"io/ioutil" "io/ioutil"
"log"
"runtime/pprof"
) )
var cpuprofile = flag.String("cpuprofile", "", "write cpu profile to file")
func main() { func main() {
var b []byte var b []byte
@ -33,6 +37,15 @@ func main() {
Dlists: *optDlists, Dlists: *optDlists,
} }
if *cpuprofile != "" {
f, err := os.Create(*cpuprofile)
if err != nil {
log.Fatal(err)
}
pprof.StartCPUProfile(f)
defer pprof.StopCPUProfile()
}
doc := markdown.Parse(string(b), e) doc := markdown.Parse(string(b), e)
w := bufio.NewWriter(os.Stdout) w := bufio.NewWriter(os.Stdout)
doc.WriteHtml(w) doc.WriteHtml(w)