@@ -21,6 +21,7 @@ import (
2121 "fmt"
2222 "io/ioutil"
2323 "os"
24+ "runtime/pprof"
2425 "time"
2526
2627 goruntime "runtime"
@@ -108,6 +109,19 @@ func runCmd(ctx *cli.Context) error {
108109 },
109110 }
110111
112+ if cpuProfilePath := ctx .GlobalString (CPUProfileFlag .Name ); cpuProfilePath != "" {
113+ f , err := os .Create (cpuProfilePath )
114+ if err != nil {
115+ fmt .Println ("could not create CPU profile: " , err )
116+ os .Exit (1 )
117+ }
118+ if err := pprof .StartCPUProfile (f ); err != nil {
119+ fmt .Println ("could not start CPU profile: " , err )
120+ os .Exit (1 )
121+ }
122+ defer pprof .StopCPUProfile ()
123+ }
124+
111125 tstart := time .Now ()
112126 if ctx .GlobalBool (CreateFlag .Name ) {
113127 input := append (code , common .Hex2Bytes (ctx .GlobalString (InputFlag .Name ))... )
@@ -125,12 +139,27 @@ func runCmd(ctx *cli.Context) error {
125139 fmt .Println (string (statedb .Dump ()))
126140 }
127141
142+ if memProfilePath := ctx .GlobalString (MemProfileFlag .Name ); memProfilePath != "" {
143+ f , err := os .Create (memProfilePath )
144+ if err != nil {
145+ fmt .Println ("could not create memory profile: " , err )
146+ os .Exit (1 )
147+ }
148+ if err := pprof .WriteHeapProfile (f ); err != nil {
149+ fmt .Println ("could not write memory profile: " , err )
150+ os .Exit (1 )
151+ }
152+ f .Close ()
153+ }
154+
128155 if ctx .GlobalBool (DebugFlag .Name ) {
129156 fmt .Fprintln (os .Stderr , "#### TRACE ####" )
130157 vm .WriteTrace (os .Stderr , logger .StructLogs ())
131158 fmt .Fprintln (os .Stderr , "#### LOGS ####" )
132159 vm .WriteLogs (os .Stderr , statedb .Logs ())
160+ }
133161
162+ if ctx .GlobalBool (StatDumpFlag .Name ) {
134163 var mem goruntime.MemStats
135164 goruntime .ReadMemStats (& mem )
136165 fmt .Fprintf (os .Stderr , `evm execution time: %v
0 commit comments