Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use env var to enable gas tracing #4653

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 40 additions & 33 deletions pkg/vm/gas/gas_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package gas

import (
"fmt"
"os"
"time"

"github.com/filecoin-project/go-state-types/exitcode"
Expand Down Expand Up @@ -41,46 +42,52 @@ func (t *GasTracker) Charge(gas GasCharge, msg string, args ...interface{}) {
}
}

// EnableGasTracing, if true, outputs gas tracing in execution traces.
var EnableGasTracing = os.Getenv("LOTUS_VM_ENABLE_GAS_TRACING_VERY_SLOW") == "1"

// TryCharge charges `amount` or `RemainingGas()``, whichever is smaller.
//
// Returns `True` if the there was enough gas To pay for `amount`.
func (t *GasTracker) TryCharge(gasCharge GasCharge) bool {
toUse := gasCharge.Total()
var callers [10]uintptr
cout := 0 //gruntime.Callers(2+skip, callers[:])

now := time.Now()
if t.LastGasCharge != nil {
t.LastGasCharge.TimeTaken = now.Sub(t.LastGasChargeTime)
//code for https://github.com/filecoin-project/venus/issues/4610
if EnableGasTracing {
var callers [10]uintptr
cout := 0 //gruntime.Callers(2+skip, callers[:])

now := time.Now()
if t.LastGasCharge != nil {
t.LastGasCharge.TimeTaken = now.Sub(t.LastGasChargeTime)
}

gasTrace := types2.GasTrace{
Name: gasCharge.Name,
Extra: gasCharge.Extra,

TotalGas: toUse,
ComputeGas: gasCharge.ComputeGas,
StorageGas: gasCharge.StorageGas,

//TotalVirtualGas: gasCharge.VirtualCompute*GasComputeMulti + gasCharge.VirtualStorage*GasStorageMulti,
TotalVirtualGas: gasCharge.VirtualCompute + gasCharge.VirtualStorage,
VirtualComputeGas: gasCharge.VirtualCompute,
VirtualStorageGas: gasCharge.VirtualStorage,

Callers: callers[:cout],
}

if gasTrace.VirtualStorageGas == 0 {
gasTrace.VirtualStorageGas = gasTrace.StorageGas
}
if gasTrace.VirtualComputeGas == 0 {
gasTrace.VirtualComputeGas = gasTrace.ComputeGas
}

t.ExecutionTrace.GasCharges = append(t.ExecutionTrace.GasCharges, &gasTrace)
t.LastGasChargeTime = now
t.LastGasCharge = &gasTrace
}

gasTrace := types2.GasTrace{
Name: gasCharge.Name,
Extra: gasCharge.Extra,

TotalGas: toUse,
ComputeGas: gasCharge.ComputeGas,
StorageGas: gasCharge.StorageGas,

//TotalVirtualGas: gasCharge.VirtualCompute*GasComputeMulti + gasCharge.VirtualStorage*GasStorageMulti,
TotalVirtualGas: gasCharge.VirtualCompute + gasCharge.VirtualStorage,
VirtualComputeGas: gasCharge.VirtualCompute,
VirtualStorageGas: gasCharge.VirtualStorage,

Callers: callers[:cout],
}

if gasTrace.VirtualStorageGas == 0 {
gasTrace.VirtualStorageGas = gasTrace.StorageGas
}
if gasTrace.VirtualComputeGas == 0 {
gasTrace.VirtualComputeGas = gasTrace.ComputeGas
}

t.ExecutionTrace.GasCharges = append(t.ExecutionTrace.GasCharges, &gasTrace)
t.LastGasChargeTime = now
t.LastGasCharge = &gasTrace

// overflow safe
if t.GasUsed > t.GasAvailable-toUse {
t.GasUsed = t.GasAvailable
Expand Down