@@ -108,6 +108,11 @@ public String describe() {
108108 */
109109 private long rowsEmitted ;
110110
111+ /**
112+ * Total nanos for emitting the output
113+ */
114+ protected long emitNanos ;
115+
111116 @ SuppressWarnings ("this-escape" )
112117 public HashAggregationOperator (
113118 List <GroupingAggregator .Factory > aggregators ,
@@ -217,6 +222,7 @@ public void finish() {
217222 finished = true ;
218223 Block [] blocks = null ;
219224 IntVector selected = null ;
225+ long startInNanos = System .nanoTime ();
220226 boolean success = false ;
221227 try {
222228 selected = blockHash .nonEmpty ();
@@ -240,6 +246,7 @@ public void finish() {
240246 if (success == false && blocks != null ) {
241247 Releasables .closeExpectNoException (blocks );
242248 }
249+ emitNanos += System .nanoTime () - startInNanos ;
243250 }
244251 }
245252
@@ -258,7 +265,7 @@ public void close() {
258265
259266 @ Override
260267 public Operator .Status status () {
261- return new Status (hashNanos , aggregationNanos , pagesProcessed , rowsReceived , rowsEmitted );
268+ return new Status (hashNanos , aggregationNanos , pagesProcessed , rowsReceived , rowsEmitted , emitNanos );
262269 }
263270
264271 protected static void checkState (boolean condition , String msg ) {
@@ -309,20 +316,24 @@ public static class Status implements Operator.Status {
309316 */
310317 private final long rowsEmitted ;
311318
319+ private final long emitNanos ;
320+
312321 /**
313322 * Build.
314323 * @param hashNanos Nanoseconds this operator has spent hashing grouping keys.
315324 * @param aggregationNanos Nanoseconds this operator has spent running the aggregations.
316325 * @param pagesProcessed Count of pages this operator has processed.
317326 * @param rowsReceived Count of rows this operator has received.
318327 * @param rowsEmitted Count of rows this operator has emitted.
328+ * @param emitNanos Nanoseconds this operator has spent emitting the output.
319329 */
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 ) {
321331 this .hashNanos = hashNanos ;
322332 this .aggregationNanos = aggregationNanos ;
323333 this .pagesProcessed = pagesProcessed ;
324334 this .rowsReceived = rowsReceived ;
325335 this .rowsEmitted = rowsEmitted ;
336+ this .emitNanos = emitNanos ;
326337 }
327338
328339 protected Status (StreamInput in ) throws IOException {
@@ -337,6 +348,11 @@ protected Status(StreamInput in) throws IOException {
337348 rowsReceived = 0 ;
338349 rowsEmitted = 0 ;
339350 }
351+ if (in .getTransportVersion ().onOrAfter (TransportVersions .ESQL_HASH_OPERATOR_STATUS_OUTPUT_TIME_8_19 )) {
352+ emitNanos = in .readVLong ();
353+ } else {
354+ emitNanos = 0 ;
355+ }
340356 }
341357
342358 @ Override
@@ -349,6 +365,9 @@ public void writeTo(StreamOutput out) throws IOException {
349365 out .writeVLong (rowsReceived );
350366 out .writeVLong (rowsEmitted );
351367 }
368+ if (out .getTransportVersion ().onOrAfter (TransportVersions .ESQL_HASH_OPERATOR_STATUS_OUTPUT_TIME_8_19 )) {
369+ out .writeVLong (emitNanos );
370+ }
352371 }
353372
354373 @ Override
@@ -391,6 +410,13 @@ public long rowsEmitted() {
391410 return rowsEmitted ;
392411 }
393412
413+ /**
414+ * Nanoseconds this operator has spent emitting the output.
415+ */
416+ public long emitNanos () {
417+ return emitNanos ;
418+ }
419+
394420 @ Override
395421 public XContentBuilder toXContent (XContentBuilder builder , Params params ) throws IOException {
396422 builder .startObject ();
@@ -405,6 +431,10 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
405431 builder .field ("pages_processed" , pagesProcessed );
406432 builder .field ("rows_received" , rowsReceived );
407433 builder .field ("rows_emitted" , rowsEmitted );
434+ builder .field ("emit_nanos" , emitNanos );
435+ if (builder .humanReadable ()) {
436+ builder .field ("emit_time" , TimeValue .timeValueNanos (emitNanos ));
437+ }
408438 return builder .endObject ();
409439
410440 }
@@ -418,12 +448,13 @@ public boolean equals(Object o) {
418448 && aggregationNanos == status .aggregationNanos
419449 && pagesProcessed == status .pagesProcessed
420450 && rowsReceived == status .rowsReceived
421- && rowsEmitted == status .rowsEmitted ;
451+ && rowsEmitted == status .rowsEmitted
452+ && emitNanos == status .emitNanos ;
422453 }
423454
424455 @ Override
425456 public int hashCode () {
426- return Objects .hash (hashNanos , aggregationNanos , pagesProcessed , rowsReceived , rowsEmitted );
457+ return Objects .hash (hashNanos , aggregationNanos , pagesProcessed , rowsReceived , rowsEmitted , emitNanos );
427458 }
428459
429460 @ Override
0 commit comments