@@ -24,9 +24,36 @@ import (
24
24
"os"
25
25
26
26
benchparse "golang.org/x/tools/benchmark/parse"
27
- "k8s.io/kubernetes/test/e2e/perftype"
28
27
)
29
28
29
+ // TODO(random-liu): Replace this with prometheus' data model.
30
+
31
+ // The following performance data structures are generalized and well-formatted.
32
+ // They can be pretty printed in json format and be analyzed by other performance
33
+ // analyzing tools, such as Perfdash (k8s.io/contrib/perfdash).
34
+
35
+ // DataItem is the data point.
36
+ type DataItem struct {
37
+ // Data is a map from bucket to real data point (e.g. "Perc90" -> 23.5). Notice
38
+ // that all data items with the same label combination should have the same buckets.
39
+ Data map [string ]float64 `json:"data"`
40
+ // Unit is the data unit. Notice that all data items with the same label combination
41
+ // should have the same unit.
42
+ Unit string `json:"unit"`
43
+ // Labels is the labels of the data item.
44
+ Labels map [string ]string `json:"labels,omitempty"`
45
+ }
46
+
47
+ // PerfData contains all data items generated in current test.
48
+ type PerfData struct {
49
+ // Version is the version of the metrics. The metrics consumer could use the version
50
+ // to detect metrics version change and decide what version to support.
51
+ Version string `json:"version"`
52
+ DataItems []DataItem `json:"dataItems"`
53
+ // Labels is the labels of the dataset.
54
+ Labels map [string ]string `json:"labels,omitempty"`
55
+ }
56
+
30
57
func main () {
31
58
err := run ()
32
59
if err != nil {
@@ -42,7 +69,7 @@ func run() error {
42
69
if err != nil {
43
70
return err
44
71
}
45
- data := perftype. PerfData {Version : "v1" }
72
+ data := PerfData {Version : "v1" }
46
73
for _ , benchMarks := range benchmarkSet {
47
74
for _ , benchMark := range benchMarks {
48
75
data .DataItems = appendIfMeasured (data .DataItems , benchMark , benchparse .NsPerOp , "time" , "μs" , benchMark .NsPerOp / 1000.0 )
@@ -63,11 +90,11 @@ func run() error {
63
90
return ioutil .WriteFile (os .Args [1 ], formatted .Bytes (), 0664 )
64
91
}
65
92
66
- func appendIfMeasured (items []perftype. DataItem , benchmark * benchparse.Benchmark , metricType int , metricName string , unit string , value float64 ) []perftype. DataItem {
93
+ func appendIfMeasured (items []DataItem , benchmark * benchparse.Benchmark , metricType int , metricName string , unit string , value float64 ) []DataItem {
67
94
if metricType != 0 && (benchmark .Measured & metricType ) == 0 {
68
95
return items
69
96
}
70
- return append (items , perftype. DataItem {
97
+ return append (items , DataItem {
71
98
Unit : unit ,
72
99
Labels : map [string ]string {
73
100
"benchmark" : benchmark .Name ,
0 commit comments