@@ -121,64 +121,9 @@ type TransformResult struct {
121
121
}
122
122
123
123
func Transform (res * nighthawk_client.ExecutionResponse , typ string ) ([]byte , error ) {
124
-
125
- //dur, err := time.ParseDuration(fmt.Sprintf("%ds%dµs", res.Output.Timestamp.Seconds, res.Output.Timestamp.Nanos))
126
- //if err != nil {
127
- // return nil, err
128
- //}
129
-
130
- results := make ([]Result , 0 )
131
-
132
- for _ , r := range res .Output .Results {
133
- statistics := make ([]Statistic , 0 )
134
- counters := make ([]Counter , 0 )
135
- for _ , c := range r .Counters {
136
- counters = append (counters , Counter {
137
- Name : c .Name ,
138
- Value : strconv .Itoa (int (c .Value )),
139
- })
140
- }
141
-
142
- for _ , s := range r .Statistics {
143
- percentiles := make ([]Percentile , 0 )
144
- for _ , p := range s .Percentiles {
145
- percentiles = append (percentiles , Percentile {
146
- Percentile : int (p .Percentile ),
147
- Count : strconv .Itoa (int (p .Count )),
148
- Duration : formatToNs (p .GetDuration ()),
149
- })
150
- }
151
-
152
- sts := Statistic {
153
- Count : strconv .Itoa (int (s .Count )),
154
- ID : s .Id ,
155
- Percentiles : percentiles ,
156
- Mean : formatToNs (s .GetMean ()),
157
- Pstdev : formatToNs (s .GetPstdev ()),
158
- Min : formatToNs (s .GetMin ()),
159
- Max : formatToNs (s .GetMax ()),
160
- }
161
- if sts .Mean == "" {
162
- sts .RawMean = int (s .GetRawMean ())
163
- }
164
- if sts .Pstdev == "" {
165
- sts .RawPstdev = int (s .GetRawPstdev ())
166
- }
167
- if sts .Min == "" {
168
- sts .RawMin = strconv .Itoa (int (s .GetRawMin ()))
169
- }
170
- if sts .Max == "" {
171
- sts .RawMax = strconv .Itoa (int (s .GetRawMax ()))
172
- }
173
- statistics = append (statistics , sts )
174
- }
175
- results = append (results , Result {
176
- Name : r .Name ,
177
- ExecutionStart : r .ExecutionStart .AsTime (),
178
- ExecutionDuration : formatToNs (r .ExecutionDuration ),
179
- Statistics : statistics ,
180
- Counters : counters ,
181
- })
124
+ results , err := constructResults (res )
125
+ if err != nil {
126
+ return nil , err
182
127
}
183
128
184
129
expStrategy := res .Output .Options .ExperimentalH1ConnectionReuseStrategy .String ()
@@ -241,20 +186,118 @@ func Transform(res *nighthawk_client.ExecutionResponse, typ string) ([]byte, err
241
186
if err != nil {
242
187
return nil , err
243
188
}
244
- fmt .Println ("input: " , input )
245
189
246
- command := "/private/var/tmp/_bazel_abishekk/eaf1167d72f4772496616c435b301da8/execroot/nighthawk/bazel-out/darwin-opt/bin /nighthawk_output_transform"
190
+ command := ". /nighthawk_output_transform"
247
191
cmd := exec .Command (command , "--output-format" , "fortio" )
248
192
cmd .Stdin = strings .NewReader (input )
249
193
out , err := cmd .Output ()
250
194
if err != nil {
251
195
return nil , err
252
196
}
253
- fmt .Println ("output: " , string (out ))
254
197
255
198
// Hack due to bug in nighthawk
199
+ outputFinal , err := hackFormat (out )
200
+ if err != nil {
201
+ return nil , err
202
+ }
203
+
204
+ return outputFinal , nil
205
+ }
206
+
207
+ func constructResults (res * nighthawk_client.ExecutionResponse ) ([]Result , error ) {
208
+ results := make ([]Result , 0 )
209
+ if res == nil {
210
+ return nil , ErrResponseNil
211
+ }
212
+
213
+ for _ , r := range res .Output .Results {
214
+ statistics := make ([]Statistic , 0 )
215
+ counters := make ([]Counter , 0 )
216
+ for _ , c := range r .Counters {
217
+ counters = append (counters , Counter {
218
+ Name : c .Name ,
219
+ Value : strconv .Itoa (int (c .Value )),
220
+ })
221
+ }
222
+
223
+ for _ , s := range r .Statistics {
224
+ percentiles := make ([]Percentile , 0 )
225
+ for _ , p := range s .Percentiles {
226
+ percentiles = append (percentiles , Percentile {
227
+ Percentile : int (p .Percentile ),
228
+ Count : strconv .Itoa (int (p .Count )),
229
+ Duration : formatToNs (p .GetDuration ()),
230
+ })
231
+ }
232
+
233
+ sts := Statistic {
234
+ Count : strconv .Itoa (int (s .Count )),
235
+ ID : s .Id ,
236
+ Percentiles : percentiles ,
237
+ Mean : formatToNs (s .GetMean ()),
238
+ Pstdev : formatToNs (s .GetPstdev ()),
239
+ Min : formatToNs (s .GetMin ()),
240
+ Max : formatToNs (s .GetMax ()),
241
+ }
242
+ if sts .Mean == "" {
243
+ sts .RawMean = int (s .GetRawMean ())
244
+ }
245
+ if sts .Pstdev == "" {
246
+ sts .RawPstdev = int (s .GetRawPstdev ())
247
+ }
248
+ if sts .Min == "" {
249
+ sts .RawMin = strconv .Itoa (int (s .GetRawMin ()))
250
+ }
251
+ if sts .Max == "" {
252
+ sts .RawMax = strconv .Itoa (int (s .GetRawMax ()))
253
+ }
254
+ statistics = append (statistics , sts )
255
+ }
256
+ results = append (results , Result {
257
+ Name : r .Name ,
258
+ ExecutionStart : r .ExecutionStart .AsTime (),
259
+ ExecutionDuration : formatToNs (r .ExecutionDuration ),
260
+ Statistics : statistics ,
261
+ Counters : counters ,
262
+ })
263
+ }
264
+ return results , nil
265
+ }
266
+
267
+ func formatToNs (s * duration.Duration ) string {
268
+ ss := s .AsDuration ().String ()
269
+ if strings .Contains (ss , "ms" ) {
270
+ sep := strings .Split (ss , "m" )
271
+ f , _ := strconv .ParseFloat (sep [0 ], 64 )
272
+ f /= 1000
273
+ st := fmt .Sprintf ("%f" , f )
274
+ sep [0 ] = st
275
+ ss = strings .Join (sep , "" )
276
+ } else if strings .Contains (ss , "µs" ) {
277
+ sep := strings .Split (ss , "µ" )
278
+ f , _ := strconv .ParseFloat (sep [0 ], 64 )
279
+ f /= 1000000
280
+ st := fmt .Sprintf ("%f" , f )
281
+ sep [0 ] = st
282
+ ss = strings .Join (sep , "" )
283
+ } else if strings .Contains (ss , "ns" ) {
284
+ sep := strings .Split (ss , "n" )
285
+ f , _ := strconv .ParseFloat (sep [0 ], 64 )
286
+ f /= 10000000
287
+ st := fmt .Sprintf ("%f" , f )
288
+ sep [0 ] = st
289
+ ss = strings .Join (sep , "" )
290
+ }
291
+ return ss
292
+ }
293
+
294
+ func hackFormat (out []byte ) ([]byte , error ) {
256
295
m := map [string ]interface {}{}
257
- err = json .Unmarshal (out , & m )
296
+ err := json .Unmarshal (out , & m )
297
+ if err != nil {
298
+ return nil , err
299
+ }
300
+
258
301
m ["RequestedQPS" ] = fmt .Sprint (m ["RequestedQPS" ].(float64 ))
259
302
260
303
if m ["DurationHistogram" ] != nil {
@@ -298,35 +341,5 @@ func Transform(res *nighthawk_client.ExecutionResponse, typ string) ([]byte, err
298
341
}
299
342
m ["Sizes" ].(map [string ]interface {})["Count" ] = h
300
343
}
301
-
302
- outTemp , _ := json .Marshal (m )
303
-
304
- return outTemp , nil
305
- }
306
-
307
- func formatToNs (s * duration.Duration ) string {
308
- ss := s .AsDuration ().String ()
309
- if strings .Contains (ss , "ms" ) {
310
- sep := strings .Split (ss , "m" )
311
- f , _ := strconv .ParseFloat (sep [0 ], 64 )
312
- f = f / 1000
313
- st := fmt .Sprintf ("%f" , f )
314
- sep [0 ] = st
315
- ss = strings .Join (sep , "" )
316
- } else if strings .Contains (ss , "µs" ) {
317
- sep := strings .Split (ss , "µ" )
318
- f , _ := strconv .ParseFloat (sep [0 ], 64 )
319
- f = f / 1000000
320
- st := fmt .Sprintf ("%f" , f )
321
- sep [0 ] = st
322
- ss = strings .Join (sep , "" )
323
- } else if strings .Contains (ss , "ns" ) {
324
- sep := strings .Split (ss , "n" )
325
- f , _ := strconv .ParseFloat (sep [0 ], 64 )
326
- f = f / 10000000
327
- st := fmt .Sprintf ("%f" , f )
328
- sep [0 ] = st
329
- ss = strings .Join (sep , "" )
330
- }
331
- return ss
344
+ return json .Marshal (m )
332
345
}
0 commit comments