Move profiler to main
parent
0dc2425a6c
commit
1d0b139a3a
|
@ -6,6 +6,9 @@ import (
|
|||
"github.com/fatih/color"
|
||||
"log"
|
||||
"math/rand"
|
||||
"os"
|
||||
"runtime"
|
||||
"runtime/pprof"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
@ -203,6 +206,29 @@ func BenchThread(cephconn *Cephconnection, osddevice Device, buffs [][]byte, par
|
|||
|
||||
func main() {
|
||||
params := Route()
|
||||
if params.cpuprofile != "" {
|
||||
f, err := os.Create(params.cpuprofile)
|
||||
if err != nil {
|
||||
log.Fatal("could not create CPU profile: ", err)
|
||||
}
|
||||
defer f.Close()
|
||||
if err := pprof.StartCPUProfile(f); err != nil {
|
||||
log.Fatal("could not start CPU profile: ", err)
|
||||
}
|
||||
defer pprof.StopCPUProfile()
|
||||
}
|
||||
|
||||
if params.memprofile != "" {
|
||||
f, err := os.Create(params.memprofile)
|
||||
if err != nil {
|
||||
log.Fatal("could not create memory profile: ", err)
|
||||
}
|
||||
defer f.Close()
|
||||
runtime.GC() // get up-to-date statistics
|
||||
if err := pprof.WriteHeapProfile(f); err != nil {
|
||||
log.Fatal("could not write memory profile: ", err)
|
||||
}
|
||||
}
|
||||
cephconn := connectioninit(params)
|
||||
defer cephconn.conn.Shutdown()
|
||||
|
||||
|
|
27
flags.go
27
flags.go
|
@ -4,9 +4,6 @@ import (
|
|||
"code.cloudfoundry.org/bytefmt"
|
||||
"github.com/juju/gnuflag"
|
||||
"log"
|
||||
"os"
|
||||
"runtime"
|
||||
"runtime/pprof"
|
||||
"time"
|
||||
)
|
||||
|
||||
|
@ -58,30 +55,6 @@ func Route() Params {
|
|||
"Name of memprofile")
|
||||
gnuflag.Parse(true)
|
||||
|
||||
if params.cpuprofile != "" {
|
||||
f, err := os.Create(params.cpuprofile)
|
||||
if err != nil {
|
||||
log.Fatal("could not create CPU profile: ", err)
|
||||
}
|
||||
defer f.Close()
|
||||
if err := pprof.StartCPUProfile(f); err != nil {
|
||||
log.Fatal("could not start CPU profile: ", err)
|
||||
}
|
||||
defer pprof.StopCPUProfile()
|
||||
}
|
||||
|
||||
if params.memprofile != "" {
|
||||
f, err := os.Create(params.memprofile)
|
||||
if err != nil {
|
||||
log.Fatal("could not create memory profile: ", err)
|
||||
}
|
||||
defer f.Close()
|
||||
runtime.GC() // get up-to-date statistics
|
||||
if err := pprof.WriteHeapProfile(f); err != nil {
|
||||
log.Fatal("could not write memory profile: ", err)
|
||||
}
|
||||
}
|
||||
|
||||
blocksize, err := bytefmt.ToBytes(params.bs)
|
||||
params.blocksize = blocksize
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in New Issue