From b113a34355a6fdbf115b737299aced1815138cde Mon Sep 17 00:00:00 2001 From: Roman Leventov Date: Tue, 18 Oct 2016 17:06:42 +0300 Subject: [PATCH] In CPUTimeMetricQueryRunner, account CPU consumed in baseSequence.toYielder() (#3587) --- .../druid/query/CPUTimeMetricQueryRunner.java | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) 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); } }