diff --git a/processing/src/main/java/io/druid/query/CPUTimeMetricQueryRunner.java b/processing/src/main/java/io/druid/query/CPUTimeMetricQueryRunner.java index 1a5dbd191ad..909d89dce0e 100644 --- a/processing/src/main/java/io/druid/query/CPUTimeMetricQueryRunner.java +++ b/processing/src/main/java/io/druid/query/CPUTimeMetricQueryRunner.java @@ -85,11 +85,16 @@ public class CPUTimeMetricQueryRunner implements QueryRunner } @Override - public Yielder toYielder( - OutType initValue, YieldingAccumulator accumulator - ) + public Yielder toYielder(OutType initValue, YieldingAccumulator accumulator) { - final Yielder delegateYielder = baseSequence.toYielder(initValue, accumulator); + final long start = VMUtils.getCurrentThreadCpuTime(); + final Yielder delegateYielder; + try { + delegateYielder = baseSequence.toYielder(initValue, accumulator); + } + finally { + cpuTimeAccumulator.addAndGet(VMUtils.getCurrentThreadCpuTime() - start); + } return new Yielder() { @Override @@ -100,9 +105,7 @@ public class CPUTimeMetricQueryRunner implements QueryRunner return delegateYielder.get(); } finally { - cpuTimeAccumulator.addAndGet( - VMUtils.getCurrentThreadCpuTime() - start - ); + cpuTimeAccumulator.addAndGet(VMUtils.getCurrentThreadCpuTime() - start); } } @@ -114,9 +117,7 @@ public class CPUTimeMetricQueryRunner implements QueryRunner return delegateYielder.next(initValue); } finally { - cpuTimeAccumulator.addAndGet( - VMUtils.getCurrentThreadCpuTime() - start - ); + cpuTimeAccumulator.addAndGet(VMUtils.getCurrentThreadCpuTime() - start); } }