aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJimmy Hu <jimmy.hu@dexon.org>2018-08-14 13:40:21 +0800
committerWei-Ning Huang <aitjcize@gmail.com>2018-08-14 13:40:21 +0800
commitd71e5de94004bf4be191287a8e40ba1728a3f585 (patch)
tree58bfec55c8ffb840e49d2ffb8fc6c2308bc170b3
parent25c845c700f533c436a33cdb445138a607f65a33 (diff)
downloaddexon-consensus-d71e5de94004bf4be191287a8e40ba1728a3f585.tar
dexon-consensus-d71e5de94004bf4be191287a8e40ba1728a3f585.tar.gz
dexon-consensus-d71e5de94004bf4be191287a8e40ba1728a3f585.tar.bz2
dexon-consensus-d71e5de94004bf4be191287a8e40ba1728a3f585.tar.lz
dexon-consensus-d71e5de94004bf4be191287a8e40ba1728a3f585.tar.xz
dexon-consensus-d71e5de94004bf4be191287a8e40ba1728a3f585.tar.zst
dexon-consensus-d71e5de94004bf4be191287a8e40ba1728a3f585.zip
Add -cpuprofile and -memprofile to dexcon-simulation (#56)
-rw-r--r--cmd/dexcon-simulation/main.go28
-rw-r--r--core/cpu.profbin0 -> 15437 bytes
2 files changed, 28 insertions, 0 deletions
diff --git a/cmd/dexcon-simulation/main.go b/cmd/dexcon-simulation/main.go
index 5547700..def4ac9 100644
--- a/cmd/dexcon-simulation/main.go
+++ b/cmd/dexcon-simulation/main.go
@@ -20,8 +20,11 @@ package main
import (
"flag"
"fmt"
+ "log"
"math/rand"
"os"
+ "runtime"
+ "runtime/pprof"
"time"
"github.com/dexon-foundation/dexon-consensus-core/simulation"
@@ -30,6 +33,8 @@ import (
var initialize = flag.Bool("init", false, "initialize config file")
var configFile = flag.String("config", "", "path to simulation config file")
+var cpuprofile = flag.String("cpuprofile", "", "write cpu profile to `file`")
+var memprofile = flag.String("memprofile", "", "write memory profile to `file`")
func main() {
flag.Parse()
@@ -49,5 +54,28 @@ func main() {
//os.Exit(0)
}
+ if *cpuprofile != "" {
+ f, err := os.Create(*cpuprofile)
+ if err != nil {
+ log.Fatal("could not create CPU profile: ", err)
+ }
+ if err := pprof.StartCPUProfile(f); err != nil {
+ log.Fatal("could not start CPU profile: ", err)
+ }
+ defer pprof.StopCPUProfile()
+ }
+
simulation.Run(*configFile)
+
+ if *memprofile != "" {
+ f, err := os.Create(*memprofile)
+ if err != nil {
+ log.Fatal("could not create memory profile: ", err)
+ }
+ runtime.GC() // get up-to-date statistics
+ if err := pprof.WriteHeapProfile(f); err != nil {
+ log.Fatal("could not write memory profile: ", err)
+ }
+ f.Close()
+ }
}
diff --git a/core/cpu.prof b/core/cpu.prof
new file mode 100644
index 0000000..32963df
--- /dev/null
+++ b/core/cpu.prof
Binary files differ