Use extra field in gastrace

Signed-off-by: Jakub Sztandera <kubuxu@protocol.ai>
This commit is contained in:
Jakub Sztandera 2020-06-15 19:50:43 +02:00
parent 01f0bb3124
commit 8039701f9e
No known key found for this signature in database
GPG Key ID: 9A9AF56F8B3879BA
5 changed files with 23 additions and 11 deletions

View File

@ -30,7 +30,7 @@ type GasTrace struct {
VirtualStorageGas int64 VirtualStorageGas int64
TimeTaken time.Duration TimeTaken time.Duration
Extra interface{} Extra interface{} `json:",omitempty"`
Callers []uintptr `json:"-"` Callers []uintptr `json:"-"`
} }

View File

@ -19,6 +19,8 @@ const (
type GasCharge struct { type GasCharge struct {
Name string Name string
Extra interface{}
ComputeGas int64 ComputeGas int64
StorageGas int64 StorageGas int64
@ -36,6 +38,12 @@ func (g GasCharge) WithVirtual(compute, storage int64) GasCharge {
return out return out
} }
func (g GasCharge) WithExtra(extra interface{}) GasCharge {
out := g
out.Extra = extra
return out
}
func newGasCharge(name string, computeGas int64, storageGas int64) GasCharge { func newGasCharge(name string, computeGas int64, storageGas int64) GasCharge {
return GasCharge{ return GasCharge{
Name: name, Name: name,

View File

@ -108,12 +108,12 @@ func (pl *pricelistV0) OnMethodInvocation(value abi.TokenAmount, methodNum abi.M
// OnIpldGet returns the gas used for storing an object // OnIpldGet returns the gas used for storing an object
func (pl *pricelistV0) OnIpldGet(dataSize int) GasCharge { func (pl *pricelistV0) OnIpldGet(dataSize int) GasCharge {
return newGasCharge(fmt.Sprintf("OnIpldGet:%db", dataSize), pl.ipldGetBase+int64(dataSize)*pl.ipldGetPerByte, 0) return newGasCharge("OnIpldGet", pl.ipldGetBase+int64(dataSize)*pl.ipldGetPerByte, 0).WithExtra(dataSize)
} }
// OnIpldPut returns the gas used for storing an object // OnIpldPut returns the gas used for storing an object
func (pl *pricelistV0) OnIpldPut(dataSize int) GasCharge { func (pl *pricelistV0) OnIpldPut(dataSize int) GasCharge {
return newGasCharge(fmt.Sprintf("OnIpldPut:%db", dataSize), pl.ipldPutBase, int64(dataSize)*pl.ipldPutPerByte) return newGasCharge("OnIpldPut", pl.ipldPutBase, int64(dataSize)*pl.ipldPutPerByte).WithExtra(dataSize)
} }
// OnCreateActor returns the gas used for creating an actor // OnCreateActor returns the gas used for creating an actor
@ -133,7 +133,7 @@ func (pl *pricelistV0) OnVerifySignature(sigType crypto.SigType, planTextSize in
return GasCharge{}, fmt.Errorf("cost function for signature type %d not supported", sigType) return GasCharge{}, fmt.Errorf("cost function for signature type %d not supported", sigType)
} }
sigName, _ := sigType.Name() sigName, _ := sigType.Name()
return newGasCharge("OnVerifySignature/"+sigName, costFn(int64(planTextSize)), 0), nil return newGasCharge("OnVerifySignature", costFn(int64(planTextSize)), 0).WithExtra(sigName), nil
} }
// OnHashing // OnHashing

View File

@ -525,12 +525,16 @@ func (rt *Runtime) chargeGasInternal(gas GasCharge, skip int) aerrors.ActorError
gasTrace := types.GasTrace{ gasTrace := types.GasTrace{
Name: gas.Name, Name: gas.Name,
Extra: gas.Extra,
TotalGas: toUse, TotalGas: toUse,
ComputeGas: gas.ComputeGas, ComputeGas: gas.ComputeGas,
StorageGas: gas.StorageGas, StorageGas: gas.StorageGas,
TotalVirtualGas: gas.VirtualCompute*GasComputeMulti + gas.VirtualStorage*GasStorageMulti, TotalVirtualGas: gas.VirtualCompute*GasComputeMulti + gas.VirtualStorage*GasStorageMulti,
VirtualComputeGas: gas.VirtualCompute, VirtualComputeGas: gas.VirtualCompute,
VirtualStorageGas: gas.VirtualStorage, VirtualStorageGas: gas.VirtualStorage,
Callers: callers[:cout], Callers: callers[:cout],
} }
rt.executionTrace.GasCharges = append(rt.executionTrace.GasCharges, &gasTrace) rt.executionTrace.GasCharges = append(rt.executionTrace.GasCharges, &gasTrace)

View File

@ -1072,7 +1072,7 @@ var compStateMsg = `
{{- end}} {{- end}}
{{range .GasCharges}} {{range .GasCharges}}
<tr><td>{{.Name}}</td> <tr><td>{{.Name}}{{if .Extra}}:{{.Extra}}{{end}}</td>
{{template "gasC" .}} {{template "gasC" .}}
<td>{{.TimeTaken}}</td> <td>{{.TimeTaken}}</td>
<td> <td>