@@ -81,84 +81,90 @@ function generateCommonMetrics(obj, phaseLabels) {
81
81
return metrics ;
82
82
}
83
83
84
+ function makePropMetrics ( metricName , headerSpecs ) {
85
+ return Object . fromEntries (
86
+ headerSpecs . map ( ( [ prop , ...args ] ) => [
87
+ prop ,
88
+ promHeader ( metricName [ prop ] , ...args ) ,
89
+ ] ) ,
90
+ ) ;
91
+ }
92
+
84
93
function generateMetricsFromPrimeData ( data , labels = undefined ) {
85
- let metrics = '' ;
94
+ const metricName = {
95
+ up : 'stat_up' ,
96
+ down : 'stat_down' ,
97
+ max : 'stat_max' ,
98
+ value : 'stat_value' ,
99
+ perCrank : 'stat_per_crank' ,
100
+ } ;
101
+ const propMetrics = makePropMetrics ( metricName , [
102
+ [ 'up' , 'counter' , `Number of increments` ] ,
103
+ [ 'down' , 'counter' , `Number of decrements` ] ,
104
+ [ 'max' , 'gauge' , `Maximum value` ] ,
105
+ [ 'value' , 'gauge' , 'Latest value' ] ,
106
+ [ 'perCrank' , 'gauge' , `Autobench value per crank` ] ,
107
+ ] ) ;
108
+
86
109
const todo = new Set ( Object . keys ( data ) ) ;
87
- for ( const { metricType , key, name, description } of KERNEL_STATS_METRICS ) {
110
+ for ( const { key, name } of KERNEL_STATS_METRICS ) {
88
111
if ( ! ( key in data ) ) {
89
112
// eslint-disable-next-line no-continue
90
113
continue ;
91
114
}
92
115
todo . delete ( key ) ;
93
- if ( 'value' in data [ key ] ) {
94
- metrics += promHeader ( name , metricType , description ) ;
95
- metrics += promValue ( name , data [ key ] . value , labels ) ;
96
- }
97
- if ( 'up' in data [ key ] ) {
98
- const nm = `${ name } _up` ;
99
- metrics += promHeader (
100
- nm ,
101
- 'counter' ,
102
- `${ description } (number of increments)` ,
103
- ) ;
104
- metrics += promValue ( nm , data [ key ] . up , labels ) ;
105
- }
106
- if ( 'down' in data [ key ] ) {
107
- const nm = `${ name } _down` ;
108
- metrics += promHeader (
109
- nm ,
110
- 'counter' ,
111
- `${ description } (number of decrements)` ,
112
- ) ;
113
- metrics += promValue ( nm , data [ key ] . down , labels ) ;
114
- }
115
- if ( 'max' in data [ key ] ) {
116
- const nm = `${ name } _max` ;
117
- metrics += promHeader ( nm , 'gauge' , `${ description } (maximum value)` ) ;
118
- metrics += promValue ( nm , data [ key ] . max , labels ) ;
119
- }
120
- if ( 'perCrank' in data [ key ] ) {
121
- const nm = `${ name } _per_crank` ;
122
- metrics += promHeader ( nm , 'gauge' , `${ description } (value per crank)` ) ;
123
- metrics += promValue ( nm , data [ key ] . perCrank , labels ) ;
116
+ const statLabels = [ ...labels , [ 'stat' , name ] ] ;
117
+
118
+ for ( const prop of Object . keys ( propMetrics ) ) {
119
+ if ( prop in data [ key ] ) {
120
+ propMetrics [ prop ] += promValue (
121
+ metricName [ prop ] ,
122
+ data [ key ] [ prop ] ,
123
+ statLabels ,
124
+ ) ;
125
+ }
124
126
}
125
127
}
126
128
127
129
for ( const key of todo . keys ( ) ) {
128
130
console . warn ( `Unrecognized prime data property ${ key } ` ) ;
129
131
}
130
- return metrics ;
132
+ return Object . values ( propMetrics ) . join ( '' ) ;
131
133
}
132
134
133
135
function generateMetricsFromBenchmarkData ( data , labels = undefined ) {
134
- let metrics = '' ;
136
+ const metricName = {
137
+ delta : 'stat_delta' ,
138
+ deltaPerRound : 'stat_delta_per_round' ,
139
+ } ;
140
+ const propMetrics = makePropMetrics ( metricName , [
141
+ [ 'delta' , 'gauge' , `Autobench benchmark delta` ] ,
142
+ [ 'deltaPerRound' , 'gauge' , `Autobench benchmark delta per round` ] ,
143
+ ] ) ;
144
+
135
145
const todo = new Set ( Object . keys ( data ) ) ;
136
- for ( const { key, name, description } of KERNEL_STATS_METRICS ) {
146
+ for ( const { key, name } of KERNEL_STATS_METRICS ) {
137
147
if ( ! ( key in data ) ) {
138
148
// eslint-disable-next-line no-continue
139
149
continue ;
140
150
}
141
151
todo . delete ( key ) ;
142
- if ( 'delta' in data [ key ] ) {
143
- const nm = `${ name } _delta` ;
144
- metrics += promHeader ( nm , 'gauge' , `${ description } benchmark delta` ) ;
145
- metrics += promValue ( nm , data [ key ] . delta , labels ) ;
146
- }
147
- if ( 'deltaPerRound' in data [ key ] ) {
148
- const nm = `${ name } _delta_per_round` ;
149
- metrics += promHeader (
150
- nm ,
151
- 'gauge' ,
152
- `${ description } benchmark delta per round` ,
153
- ) ;
154
- metrics += promValue ( nm , data [ key ] . deltaPerRound , labels ) ;
152
+ const statLabels = [ ...labels , [ 'stat' , name ] ] ;
153
+ for ( const prop of Object . keys ( propMetrics ) ) {
154
+ if ( prop in data [ key ] ) {
155
+ propMetrics [ prop ] += promValue (
156
+ metricName [ prop ] ,
157
+ data [ key ] [ prop ] ,
158
+ statLabels ,
159
+ ) ;
160
+ }
155
161
}
156
162
}
157
163
158
164
for ( const key of todo . keys ( ) ) {
159
165
console . warn ( `Unrecognized benchmark data property ${ key } ` ) ;
160
166
}
161
- return metrics ;
167
+ return Object . values ( propMetrics ) . join ( '' ) ;
162
168
}
163
169
164
170
function generateMetricsFromBenchStats ( benchStats , labels = [ ] ) {
0 commit comments