@@ -108,6 +108,11 @@ public String describe() {
108
108
*/
109
109
private long rowsEmitted ;
110
110
111
+ /**
112
+ * Total nanos for emitting the output
113
+ */
114
+ protected long emitNanos ;
115
+
111
116
@ SuppressWarnings ("this-escape" )
112
117
public HashAggregationOperator (
113
118
List <GroupingAggregator .Factory > aggregators ,
@@ -217,6 +222,7 @@ public void finish() {
217
222
finished = true ;
218
223
Block [] blocks = null ;
219
224
IntVector selected = null ;
225
+ long startInNanos = System .nanoTime ();
220
226
boolean success = false ;
221
227
try {
222
228
selected = blockHash .nonEmpty ();
@@ -240,6 +246,7 @@ public void finish() {
240
246
if (success == false && blocks != null ) {
241
247
Releasables .closeExpectNoException (blocks );
242
248
}
249
+ emitNanos += System .nanoTime () - startInNanos ;
243
250
}
244
251
}
245
252
@@ -258,7 +265,7 @@ public void close() {
258
265
259
266
@ Override
260
267
public Operator .Status status () {
261
- return new Status (hashNanos , aggregationNanos , pagesProcessed , rowsReceived , rowsEmitted );
268
+ return new Status (hashNanos , aggregationNanos , pagesProcessed , rowsReceived , rowsEmitted , emitNanos );
262
269
}
263
270
264
271
protected static void checkState (boolean condition , String msg ) {
@@ -309,20 +316,24 @@ public static class Status implements Operator.Status {
309
316
*/
310
317
private final long rowsEmitted ;
311
318
319
+ private final long emitNanos ;
320
+
312
321
/**
313
322
* Build.
314
323
* @param hashNanos Nanoseconds this operator has spent hashing grouping keys.
315
324
* @param aggregationNanos Nanoseconds this operator has spent running the aggregations.
316
325
* @param pagesProcessed Count of pages this operator has processed.
317
326
* @param rowsReceived Count of rows this operator has received.
318
327
* @param rowsEmitted Count of rows this operator has emitted.
328
+ * @param emitNanos Nanoseconds this operator has spent emitting the output.
319
329
*/
320
- public Status (long hashNanos , long aggregationNanos , int pagesProcessed , long rowsReceived , long rowsEmitted ) {
330
+ public Status (long hashNanos , long aggregationNanos , int pagesProcessed , long rowsReceived , long rowsEmitted , long emitNanos ) {
321
331
this .hashNanos = hashNanos ;
322
332
this .aggregationNanos = aggregationNanos ;
323
333
this .pagesProcessed = pagesProcessed ;
324
334
this .rowsReceived = rowsReceived ;
325
335
this .rowsEmitted = rowsEmitted ;
336
+ this .emitNanos = emitNanos ;
326
337
}
327
338
328
339
protected Status (StreamInput in ) throws IOException {
@@ -337,6 +348,11 @@ protected Status(StreamInput in) throws IOException {
337
348
rowsReceived = 0 ;
338
349
rowsEmitted = 0 ;
339
350
}
351
+ if (in .getTransportVersion ().onOrAfter (TransportVersions .ESQL_HASH_OPERATOR_STATUS_OUTPUT_TIME_8_19 )) {
352
+ emitNanos = in .readVLong ();
353
+ } else {
354
+ emitNanos = 0 ;
355
+ }
340
356
}
341
357
342
358
@ Override
@@ -349,6 +365,9 @@ public void writeTo(StreamOutput out) throws IOException {
349
365
out .writeVLong (rowsReceived );
350
366
out .writeVLong (rowsEmitted );
351
367
}
368
+ if (out .getTransportVersion ().onOrAfter (TransportVersions .ESQL_HASH_OPERATOR_STATUS_OUTPUT_TIME_8_19 )) {
369
+ out .writeVLong (emitNanos );
370
+ }
352
371
}
353
372
354
373
@ Override
@@ -391,6 +410,13 @@ public long rowsEmitted() {
391
410
return rowsEmitted ;
392
411
}
393
412
413
+ /**
414
+ * Nanoseconds this operator has spent emitting the output.
415
+ */
416
+ public long emitNanos () {
417
+ return emitNanos ;
418
+ }
419
+
394
420
@ Override
395
421
public XContentBuilder toXContent (XContentBuilder builder , Params params ) throws IOException {
396
422
builder .startObject ();
@@ -405,6 +431,10 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
405
431
builder .field ("pages_processed" , pagesProcessed );
406
432
builder .field ("rows_received" , rowsReceived );
407
433
builder .field ("rows_emitted" , rowsEmitted );
434
+ builder .field ("emit_nanos" , emitNanos );
435
+ if (builder .humanReadable ()) {
436
+ builder .field ("emit_time" , TimeValue .timeValueNanos (emitNanos ));
437
+ }
408
438
return builder .endObject ();
409
439
410
440
}
@@ -418,12 +448,13 @@ public boolean equals(Object o) {
418
448
&& aggregationNanos == status .aggregationNanos
419
449
&& pagesProcessed == status .pagesProcessed
420
450
&& rowsReceived == status .rowsReceived
421
- && rowsEmitted == status .rowsEmitted ;
451
+ && rowsEmitted == status .rowsEmitted
452
+ && emitNanos == status .emitNanos ;
422
453
}
423
454
424
455
@ Override
425
456
public int hashCode () {
426
- return Objects .hash (hashNanos , aggregationNanos , pagesProcessed , rowsReceived , rowsEmitted );
457
+ return Objects .hash (hashNanos , aggregationNanos , pagesProcessed , rowsReceived , rowsEmitted , emitNanos );
427
458
}
428
459
429
460
@ Override
0 commit comments