7
7
"fmt"
8
8
"io/ioutil"
9
9
"log"
10
+ "sort"
11
+ "strconv"
10
12
"time"
11
13
)
12
14
@@ -18,6 +20,7 @@ const (
18
20
var (
19
21
threshold = flag .Float64 ("threshold" , 0.1 , "Failure threshold." )
20
22
mode = flag .String ("mode" , "compare" , "Mode" )
23
+ baseline = flag .String ("baseline" , "" , "" )
21
24
)
22
25
23
26
type APIResponsiveness struct {
@@ -38,6 +41,7 @@ type Labels struct {
38
41
Scope string `json:"Scope"`
39
42
Subresource string `json:"Subresource"`
40
43
Verb string `json:"Verb"`
44
+ Count string `json:"Count"`
41
45
}
42
46
43
47
func (l * Labels ) asKey () string {
@@ -46,7 +50,14 @@ func (l *Labels) asKey() string {
46
50
key = fmt .Sprintf ("%s/%s" , key , l .Subresource )
47
51
}
48
52
return key
53
+ }
49
54
55
+ func (l * Labels ) count () int {
56
+ i , err := strconv .Atoi (l .Count )
57
+ if err != nil {
58
+ log .Fatalf ("cannot convert count: %s" , l .Count )
59
+ }
60
+ return i
50
61
}
51
62
52
63
func (d * APIResponsiveness ) asMap () map [string ]time.Duration {
@@ -99,32 +110,41 @@ func compareResults(base, result *APIResponsiveness) {
99
110
fmt .Printf ("good: %d, bad %d\n " , good , bad )
100
111
}
101
112
102
- func compare () error {
103
- if flag .NArg () != 2 {
104
- return errors .New ("expected 2 positional arguments: path to baseline and result" )
105
- }
106
-
107
- path := flag .Args ()[0 ]
108
- baseline , err := parseResults (path )
113
+ func compare (result * APIResponsiveness ) error {
114
+ baseline , err := parseResults (* baseline )
109
115
if err != nil {
110
116
return err
111
117
}
112
- path = flag .Args ()[1 ]
113
- result , err := parseResults (path )
114
- if err != nil {
115
- return err
116
-
117
- }
118
118
compareResults (baseline , result )
119
119
return nil
120
120
}
121
121
122
+ func printSorted (result * APIResponsiveness ) {
123
+ sort .Slice (result .DataItems , func (i , j int ) bool {
124
+ return result .DataItems [i ].Labels .count () > result .DataItems [j ].Labels .count ()
125
+ })
126
+ for _ , i := range result .DataItems {
127
+ fmt .Printf ("%d %s\n " , i .Labels .count (), i .Labels .asKey ())
128
+ }
129
+ }
130
+
122
131
func main () {
123
132
flag .Parse ()
124
- var err error
133
+ if flag .NArg () != 1 {
134
+ log .Fatalf ("expected 1 positional arguments: path to result, got: %v" , flag .Args ())
135
+ }
136
+
137
+ result , err := parseResults (flag .Arg (0 ))
138
+ if err != nil {
139
+ log .Fatalf ("error while parsing result: %v" , err )
140
+
141
+ }
142
+
125
143
switch * mode {
126
144
case "compare" :
127
- err = compare ()
145
+ err = compare (result )
146
+ case "sort" :
147
+ printSorted (result )
128
148
default :
129
149
err = errors .New ("unknown mode" )
130
150
}
0 commit comments