mirror of
https://github.com/mjl-/mox.git
synced 2025-07-12 17:04:39 +03:00
add subcommand "ximport", that is like "import" but directly access files in the datadir
so mox doesn't have to be running when you run it. will be useful for testing in the near future. this also moves cpuprof and memprof cli flags to top-level flag parsing, so all commands can use them.
This commit is contained in:
45
profile.go
Normal file
45
profile.go
Normal file
@ -0,0 +1,45 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
"runtime"
|
||||
"runtime/pprof"
|
||||
)
|
||||
|
||||
func memprofile(mempath string) {
|
||||
if mempath == "" {
|
||||
return
|
||||
}
|
||||
|
||||
f, err := os.Create(mempath)
|
||||
xcheckf(err, "creating memory profile")
|
||||
defer func() {
|
||||
if err := f.Close(); err != nil {
|
||||
log.Printf("closing memory profile: %v", err)
|
||||
}
|
||||
}()
|
||||
runtime.GC() // get up-to-date statistics
|
||||
err = pprof.WriteHeapProfile(f)
|
||||
xcheckf(err, "writing memory profile")
|
||||
}
|
||||
|
||||
func profile(cpupath, mempath string) func() {
|
||||
if cpupath == "" {
|
||||
return func() {
|
||||
memprofile(mempath)
|
||||
}
|
||||
}
|
||||
|
||||
f, err := os.Create(cpupath)
|
||||
xcheckf(err, "creating CPU profile")
|
||||
err = pprof.StartCPUProfile(f)
|
||||
xcheckf(err, "start CPU profile")
|
||||
return func() {
|
||||
pprof.StopCPUProfile()
|
||||
if err := f.Close(); err != nil {
|
||||
log.Printf("closing cpu profile: %v", err)
|
||||
}
|
||||
memprofile(mempath)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user