99
1010 "github.com/olekukonko/tablewriter"
1111 "github.com/spf13/cobra"
12- flag "github.com/spf13/pflag"
1312
1413 "github.com/oasisprotocol/oasis-core/go/common/cbor"
1514 "github.com/oasisprotocol/oasis-core/go/common/crypto/signature"
@@ -28,17 +27,7 @@ import (
2827 "github.com/oasisprotocol/cli/metadata"
2928)
3029
31- var (
32- writeCSV bool
33- fileCSV string
34-
35- csvFlags * flag.FlagSet = func () * flag.FlagSet {
36- fs := flag .NewFlagSet ("" , flag .ContinueOnError )
37- fs .BoolVar (& writeCSV , "write-csv" , false , "write stats to CSV" )
38- fs .StringVar (& fileCSV , "csv-file" , "" , "custom CSV file path" )
39- return fs
40- }()
41- )
30+ var fileCSV string
4231
4332type runtimeStats struct {
4433 // Rounds.
@@ -101,8 +90,11 @@ type entityStats struct {
10190}
10291
10392var statsCmd = & cobra.Command {
104- Use : "statistics [<start-height> [<end-height>]]" ,
105- Short : "Show ParaTime statistics" ,
93+ Use : "statistics [<start-height> [<end-height>]]" ,
94+ Short : "Show ParaTime statistics" ,
95+ Long : "Show ParaTime statistics between start-height and end-height round of blocks." +
96+ "\n If negative start-height is passed, it will show statistics for the last given blocks." +
97+ "\n If 0 start-height passed, it will generate statistics from the oldest block available to the endpoint." ,
10698 Aliases : []string {"stats" },
10799 Args : cobra .MaximumNArgs (2 ),
108100 Run : func (cmd * cobra.Command , args []string ) {
@@ -115,7 +107,7 @@ var statsCmd = &cobra.Command{
115107
116108 // Parse command line arguments
117109 var (
118- startHeightArg int64
110+ startHeightArg int64 = - 1
119111 endHeight uint64
120112 )
121113 if argLen := len (args ); argLen > 0 {
@@ -166,12 +158,15 @@ var statsCmd = &cobra.Command{
166158 cobra .CheckErr (err )
167159 signature .SetChainContext (chainCtx )
168160
169- fmt .Printf (
170- "gathering statistics: runtime-id: %s, start-height: %d, end-height: %d\n " ,
171- runtimeID ,
172- startHeight ,
173- endHeight ,
174- )
161+ fmt .Println ("=== PARATIME STATISTICS ===" )
162+ fmt .Printf ("%-26s %s" , "Network:" , npa .PrettyPrintNetwork ())
163+ fmt .Println ()
164+ fmt .Printf ("%-26s %s" , "ParaTime ID:" , runtimeID )
165+ fmt .Println ()
166+ fmt .Printf ("%-26s %8d" , "Start height:" , startHeight )
167+ fmt .Println ()
168+ fmt .Printf ("%-26s %8d" , "End height:" , endHeight )
169+ fmt .Println ()
175170
176171 // Do the actual work
177172 stats := & runtimeStats {
@@ -458,14 +453,12 @@ var statsCmd = &cobra.Command{
458453 stats .prepareEntitiesOutput (entityMetadataLookup )
459454 stats .printStats ()
460455
461- if ! writeCSV {
456+ if fileCSV == "" {
457+ stats .printEntityStats ()
462458 return
463459 }
464460
465461 // Also save entity stats in a csv.
466- if fileCSV == "" {
467- fileCSV = fmt .Sprintf ("runtime-%s-%d-%d-stats.csv" , runtimeID , startHeight , endHeight )
468- }
469462 fout , err := os .Create (fileCSV )
470463 cobra .CheckErr (err )
471464 defer fout .Close ()
@@ -539,15 +532,25 @@ func (s *runtimeStats) prepareEntitiesOutput(
539532}
540533
541534func (s * runtimeStats ) printStats () {
542- fmt .Printf ("ParaTime rounds: %d\n " , s .rounds )
543- fmt .Printf ("Successful rounds: %d\n " , s .successfulRounds )
544- fmt .Printf ("Epoch transition rounds: %d\n " , s .epochTransitionRounds )
545- fmt .Printf ("Proposer timeouted rounds: %d\n " , s .proposerTimeoutedRounds )
546- fmt .Printf ("Failed rounds: %d\n " , s .failedRounds )
547- fmt .Printf ("Discrepancies: %d\n " , s .discrepancyDetected )
548- fmt .Printf ("Discrepancies (timeout): %d\n " , s .discrepancyDetectedTimeout )
549- fmt .Printf ("Suspended: %d\n " , s .suspendedRounds )
535+ fmt .Printf ("%-26s %d" , "ParaTime rounds:" , s .rounds )
536+ fmt .Println ()
537+ fmt .Printf ("%-26s %d" , "Successful rounds:" , s .successfulRounds )
538+ fmt .Println ()
539+ fmt .Printf ("%-26s %d" , "Epoch transition rounds:" , s .epochTransitionRounds )
540+ fmt .Println ()
541+ fmt .Printf ("%-26s %d" , "Proposer timed out rounds:" , s .proposerTimeoutedRounds )
542+ fmt .Println ()
543+ fmt .Printf ("%-26s %d" , "Failed rounds:" , s .failedRounds )
544+ fmt .Println ()
545+ fmt .Printf ("%-26s %d" , "Discrepancies:" , s .discrepancyDetected )
546+ fmt .Println ()
547+ fmt .Printf ("%-26s %d" , "Discrepancies (timeout):" , s .discrepancyDetectedTimeout )
548+ fmt .Println ()
549+ fmt .Printf ("%-26s %d" , "Suspended:" , s .suspendedRounds )
550+ fmt .Println ()
551+ }
550552
553+ func (s * runtimeStats ) printEntityStats () {
551554 fmt .Println ("\n === ENTITY STATISTICS ===" )
552555 table := tablewriter .NewWriter (os .Stdout )
553556 table .SetBorders (tablewriter.Border {Left : true , Top : false , Right : true , Bottom : false })
@@ -559,5 +562,5 @@ func (s *runtimeStats) printStats() {
559562
560563func init () {
561564 statsCmd .Flags ().AddFlagSet (common .SelectorNPFlags )
562- statsCmd .Flags ().AddFlagSet ( csvFlags )
565+ statsCmd .Flags ().StringVarP ( & fileCSV , "output-file" , "o" , "" , "output statistics into specified CSV file" )
563566}
0 commit comments