@@ -2,6 +2,8 @@ package bench
2
2
3
3
import (
4
4
"net/http"
5
+ "os"
6
+ "runtime/pprof"
5
7
"testing"
6
8
"time"
7
9
@@ -30,6 +32,7 @@ func benchCommand() *cobra.Command {
30
32
changelogPath string
31
33
loadSnapshot bool
32
34
usePrometheus bool
35
+ cpuProfile string
33
36
)
34
37
cmd := & cobra.Command {
35
38
Use : "std" ,
@@ -44,12 +47,26 @@ $ go run ./cmd snapshot --db /tmp/iavl-v2 --version 1
44
47
` ,
45
48
46
49
RunE : func (_ * cobra.Command , _ []string ) error {
50
+ if cpuProfile != "" {
51
+ f , err := os .Create (cpuProfile )
52
+ if err != nil {
53
+ return err
54
+ }
55
+ if err := pprof .StartCPUProfile (f ); err != nil {
56
+ return err
57
+ }
58
+ defer func () {
59
+ pprof .StopCPUProfile ()
60
+ f .Close ()
61
+ }()
62
+ }
47
63
t := & testing.T {}
48
64
treeOpts := iavl .DefaultTreeOptions ()
49
65
treeOpts .CheckpointInterval = 80
50
66
treeOpts .StateStorage = true
51
67
treeOpts .HeightFilter = 1
52
68
treeOpts .EvictionDepth = 22
69
+ treeOpts .PruneRatio = 0
53
70
treeOpts .MetricsProxy = metrics .NewStructMetrics ()
54
71
if usePrometheus {
55
72
treeOpts .MetricsProxy = newPrometheusMetricsProxy ()
@@ -84,6 +101,7 @@ $ go run ./cmd snapshot --db /tmp/iavl-v2 --version 1
84
101
cmd .Flags ().StringVar (& changelogPath , "changelog" , "/tmp/osmo-like-many/v2" , "the path to the changelog" )
85
102
cmd .Flags ().BoolVar (& loadSnapshot , "snapshot" , false , "load the snapshot at version 1 before running the benchmarks (loads full tree into memory)" )
86
103
cmd .Flags ().BoolVar (& usePrometheus , "prometheus" , false , "enable prometheus metrics" )
104
+ cmd .Flags ().StringVar (& cpuProfile , "cpu-profile" , "" , "write cpu profile to file" )
87
105
88
106
if err := cmd .MarkFlagRequired ("changelog" ); err != nil {
89
107
panic (err )
0 commit comments