cmd: move profiling stuff into pprof.go
This commit is contained in:
parent
178d014fcf
commit
ea9008f19c
@ -6,13 +6,9 @@ import (
|
||||
"fmt"
|
||||
"github.com/knieriem/markdown"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"runtime/pprof"
|
||||
)
|
||||
|
||||
var cpuprofile = flag.String("cpuprofile", "", "write cpu profile to file")
|
||||
|
||||
func main() {
|
||||
var b []byte
|
||||
|
||||
@ -37,14 +33,8 @@ func main() {
|
||||
Dlists: *optDlists,
|
||||
}
|
||||
|
||||
if *cpuprofile != "" {
|
||||
f, err := os.Create(*cpuprofile)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
pprof.StartCPUProfile(f)
|
||||
defer pprof.StopCPUProfile()
|
||||
}
|
||||
startPProf()
|
||||
defer stopPProf()
|
||||
|
||||
doc := markdown.Parse(string(b), e)
|
||||
w := bufio.NewWriter(os.Stdout)
|
||||
|
35
cmd/markdown/pprof.go
Normal file
35
cmd/markdown/pprof.go
Normal file
@ -0,0 +1,35 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"log"
|
||||
"os"
|
||||
"runtime/pprof"
|
||||
)
|
||||
|
||||
var cpuprofile = flag.String("cpuprofile", "", "write cpu profile to file")
|
||||
var memprofile = flag.String("memprofile", "", "write memory profile to file")
|
||||
|
||||
func startPProf() {
|
||||
if *cpuprofile != "" {
|
||||
f, err := os.Create(*cpuprofile)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
pprof.StartCPUProfile(f)
|
||||
}
|
||||
}
|
||||
|
||||
func stopPProf() {
|
||||
if *cpuprofile != "" {
|
||||
pprof.StopCPUProfile()
|
||||
}
|
||||
if *memprofile != "" {
|
||||
f, err := os.Create(*memprofile)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
pprof.WriteHeapProfile(f)
|
||||
f.Close()
|
||||
}
|
||||
}
|
@ -27,8 +27,8 @@ benchmark: m ,,pmd ,,prevmd
|
||||
#
|
||||
pprof: cmd m
|
||||
$(MD) -cpuprofile /tmp/md.prof <m > /tmp/,,md.out
|
||||
@echo gopprof \'--nodefraction=0.1\' $(MD) /tmp/md.prof
|
||||
@echo gopprof $(MD) /tmp/md.prof
|
||||
@echo go tool pprof \'--nodefraction=0.1\' $(MD) /tmp/md.prof
|
||||
@echo go tool pprof $(MD) /tmp/md.prof
|
||||
|
||||
.PHONY:\
|
||||
diff\
|
||||
|
Loading…
Reference in New Issue
Block a user