Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var FoldTraceCmd = &cobra.Command{ Use: "fold-trace", Short: "Trace an execution trace and fold it for visualization.", Long: usage, Args: cobra.ArbitraryArgs, PreRunE: func(cmd *cobra.Command, args []string) error { return validateInputMetric() }, RunE: func(cmd *cobra.Command, args []string) error { data, err := getInputData(cmd, args) if err != nil { return fmt.Errorf("unable to read input data: %w", err) } td := &TraceData{} err = json.Unmarshal(data, td) if err != nil { return fmt.Errorf("unable to unmarshal input json trace: %w", err) } folded := make(map[string]uint64) contexts := []string{inputRootContextName} currentDepth := uint64(1) lastLabel := "" metricType := inputMetric for idx, op := range td.StructLogs { if op.Depth > currentDepth { contexts = append(contexts, lastLabel) } else if op.Depth < currentDepth { contexts = contexts[:len(contexts)-1] } currentDepth = op.Depth currentLabel := op.OP if isCall(op.OP) { if len(op.Stack) < 6 { log.Warn().Int("stackLength", len(op.Stack)).Msg("detected a call with a stack that's too short") } else { currentLabel = op.OP + " to " + op.Stack[len(op.Stack)-2] } } lastLabel = currentLabel var metricValue uint64 if metricType == "gas" { metricValue = op.GasCost } else if metricType == "actualgas" { metricValue = getActualUsedGas(idx, td) } else { metricValue = 1 } currentMetricPath := strings.Join(contexts, ";") + ";" + currentLabel if !isCall(op.OP) { folded[currentMetricPath] += metricValue } if isCall(op.OP) && len(op.Stack[len(op.Stack)-2]) < 6 { folded[currentMetricPath] += metricValue } log.Trace().Strs("context", contexts).Uint64("depth", currentDepth).Str("currentLabel", currentLabel).Uint64("pc", op.PC).Msg("trace operation") } for context, metric := range folded { fmt.Printf("%s %d\n", context, metric) } return nil }, }
Functions ¶
This section is empty.
Types ¶
type TraceData ¶
type TraceData struct {
StructLogs []TraceOperation `json:"structLogs"`
}
Click to show internal directories.
Click to hide internal directories.