From ec93c2ee28691ad5986148e3455d1a78ecc21380 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Teichgr=C3=A4ber?= Date: Wed, 29 Jun 2011 20:01:24 +0200 Subject: [PATCH] cmd/main.go: add flag -cpuprofile to enable runtime/pprof profiling --- cmd/main.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/cmd/main.go b/cmd/main.go index c634a06..b49d524 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -7,8 +7,12 @@ import ( "os" "bufio" "io/ioutil" + "log" + "runtime/pprof" ) +var cpuprofile = flag.String("cpuprofile", "", "write cpu profile to file") + func main() { var b []byte @@ -33,6 +37,15 @@ func main() { 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) w := bufio.NewWriter(os.Stdout) doc.WriteHtml(w)