Add toggle for badger, flag out gas tracing

Signed-off-by: Jakub Sztandera <kubuxu@protocol.ai>
This commit is contained in:
Jakub Sztandera 2020-09-22 00:46:31 +02:00
parent 0771c23fb0
commit 55c6b88537
No known key found for this signature in database
GPG Key ID: 9A9AF56F8B3879BA
3 changed files with 75 additions and 58 deletions

View File

@ -459,8 +459,10 @@ func (rt *Runtime) stateCommit(oldh, newh cid.Cid) aerrors.ActorError {
} }
func (rt *Runtime) finilizeGasTracing() { func (rt *Runtime) finilizeGasTracing() {
if rt.lastGasCharge != nil { if enableTracing {
rt.lastGasCharge.TimeTaken = time.Since(rt.lastGasChargeTime) if rt.lastGasCharge != nil {
rt.lastGasCharge.TimeTaken = time.Since(rt.lastGasChargeTime)
}
} }
} }
@ -489,35 +491,39 @@ func (rt *Runtime) chargeGasFunc(skip int) func(GasCharge) {
} }
var enableTracing = false
func (rt *Runtime) chargeGasInternal(gas GasCharge, skip int) aerrors.ActorError { func (rt *Runtime) chargeGasInternal(gas GasCharge, skip int) aerrors.ActorError {
toUse := gas.Total() toUse := gas.Total()
var callers [10]uintptr if enableTracing {
var callers [10]uintptr
cout := 0 //gruntime.Callers(2+skip, callers[:]) cout := 0 //gruntime.Callers(2+skip, callers[:])
now := build.Clock.Now() now := build.Clock.Now()
if rt.lastGasCharge != nil { if rt.lastGasCharge != nil {
rt.lastGasCharge.TimeTaken = now.Sub(rt.lastGasChargeTime) rt.lastGasCharge.TimeTaken = now.Sub(rt.lastGasChargeTime)
}
gasTrace := types.GasTrace{
Name: gas.Name,
Extra: gas.Extra,
TotalGas: toUse,
ComputeGas: gas.ComputeGas,
StorageGas: gas.StorageGas,
TotalVirtualGas: gas.VirtualCompute*GasComputeMulti + gas.VirtualStorage*GasStorageMulti,
VirtualComputeGas: gas.VirtualCompute,
VirtualStorageGas: gas.VirtualStorage,
Callers: callers[:cout],
}
rt.executionTrace.GasCharges = append(rt.executionTrace.GasCharges, &gasTrace)
rt.lastGasChargeTime = now
rt.lastGasCharge = &gasTrace
} }
gasTrace := types.GasTrace{
Name: gas.Name,
Extra: gas.Extra,
TotalGas: toUse,
ComputeGas: gas.ComputeGas,
StorageGas: gas.StorageGas,
TotalVirtualGas: gas.VirtualCompute*GasComputeMulti + gas.VirtualStorage*GasStorageMulti,
VirtualComputeGas: gas.VirtualCompute,
VirtualStorageGas: gas.VirtualStorage,
Callers: callers[:cout],
}
rt.executionTrace.GasCharges = append(rt.executionTrace.GasCharges, &gasTrace)
rt.lastGasChargeTime = now
rt.lastGasCharge = &gasTrace
// overflow safe // overflow safe
if rt.gasUsed > rt.gasAvailable-toUse { if rt.gasUsed > rt.gasAvailable-toUse {
rt.gasUsed = rt.gasAvailable rt.gasUsed = rt.gasAvailable

View File

@ -227,14 +227,21 @@ func (vm *VM) send(ctx context.Context, msg *types.Message, parent *Runtime,
} }
rt := vm.makeRuntime(ctx, msg, origin, on, gasUsed, nac) rt := vm.makeRuntime(ctx, msg, origin, on, gasUsed, nac)
rt.lastGasChargeTime = start if enableTracing {
rt.lastGasChargeTime = start
if parent != nil {
rt.lastGasChargeTime = parent.lastGasChargeTime
rt.lastGasCharge = parent.lastGasCharge
defer func() {
parent.lastGasChargeTime = rt.lastGasChargeTime
parent.lastGasCharge = rt.lastGasCharge
}()
}
}
if parent != nil { if parent != nil {
rt.lastGasChargeTime = parent.lastGasChargeTime
rt.lastGasCharge = parent.lastGasCharge
defer func() { defer func() {
parent.gasUsed = rt.gasUsed parent.gasUsed += rt.gasUsed
parent.lastGasChargeTime = rt.lastGasChargeTime
parent.lastGasCharge = rt.lastGasCharge
}() }()
} }
if gasCharge != nil { if gasCharge != nil {

View File

@ -119,33 +119,37 @@ var importBenchCmd = &cli.Command{
tdir = tmp tdir = tmp
} }
bdgOpt := badger.DefaultOptions var bds datastore.Batching
bdgOpt.GcInterval = 0 if false {
bdgOpt.Options = bdg.DefaultOptions("") cache := 512
bdgOpt.Options.SyncWrites = false bds, err = pebbleds.NewDatastore(tdir, &pebble.Options{
bdgOpt.Options.Truncate = true // Pebble has a single combined cache area and the write
bdgOpt.Options.DetectConflicts = false // buffers are taken from this too. Assign all available
// memory allowance for cache.
cache := 512 Cache: pebble.NewCache(int64(cache * 1024 * 1024)),
bds, err := pebbleds.NewDatastore(tdir, &pebble.Options{ // The size of memory table(as well as the write buffer).
// Pebble has a single combined cache area and the write // Note, there may have more than two memory tables in the system.
// buffers are taken from this too. Assign all available // MemTableStopWritesThreshold can be configured to avoid the memory abuse.
// memory allowance for cache. MemTableSize: cache * 1024 * 1024 / 4,
Cache: pebble.NewCache(int64(cache * 1024 * 1024)), // The default compaction concurrency(1 thread),
// The size of memory table(as well as the write buffer). // Here use all available CPUs for faster compaction.
// Note, there may have more than two memory tables in the system. MaxConcurrentCompactions: runtime.NumCPU(),
// MemTableStopWritesThreshold can be configured to avoid the memory abuse. // Per-level options. Options for at least one level must be specified. The
MemTableSize: cache * 1024 * 1024 / 4, // options for the last level are used for all subsequent levels.
// The default compaction concurrency(1 thread), Levels: []pebble.LevelOptions{
// Here use all available CPUs for faster compaction. {TargetFileSize: 2 * 1024 * 1024, FilterPolicy: bloom.FilterPolicy(10)},
MaxConcurrentCompactions: runtime.NumCPU(), },
// Per-level options. Options for at least one level must be specified. The Logger: log,
// options for the last level are used for all subsequent levels. })
Levels: []pebble.LevelOptions{ } else {
{TargetFileSize: 2 * 1024 * 1024, FilterPolicy: bloom.FilterPolicy(10)}, bdgOpt := badger.DefaultOptions
}, bdgOpt.GcInterval = 0
Logger: log, bdgOpt.Options = bdg.DefaultOptions("")
}) bdgOpt.Options.SyncWrites = false
bdgOpt.Options.Truncate = true
bdgOpt.Options.DetectConflicts = false
bds, err = badger.NewDatastore(tdir, &bdgOpt)
}
if err != nil { if err != nil {
return err return err
} }