Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: filecoin-project/lotus
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 03f2ea0952a18d73be5cd1f2caf75ec8631753ba
Choose a base ref
..
head repository: filecoin-project/lotus
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 5abc44c9b049a5473e9f33dde630fc639ba7a5f5
Choose a head ref
Showing with 20 additions and 9 deletions.
  1. +20 −9 cmd/lotus-shed/msg.go
29 changes: 20 additions & 9 deletions cmd/lotus-shed/msg.go
Original file line number Diff line number Diff line change
@@ -96,28 +96,39 @@ var msgCmd = &cli.Command{
}

if cctx.Bool("gas-stats") {
var printTrace func(descPfx string, trace types.ExecutionTrace)
printTrace = func(descPfx string, trace types.ExecutionTrace) {
var printTrace func(descPfx string, trace types.ExecutionTrace) error
printTrace = func(descPfx string, trace types.ExecutionTrace) error {
typ := "Message"
if descPfx != "" {
typ = "Subcall"
}
_, _ = fmt.Fprintln(cctx.App.Writer, color.New(color.Bold).Sprint(fmt.Sprintf("%s (%s%s) gas charges:", typ, descPfx, trace.Msg.To)))
statsTable(cctx.App.Writer, trace, false)
if err := statsTable(cctx.App.Writer, trace, false); err != nil {
return err
}
for _, subtrace := range trace.Subcalls {
_, _ = fmt.Fprintln(cctx.App.Writer)
printTrace(descPfx+trace.Msg.To.String()+"➜", subtrace)
if err := printTrace(descPfx+trace.Msg.To.String()+"➜", subtrace); err != nil {
return err
}
}
return nil
}
if err := printTrace("", res.ExecutionTrace); err != nil {
return err
}
printTrace("", res.ExecutionTrace)
if len(res.ExecutionTrace.Subcalls) > 0 {
_, _ = fmt.Fprintln(cctx.App.Writer)
_, _ = fmt.Fprintln(cctx.App.Writer, color.New(color.Bold).Sprint("Total gas charges:"))
statsTable(cctx.App.Writer, res.ExecutionTrace, true)
if err := statsTable(cctx.App.Writer, res.ExecutionTrace, true); err != nil {
return err
}
perCallTrace := gasTracesPerCall(res.ExecutionTrace)
_, _ = fmt.Fprintln(cctx.App.Writer)
_, _ = fmt.Fprintln(cctx.App.Writer, color.New(color.Bold).Sprint("Gas charges per call:"))
statsTable(cctx.App.Writer, perCallTrace, false)
if err := statsTable(cctx.App.Writer, perCallTrace, false); err != nil {
return err
}
}
}
}
@@ -408,7 +419,7 @@ func accumGasTallies(charges map[string]*gasTally, totals *gasTally, trace types
}
}

func statsTable(out io.Writer, trace types.ExecutionTrace, recurse bool) {
func statsTable(out io.Writer, trace types.ExecutionTrace, recurse bool) error {
tw := tablewriter.New(
tablewriter.Col("Type"),
tablewriter.Col("Count", tablewriter.RightAlign()),
@@ -454,7 +465,7 @@ func statsTable(out io.Writer, trace types.ExecutionTrace, recurse bool) {
"Total Gas": totals.storageGas + totals.computeGas,
"T%": "100.00",
})
tw.Flush(out, tablewriter.WithBorders())
return tw.Flush(out, tablewriter.WithBorders())
}

// Takes an execution trace and returns a new trace that groups all the gas charges by the message