2020-04-08 22:27:31 +00:00
|
|
|
package types
|
|
|
|
|
2020-06-11 19:59:39 +00:00
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
2020-10-14 05:10:37 +00:00
|
|
|
"regexp"
|
2020-06-11 19:59:39 +00:00
|
|
|
"runtime"
|
|
|
|
"strings"
|
|
|
|
"time"
|
|
|
|
)
|
2020-06-02 19:53:24 +00:00
|
|
|
|
2020-06-11 00:47:28 +00:00
|
|
|
type ExecutionTrace struct {
|
2020-06-11 19:59:39 +00:00
|
|
|
Msg *Message
|
|
|
|
MsgRct *MessageReceipt
|
|
|
|
Error string
|
|
|
|
Duration time.Duration
|
|
|
|
GasCharges []*GasTrace
|
2020-04-08 22:27:31 +00:00
|
|
|
|
2020-06-11 00:47:28 +00:00
|
|
|
Subcalls []ExecutionTrace
|
2020-04-08 22:27:31 +00:00
|
|
|
}
|
2020-06-11 19:59:39 +00:00
|
|
|
|
|
|
|
type GasTrace struct {
|
2020-06-12 16:49:29 +00:00
|
|
|
Name string
|
|
|
|
|
2020-06-25 14:46:50 +00:00
|
|
|
Location []Loc `json:"loc"`
|
|
|
|
TotalGas int64 `json:"tg"`
|
|
|
|
ComputeGas int64 `json:"cg"`
|
|
|
|
StorageGas int64 `json:"sg"`
|
|
|
|
TotalVirtualGas int64 `json:"vtg"`
|
|
|
|
VirtualComputeGas int64 `json:"vcg"`
|
|
|
|
VirtualStorageGas int64 `json:"vsg"`
|
|
|
|
|
|
|
|
TimeTaken time.Duration `json:"tt"`
|
|
|
|
Extra interface{} `json:"ex,omitempty"`
|
2020-06-11 19:59:39 +00:00
|
|
|
|
|
|
|
Callers []uintptr `json:"-"`
|
|
|
|
}
|
|
|
|
|
2020-06-12 16:49:29 +00:00
|
|
|
type Loc struct {
|
|
|
|
File string
|
|
|
|
Line int
|
|
|
|
Function string
|
|
|
|
}
|
|
|
|
|
2022-11-16 20:07:23 +00:00
|
|
|
func (et ExecutionTrace) SumGas() GasTrace {
|
|
|
|
return SumGas(et.GasCharges)
|
|
|
|
}
|
|
|
|
|
|
|
|
func SumGas(charges []*GasTrace) GasTrace {
|
|
|
|
var out GasTrace
|
|
|
|
for _, gc := range charges {
|
|
|
|
out.TotalGas += gc.TotalGas
|
|
|
|
out.ComputeGas += gc.ComputeGas
|
|
|
|
out.StorageGas += gc.StorageGas
|
|
|
|
|
|
|
|
out.TotalVirtualGas += gc.TotalVirtualGas
|
|
|
|
out.VirtualComputeGas += gc.VirtualComputeGas
|
|
|
|
out.VirtualStorageGas += gc.VirtualStorageGas
|
|
|
|
}
|
|
|
|
|
|
|
|
return out
|
|
|
|
}
|
|
|
|
|
2020-06-12 16:49:29 +00:00
|
|
|
func (l Loc) Show() bool {
|
|
|
|
ignorePrefix := []string{
|
|
|
|
"reflect.",
|
|
|
|
"github.com/filecoin-project/lotus/chain/vm.(*Invoker).transform",
|
|
|
|
"github.com/filecoin-project/go-amt-ipld/",
|
|
|
|
}
|
|
|
|
for _, pre := range ignorePrefix {
|
|
|
|
if strings.HasPrefix(l.Function, pre) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
func (l Loc) String() string {
|
|
|
|
file := strings.Split(l.File, "/")
|
|
|
|
|
|
|
|
fn := strings.Split(l.Function, "/")
|
|
|
|
var fnpkg string
|
|
|
|
if len(fn) > 2 {
|
|
|
|
fnpkg = strings.Join(fn[len(fn)-2:], "/")
|
|
|
|
} else {
|
|
|
|
fnpkg = l.Function
|
|
|
|
}
|
|
|
|
|
|
|
|
return fmt.Sprintf("%s@%s:%d", fnpkg, file[len(file)-1], l.Line)
|
|
|
|
}
|
|
|
|
|
2020-10-14 05:10:37 +00:00
|
|
|
var importantRegex = regexp.MustCompile(`github.com/filecoin-project/specs-actors/(v\d+/)?actors/builtin`)
|
|
|
|
|
2020-06-12 16:49:29 +00:00
|
|
|
func (l Loc) Important() bool {
|
2020-10-14 05:10:37 +00:00
|
|
|
return importantRegex.MatchString(l.Function)
|
2020-06-12 16:49:29 +00:00
|
|
|
}
|
|
|
|
|
2020-06-11 19:59:39 +00:00
|
|
|
func (gt *GasTrace) MarshalJSON() ([]byte, error) {
|
|
|
|
type GasTraceCopy GasTrace
|
2020-06-12 16:49:29 +00:00
|
|
|
if len(gt.Location) == 0 {
|
2020-06-11 19:59:39 +00:00
|
|
|
if len(gt.Callers) != 0 {
|
|
|
|
frames := runtime.CallersFrames(gt.Callers)
|
|
|
|
for {
|
|
|
|
frame, more := frames.Next()
|
2020-06-12 16:49:29 +00:00
|
|
|
if frame.Function == "github.com/filecoin-project/lotus/chain/vm.(*VM).ApplyMessage" {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
l := Loc{
|
|
|
|
File: frame.File,
|
|
|
|
Line: frame.Line,
|
|
|
|
Function: frame.Function,
|
|
|
|
}
|
|
|
|
gt.Location = append(gt.Location, l)
|
2020-06-11 19:59:39 +00:00
|
|
|
if !more {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cpy := (*GasTraceCopy)(gt)
|
|
|
|
return json.Marshal(cpy)
|
|
|
|
}
|