加入性能捕获工具

This commit is contained in:
Mr.Li 2023-04-08 10:09:30 +08:00
parent ec94cb1377
commit 987e24bf29
1 changed files with 44 additions and 0 deletions

44
biz/util/ppro.go Normal file
View File

@ -0,0 +1,44 @@
package util
import (
"log"
"os"
"runtime/pprof"
)
type Pprof struct {
fc *os.File
fm *os.File
}
func NewProf() *Pprof {
fc, err := os.Create("./cpu.prof")
if err != nil {
log.Fatal(err)
}
fm, err := os.Create("./men.prof")
if err != nil {
log.Fatal(err)
}
p := &Pprof{
fc: fc,
fm: fm,
}
p.Start()
return p
}
func (p *Pprof) Start() {
pprof.StartCPUProfile(p.fc)
pprof.WriteHeapProfile(p.fm)
}
func (p *Pprof) Close() {
pprof.StopCPUProfile()
p.fc.Close()
p.fm.Close()
}