Skip to content

Commit

Permalink
fix(paratime): Make paratime statistics consistent with other cmds
Browse files Browse the repository at this point in the history
  • Loading branch information
matevz committed May 29, 2023
1 parent 67aa99f commit fd4de38
Showing 1 changed file with 6 additions and 17 deletions.
23 changes: 6 additions & 17 deletions cmd/paratime/statistics.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (

"github.com/olekukonko/tablewriter"
"github.com/spf13/cobra"
flag "github.com/spf13/pflag"

"github.com/oasisprotocol/oasis-core/go/common/cbor"
"github.com/oasisprotocol/oasis-core/go/common/crypto/signature"
Expand All @@ -28,17 +27,7 @@ import (
"github.com/oasisprotocol/cli/metadata"
)

var (
writeCSV bool
fileCSV string

csvFlags *flag.FlagSet = func() *flag.FlagSet {
fs := flag.NewFlagSet("", flag.ContinueOnError)
fs.BoolVar(&writeCSV, "write-csv", false, "write stats to CSV")
fs.StringVar(&fileCSV, "csv-file", "", "custom CSV file path")
return fs
}()
)
var fileCSV string

type runtimeStats struct {
// Rounds.
Expand Down Expand Up @@ -464,14 +453,12 @@ var statsCmd = &cobra.Command{
stats.prepareEntitiesOutput(entityMetadataLookup)
stats.printStats()

if !writeCSV {
if fileCSV == "" {
stats.printEntityStats()
return
}

// Also save entity stats in a csv.
if fileCSV == "" {
fileCSV = fmt.Sprintf("runtime-%s-%d-%d-stats.csv", runtimeID, startHeight, endHeight)
}
fout, err := os.Create(fileCSV)
cobra.CheckErr(err)
defer fout.Close()
Expand Down Expand Up @@ -561,7 +548,9 @@ func (s *runtimeStats) printStats() {
fmt.Println()
fmt.Printf("%-26s %d", "Suspended:", s.suspendedRounds)
fmt.Println()
}

func (s *runtimeStats) printEntityStats() {
fmt.Println("\n=== ENTITY STATISTICS ===")
table := tablewriter.NewWriter(os.Stdout)
table.SetBorders(tablewriter.Border{Left: true, Top: false, Right: true, Bottom: false})
Expand All @@ -573,5 +562,5 @@ func (s *runtimeStats) printStats() {

func init() {
statsCmd.Flags().AddFlagSet(common.SelectorNPFlags)
statsCmd.Flags().AddFlagSet(csvFlags)
statsCmd.Flags().StringVarP(&fileCSV, "output-file", "o", "", "output statistics into specified CSV file")
}

0 comments on commit fd4de38

Please sign in to comment.