diff options
author | Péter Szilágyi <peterke@gmail.com> | 2017-03-02 19:01:01 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-03-02 19:01:01 +0800 |
commit | 82e7c1d1241737fd0ae9b25e0f20857b8597b148 (patch) | |
tree | e4a0e97dc85578b374102072fa73249baa196bc0 /cmd/evm | |
parent | c52ab932e61ef9eba37c107e8b58b22c7d32e6c2 (diff) | |
parent | f30733c806561a97900613517dade377bf57528c (diff) | |
download | dexon-82e7c1d1241737fd0ae9b25e0f20857b8597b148.tar dexon-82e7c1d1241737fd0ae9b25e0f20857b8597b148.tar.gz dexon-82e7c1d1241737fd0ae9b25e0f20857b8597b148.tar.bz2 dexon-82e7c1d1241737fd0ae9b25e0f20857b8597b148.tar.lz dexon-82e7c1d1241737fd0ae9b25e0f20857b8597b148.tar.xz dexon-82e7c1d1241737fd0ae9b25e0f20857b8597b148.tar.zst dexon-82e7c1d1241737fd0ae9b25e0f20857b8597b148.zip |
Merge pull request #3728 from obscuren/format-trace
core/evm, core/vm: improved evm trace output
Diffstat (limited to 'cmd/evm')
-rw-r--r-- | cmd/evm/main.go | 5 | ||||
-rw-r--r-- | cmd/evm/runner.go | 82 |
2 files changed, 44 insertions, 43 deletions
diff --git a/cmd/evm/main.go b/cmd/evm/main.go index cc4f8a49c..5f85f484e 100644 --- a/cmd/evm/main.go +++ b/cmd/evm/main.go @@ -66,10 +66,6 @@ var ( Name: "input", Usage: "input for the EVM", } - SysStatFlag = cli.BoolFlag{ - Name: "sysstat", - Usage: "display system stats", - } VerbosityFlag = cli.IntFlag{ Name: "verbosity", Usage: "sets the verbosity level", @@ -89,7 +85,6 @@ func init() { CreateFlag, DebugFlag, VerbosityFlag, - SysStatFlag, CodeFlag, CodeFileFlag, GasFlag, diff --git a/cmd/evm/runner.go b/cmd/evm/runner.go index 0bed46894..6ef9230f4 100644 --- a/cmd/evm/runner.go +++ b/cmd/evm/runner.go @@ -25,6 +25,7 @@ import ( goruntime "runtime" + "github.com/ethereum/go-ethereum/cmd/evm/internal/compiler" "github.com/ethereum/go-ethereum/cmd/utils" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/state" @@ -53,7 +54,6 @@ func runCmd(ctx *cli.Context) error { statedb, _ = state.New(common.Hash{}, db) sender = common.StringToAddress("sender") logger = vm.NewStructLogger(nil) - tstart = time.Now() ) statedb.CreateAccount(sender) @@ -62,7 +62,18 @@ func runCmd(ctx *cli.Context) error { ret []byte err error ) - if ctx.GlobalString(CodeFlag.Name) != "" { + if fn := ctx.Args().First(); len(fn) > 0 { + src, err := ioutil.ReadFile(fn) + if err != nil { + return err + } + + bin, err := compiler.Compile(fn, src, false) + if err != nil { + return err + } + code = common.Hex2Bytes(bin) + } else if ctx.GlobalString(CodeFlag.Name) != "" { code = common.Hex2Bytes(ctx.GlobalString(CodeFlag.Name)) } else { var hexcode []byte @@ -84,59 +95,54 @@ func runCmd(ctx *cli.Context) error { code = common.Hex2Bytes(string(bytes.TrimRight(hexcode, "\n"))) } + runtimeConfig := runtime.Config{ + Origin: sender, + State: statedb, + GasLimit: ctx.GlobalUint64(GasFlag.Name), + GasPrice: utils.GlobalBig(ctx, PriceFlag.Name), + Value: utils.GlobalBig(ctx, ValueFlag.Name), + EVMConfig: vm.Config{ + Tracer: logger, + Debug: ctx.GlobalBool(DebugFlag.Name), + DisableGasMetering: ctx.GlobalBool(DisableGasMeteringFlag.Name), + }, + } + + tstart := time.Now() if ctx.GlobalBool(CreateFlag.Name) { input := append(code, common.Hex2Bytes(ctx.GlobalString(InputFlag.Name))...) - ret, _, err = runtime.Create(input, &runtime.Config{ - Origin: sender, - State: statedb, - GasLimit: ctx.GlobalUint64(GasFlag.Name), - GasPrice: utils.GlobalBig(ctx, PriceFlag.Name), - Value: utils.GlobalBig(ctx, ValueFlag.Name), - EVMConfig: vm.Config{ - Tracer: logger, - Debug: ctx.GlobalBool(DebugFlag.Name), - DisableGasMetering: ctx.GlobalBool(DisableGasMeteringFlag.Name), - }, - }) + ret, _, err = runtime.Create(input, &runtimeConfig) } else { receiver := common.StringToAddress("receiver") statedb.SetCode(receiver, code) - ret, err = runtime.Call(receiver, common.Hex2Bytes(ctx.GlobalString(InputFlag.Name)), &runtime.Config{ - Origin: sender, - State: statedb, - GasLimit: ctx.GlobalUint64(GasFlag.Name), - GasPrice: utils.GlobalBig(ctx, PriceFlag.Name), - Value: utils.GlobalBig(ctx, ValueFlag.Name), - EVMConfig: vm.Config{ - Tracer: logger, - Debug: ctx.GlobalBool(DebugFlag.Name), - DisableGasMetering: ctx.GlobalBool(DisableGasMeteringFlag.Name), - }, - }) + ret, err = runtime.Call(receiver, common.Hex2Bytes(ctx.GlobalString(InputFlag.Name)), &runtimeConfig) } - vmdone := time.Since(tstart) + execTime := time.Since(tstart) if ctx.GlobalBool(DumpFlag.Name) { statedb.Commit(true) fmt.Println(string(statedb.Dump())) } - vm.StdErrFormat(logger.StructLogs()) - if ctx.GlobalBool(SysStatFlag.Name) { + if ctx.GlobalBool(DebugFlag.Name) { + fmt.Fprintln(os.Stderr, "#### TRACE ####") + vm.WriteTrace(os.Stderr, logger.StructLogs()) + fmt.Fprintln(os.Stderr, "#### LOGS ####") + vm.WriteLogs(os.Stderr, statedb.Logs()) + var mem goruntime.MemStats goruntime.ReadMemStats(&mem) - fmt.Printf("vm took %v\n", vmdone) - fmt.Printf(`alloc: %d -tot alloc: %d -no. malloc: %d -heap alloc: %d -heap objs: %d -num gc: %d -`, mem.Alloc, mem.TotalAlloc, mem.Mallocs, mem.HeapAlloc, mem.HeapObjects, mem.NumGC) + fmt.Fprintf(os.Stderr, `evm execution time: %v +heap objects: %d +allocations: %d +total allocations: %d +GC calls: %d + +`, execTime, mem.HeapObjects, mem.Alloc, mem.TotalAlloc, mem.NumGC) } - fmt.Printf("OUT: 0x%x", ret) + fmt.Printf("0x%x", ret) if err != nil { fmt.Printf(" error: %v", err) } |