Skip to content

Commit

Permalink
Merge pull request #4230 from filecoin-project/feat/inspect-counts
Browse files Browse the repository at this point in the history
Add message counts to inspect chain output
  • Loading branch information
magik6k authored Oct 8, 2020
2 parents 8f35a5c + 12cd478 commit 264fe4e
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions cli/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -449,11 +449,16 @@ var chainInspectUsage = &cli.Command{
bySender := make(map[string]int64)
byDest := make(map[string]int64)
byMethod := make(map[string]int64)
bySenderC := make(map[string]int64)
byDestC := make(map[string]int64)
byMethodC := make(map[string]int64)

var sum int64
for _, m := range msgs {
bySender[m.Message.From.String()] += m.Message.GasLimit
bySenderC[m.Message.From.String()]++
byDest[m.Message.To.String()] += m.Message.GasLimit
byDestC[m.Message.To.String()]++
sum += m.Message.GasLimit

code, err := lookupActorCode(m.Message.To)
Expand All @@ -464,7 +469,7 @@ var chainInspectUsage = &cli.Command{
mm := stmgr.MethodsMap[code][m.Message.Method]

byMethod[mm.Name] += m.Message.GasLimit

byMethodC[mm.Name]++
}

type keyGasPair struct {
Expand Down Expand Up @@ -496,19 +501,19 @@ var chainInspectUsage = &cli.Command{
fmt.Printf("By Sender:\n")
for i := 0; i < numRes && i < len(senderVals); i++ {
sv := senderVals[i]
fmt.Printf("%s\t%0.2f%%\t(%d)\n", sv.Key, (100*float64(sv.Gas))/float64(sum), sv.Gas)
fmt.Printf("%s\t%0.2f%%\t(total: %d, count: %d)\n", sv.Key, (100*float64(sv.Gas))/float64(sum), sv.Gas, bySenderC[sv.Key])
}
fmt.Println()
fmt.Printf("By Receiver:\n")
for i := 0; i < numRes && i < len(destVals); i++ {
sv := destVals[i]
fmt.Printf("%s\t%0.2f%%\t(%d)\n", sv.Key, (100*float64(sv.Gas))/float64(sum), sv.Gas)
fmt.Printf("%s\t%0.2f%%\t(total: %d, count: %d)\n", sv.Key, (100*float64(sv.Gas))/float64(sum), sv.Gas, byDestC[sv.Key])
}
fmt.Println()
fmt.Printf("By Method:\n")
for i := 0; i < numRes && i < len(methodVals); i++ {
sv := methodVals[i]
fmt.Printf("%s\t%0.2f%%\t(%d)\n", sv.Key, (100*float64(sv.Gas))/float64(sum), sv.Gas)
fmt.Printf("%s\t%0.2f%%\t(total: %d, count: %d)\n", sv.Key, (100*float64(sv.Gas))/float64(sum), sv.Gas, byMethodC[sv.Key])
}

return nil
Expand Down

0 comments on commit 264fe4e

Please sign in to comment.