Skip to content

Commit

Permalink
Merge pull request #5470 from filecoin-project/feat/no-timing-compute…
Browse files Browse the repository at this point in the history
…-state

state compute-state ---html --no-timing flag
  • Loading branch information
magik6k authored Jan 30, 2021
2 parents 3df25df + bb4e3e4 commit d9e0d47
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 18 deletions.
44 changes: 27 additions & 17 deletions cli/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -935,6 +935,10 @@ var stateComputeStateCmd = &cli.Command{
Name: "compute-state-output",
Usage: "a json file containing pre-existing compute-state output, to generate html reports without rerunning state changes",
},
&cli.BoolFlag{
Name: "no-timing",
Usage: "don't show timing information in html traces",
},
},
Action: func(cctx *cli.Context) error {
api, closer, err := GetFullNodeAPI(cctx)
Expand Down Expand Up @@ -1026,7 +1030,9 @@ var stateComputeStateCmd = &cli.Command{
return c.Code, nil
}

return ComputeStateHTMLTempl(os.Stdout, ts, stout, getCode)
_, _ = fmt.Fprintln(os.Stderr, "computed state cid: ", stout.Root)

return ComputeStateHTMLTempl(os.Stdout, ts, stout, !cctx.Bool("no-timing"), getCode)
}

fmt.Println("computed state cid: ", stout.Root)
Expand Down Expand Up @@ -1147,8 +1153,11 @@ var compStateMsg = `
{{if gt (len .Msg.Params) 0}}
<div><pre class="params">{{JsonParams ($code) (.Msg.Method) (.Msg.Params) | html}}</pre></div>
{{end}}
<div><span class="slow-{{IsSlow .Duration}}-{{IsVerySlow .Duration}}">Took {{.Duration}}</span>, <span class="exit{{IntExit .MsgRct.ExitCode}}">Exit: <b>{{.MsgRct.ExitCode}}</b></span>{{if gt (len .MsgRct.Return) 0}}, Return{{end}}</div>
{{if PrintTiming}}
<div><span class="slow-{{IsSlow .Duration}}-{{IsVerySlow .Duration}}">Took {{.Duration}}</span>, <span class="exit{{IntExit .MsgRct.ExitCode}}">Exit: <b>{{.MsgRct.ExitCode}}</b></span>{{if gt (len .MsgRct.Return) 0}}, Return{{end}}</div>
{{else}}
<div><span class="exit{{IntExit .MsgRct.ExitCode}}">Exit: <b>{{.MsgRct.ExitCode}}</b></span>{{if gt (len .MsgRct.Return) 0}}, Return{{end}}</div>
{{end}}
{{if gt (len .MsgRct.Return) 0}}
<div><pre class="ret">{{JsonReturn ($code) (.Msg.Method) (.MsgRct.Return) | html}}</pre></div>
{{end}}
Expand All @@ -1174,7 +1183,7 @@ var compStateMsg = `
{{range .GasCharges}}
<tr><td>{{.Name}}{{if .Extra}}:{{.Extra}}{{end}}</td>
{{template "gasC" .}}
<td>{{.TimeTaken}}</td>
<td>{{if PrintTiming}}{{.TimeTaken}}{{end}}</td>
<td>
{{ $fImp := FirstImportant .Location }}
{{ if $fImp }}
Expand Down Expand Up @@ -1213,7 +1222,7 @@ var compStateMsg = `
{{with SumGas .GasCharges}}
<tr class="sum"><td><b>Sum</b></td>
{{template "gasC" .}}
<td>{{.TimeTaken}}</td>
<td>{{if PrintTiming}}{{.TimeTaken}}{{end}}</td>
<td></td></tr>
{{end}}
</table>
Expand All @@ -1234,19 +1243,20 @@ type compStateHTMLIn struct {
Comp *api.ComputeStateOutput
}

func ComputeStateHTMLTempl(w io.Writer, ts *types.TipSet, o *api.ComputeStateOutput, getCode func(addr address.Address) (cid.Cid, error)) error {
func ComputeStateHTMLTempl(w io.Writer, ts *types.TipSet, o *api.ComputeStateOutput, printTiming bool, getCode func(addr address.Address) (cid.Cid, error)) error {
t, err := template.New("compute_state").Funcs(map[string]interface{}{
"GetCode": getCode,
"GetMethod": getMethod,
"ToFil": toFil,
"JsonParams": JsonParams,
"JsonReturn": jsonReturn,
"IsSlow": isSlow,
"IsVerySlow": isVerySlow,
"IntExit": func(i exitcode.ExitCode) int64 { return int64(i) },
"SumGas": sumGas,
"CodeStr": codeStr,
"Call": call,
"GetCode": getCode,
"GetMethod": getMethod,
"ToFil": toFil,
"JsonParams": JsonParams,
"JsonReturn": jsonReturn,
"IsSlow": isSlow,
"IsVerySlow": isVerySlow,
"IntExit": func(i exitcode.ExitCode) int64 { return int64(i) },
"SumGas": sumGas,
"CodeStr": codeStr,
"Call": call,
"PrintTiming": func() bool { return printTiming },
"FirstImportant": func(locs []types.Loc) *types.Loc {
if len(locs) != 0 {
for _, l := range locs {
Expand Down
2 changes: 1 addition & 1 deletion testplans/lotus-soup/rfwp/html_chain_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func FetchChainState(t *testkit.TestEnvironment, m *testkit.LotusMiner) error {
return c.Code, nil
}

return cli.ComputeStateHTMLTempl(file, tipset, stout, getCode)
return cli.ComputeStateHTMLTempl(file, tipset, stout, true, getCode)
}()
if err != nil {
return err
Expand Down

0 comments on commit d9e0d47

Please sign in to comment.