Add profiling flag

This commit is contained in:
Alexey Akhunov 2018-07-09 23:14:17 +01:00
parent 54c477fa90
commit 32e98c71f1

22
main.go
View File

@ -7,9 +7,11 @@ package main
import ( import (
"bytes" "bytes"
"encoding/json" "encoding/json"
"flag"
"fmt" "fmt"
"io" "io"
"os" "os"
"runtime/pprof"
"github.com/cosmos/ethermint/core" "github.com/cosmos/ethermint/core"
"github.com/cosmos/ethermint/state" "github.com/cosmos/ethermint/state"
@ -24,6 +26,8 @@ import (
dbm "github.com/tendermint/tendermint/libs/db" dbm "github.com/tendermint/tendermint/libs/db"
) )
var cpuprofile = flag.String("cpuprofile", "", "write cpu profile `file`")
var ( var (
// TODO: Document... // TODO: Document...
miner501 = ethcommon.HexToAddress("0x35e8e5dC5FBd97c5b421A80B596C030a2Be2A04D") miner501 = ethcommon.HexToAddress("0x35e8e5dC5FBd97c5b421A80B596C030a2Be2A04D")
@ -32,6 +36,20 @@ var (
// TODO: Document... // TODO: Document...
func main() { func main() {
flag.Parse()
if *cpuprofile != "" {
f, err := os.Create(*cpuprofile)
if err != nil {
fmt.Printf("could not create CPU profile: %v\n", err)
return
}
if err := pprof.StartCPUProfile(f); err != nil {
fmt.Printf("could not start CPU profile: %v\n", err)
return
}
defer pprof.StopCPUProfile()
}
stateDB := dbm.NewDB("state", dbm.MemDBBackend, "") stateDB := dbm.NewDB("state", dbm.MemDBBackend, "")
codeDB := dbm.NewDB("code", dbm.MemDBBackend, "") codeDB := dbm.NewDB("code", dbm.MemDBBackend, "")
@ -195,10 +213,10 @@ func main() {
} }
n++ n++
if (n % 100) == 0 { if (n % 1000) == 0 {
fmt.Printf("processed %d blocks\n", n) fmt.Printf("processed %d blocks\n", n)
} }
if n >= 1000 { if n >= 20000 {
break break
} }
} }