Skip to content

Commit

Permalink
Merge pull request #4214 from filecoin-project/gas-tracing-public
Browse files Browse the repository at this point in the history
make vm.EnableGasTracing public.
  • Loading branch information
Stebalien authored Oct 7, 2020
2 parents 099b982 + 7cd1330 commit 6eb49b7
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
9 changes: 5 additions & 4 deletions chain/vm/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ import (
"github.com/filecoin-project/lotus/chain/types"
)

// EnableGasTracing, if true, outputs gas tracing in execution traces.
var EnableGasTracing = false

type Runtime struct {
types.Message
rt0.Syscalls
Expand Down Expand Up @@ -459,7 +462,7 @@ func (rt *Runtime) stateCommit(oldh, newh cid.Cid) aerrors.ActorError {
}

func (rt *Runtime) finilizeGasTracing() {
if enableTracing {
if EnableGasTracing {
if rt.lastGasCharge != nil {
rt.lastGasCharge.TimeTaken = time.Since(rt.lastGasChargeTime)
}
Expand Down Expand Up @@ -491,11 +494,9 @@ func (rt *Runtime) chargeGasFunc(skip int) func(GasCharge) {

}

var enableTracing = false

func (rt *Runtime) chargeGasInternal(gas GasCharge, skip int) aerrors.ActorError {
toUse := gas.Total()
if enableTracing {
if EnableGasTracing {
var callers [10]uintptr

cout := 0 //gruntime.Callers(2+skip, callers[:])
Expand Down
20 changes: 20 additions & 0 deletions chain/vm/runtime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,23 @@ func TestRuntimePutErrors(t *testing.T) {
rt.StorePut(&NotAVeryGoodMarshaler{})
t.Error("expected panic")
}

func BenchmarkRuntime_CreateRuntimeChargeGas_TracingDisabled(b *testing.B) {
var (
cst = cbor.NewCborStore(nil)
gch = newGasCharge("foo", 1000, 1000)
)

b.ResetTimer()

EnableGasTracing = false
noop := func() bool { return EnableGasTracing }
for n := 0; n < b.N; n++ {
// flip the value and access it to make sure
// the compiler doesn't optimize away
EnableGasTracing = true
_ = noop()
EnableGasTracing = false
_ = (&Runtime{cst: cst}).chargeGasInternal(gch, 0)
}
}
2 changes: 1 addition & 1 deletion chain/vm/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ func (vm *VM) send(ctx context.Context, msg *types.Message, parent *Runtime,
}

rt := vm.makeRuntime(ctx, msg, origin, on, gasUsed, nac)
if enableTracing {
if EnableGasTracing {
rt.lastGasChargeTime = start
if parent != nil {
rt.lastGasChargeTime = parent.lastGasChargeTime
Expand Down

0 comments on commit 6eb49b7

Please sign in to comment.