-
Notifications
You must be signed in to change notification settings - Fork 0
/
gasTraceUtil.go
53 lines (47 loc) · 1.56 KB
/
gasTraceUtil.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package scenexec
import (
"fmt"
scenmodel "github.com/multiversx/mx-chain-scenario-go/scenario/model"
)
func logGasTrace(ae *ScenarioExecutor) {
if ae.PeekTraceGas() {
scGasTrace := ae.vm.GetGasTrace()
totalGasUsedByAPIs := 0
for scAddress, gasTrace := range scGasTrace {
fmt.Println("Gas Trace for: ", "SC Address", scAddress)
for functionName, value := range gasTrace {
totalGasUsed := uint64(0)
for _, usedGas := range value {
totalGasUsed += usedGas
}
fmt.Println("GasTrace: functionName:", functionName, ", totalGasUsed:", totalGasUsed, ", numberOfCalls:", len(value))
totalGasUsedByAPIs += int(totalGasUsed)
}
fmt.Println("TotalGasUsedByAPIs: ", totalGasUsedByAPIs)
}
}
}
func setGasTraceInMetering(ae *ScenarioExecutor, enable bool) {
if enable && ae.PeekTraceGas() {
ae.vm.SetGasTracing(true)
} else {
ae.vm.SetGasTracing(false)
}
}
func setExternalStepGasTracing(ae *ScenarioExecutor, step *scenmodel.ExternalStepsStep) {
switch step.TraceGas.ToInt() {
case scenmodel.Undefined.ToInt():
ae.scenarioTraceGas = append(ae.scenarioTraceGas, ae.PeekTraceGas())
case scenmodel.TrueValue.ToInt():
ae.scenarioTraceGas = append(ae.scenarioTraceGas, true)
case scenmodel.FalseValue.ToInt():
ae.scenarioTraceGas = append(ae.scenarioTraceGas, false)
}
}
func resetGasTracesIfNewTest(ae *ScenarioExecutor, scenario *scenmodel.Scenario) {
if ae.vm == nil || scenario.IsNewTest {
ae.scenarioTraceGas = make([]bool, 0)
ae.scenarioTraceGas = append(ae.scenarioTraceGas, scenario.TraceGas)
scenario.IsNewTest = false
}
}