@@ -110,6 +110,11 @@ public String describe() {
110110 */
111111 private long rowsEmitted ;
112112
113+ /**
114+ * Total nanos for emitting the output
115+ */
116+ protected long emitNanos ;
117+
113118 @ SuppressWarnings ("this-escape" )
114119 public HashAggregationOperator (
115120 List <GroupingAggregator .Factory > aggregators ,
@@ -223,6 +228,7 @@ public void finish() {
223228 finished = true ;
224229 Block [] blocks = null ;
225230 IntVector selected = null ;
231+ long startInNanos = System .nanoTime ();
226232 boolean success = false ;
227233 try {
228234 selected = blockHash .nonEmpty ();
@@ -247,6 +253,7 @@ public void finish() {
247253 if (success == false && blocks != null ) {
248254 Releasables .closeExpectNoException (blocks );
249255 }
256+ emitNanos += System .nanoTime () - startInNanos ;
250257 }
251258 }
252259
@@ -269,7 +276,7 @@ public void close() {
269276
270277 @ Override
271278 public Operator .Status status () {
272- return new Status (hashNanos , aggregationNanos , pagesProcessed , rowsReceived , rowsEmitted );
279+ return new Status (hashNanos , aggregationNanos , pagesProcessed , rowsReceived , rowsEmitted , emitNanos );
273280 }
274281
275282 protected static void checkState (boolean condition , String msg ) {
@@ -320,20 +327,24 @@ public static class Status implements Operator.Status {
320327 */
321328 private final long rowsEmitted ;
322329
330+ private final long emitNanos ;
331+
323332 /**
324333 * Build.
325334 * @param hashNanos Nanoseconds this operator has spent hashing grouping keys.
326335 * @param aggregationNanos Nanoseconds this operator has spent running the aggregations.
327336 * @param pagesProcessed Count of pages this operator has processed.
328337 * @param rowsReceived Count of rows this operator has received.
329338 * @param rowsEmitted Count of rows this operator has emitted.
339+ * @param emitNanos Nanoseconds this operator has spent emitting the output.
330340 */
331- public Status (long hashNanos , long aggregationNanos , int pagesProcessed , long rowsReceived , long rowsEmitted ) {
341+ public Status (long hashNanos , long aggregationNanos , int pagesProcessed , long rowsReceived , long rowsEmitted , long emitNanos ) {
332342 this .hashNanos = hashNanos ;
333343 this .aggregationNanos = aggregationNanos ;
334344 this .pagesProcessed = pagesProcessed ;
335345 this .rowsReceived = rowsReceived ;
336346 this .rowsEmitted = rowsEmitted ;
347+ this .emitNanos = emitNanos ;
337348 }
338349
339350 protected Status (StreamInput in ) throws IOException {
@@ -348,6 +359,11 @@ protected Status(StreamInput in) throws IOException {
348359 rowsReceived = 0 ;
349360 rowsEmitted = 0 ;
350361 }
362+ if (in .getTransportVersion ().onOrAfter (TransportVersions .ESQL_HASH_OPERATOR_STATUS_OUTPUT_TIME )) {
363+ emitNanos = in .readVLong ();
364+ } else {
365+ emitNanos = 0 ;
366+ }
351367 }
352368
353369 @ Override
@@ -360,6 +376,9 @@ public void writeTo(StreamOutput out) throws IOException {
360376 out .writeVLong (rowsReceived );
361377 out .writeVLong (rowsEmitted );
362378 }
379+ if (out .getTransportVersion ().onOrAfter (TransportVersions .ESQL_HASH_OPERATOR_STATUS_OUTPUT_TIME )) {
380+ out .writeVLong (emitNanos );
381+ }
363382 }
364383
365384 @ Override
@@ -402,6 +421,13 @@ public long rowsEmitted() {
402421 return rowsEmitted ;
403422 }
404423
424+ /**
425+ * Nanoseconds this operator has spent emitting the output.
426+ */
427+ public long emitNanos () {
428+ return emitNanos ;
429+ }
430+
405431 @ Override
406432 public XContentBuilder toXContent (XContentBuilder builder , Params params ) throws IOException {
407433 builder .startObject ();
@@ -416,6 +442,10 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
416442 builder .field ("pages_processed" , pagesProcessed );
417443 builder .field ("rows_received" , rowsReceived );
418444 builder .field ("rows_emitted" , rowsEmitted );
445+ builder .field ("emit_nanos" , emitNanos );
446+ if (builder .humanReadable ()) {
447+ builder .field ("emit_time" , TimeValue .timeValueNanos (emitNanos ));
448+ }
419449 return builder .endObject ();
420450
421451 }
@@ -429,12 +459,13 @@ public boolean equals(Object o) {
429459 && aggregationNanos == status .aggregationNanos
430460 && pagesProcessed == status .pagesProcessed
431461 && rowsReceived == status .rowsReceived
432- && rowsEmitted == status .rowsEmitted ;
462+ && rowsEmitted == status .rowsEmitted
463+ && emitNanos == status .emitNanos ;
433464 }
434465
435466 @ Override
436467 public int hashCode () {
437- return Objects .hash (hashNanos , aggregationNanos , pagesProcessed , rowsReceived , rowsEmitted );
468+ return Objects .hash (hashNanos , aggregationNanos , pagesProcessed , rowsReceived , rowsEmitted , emitNanos );
438469 }
439470
440471 @ Override
0 commit comments