This is an automated email from the ASF dual-hosted git repository.

siddteotia pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pinot.git


The following commit(s) were added to refs/heads/master by this push:
     new 667b55d  Simplify the usage of ThreadTimer (#7800)
667b55d is described below

commit 667b55d4429e7a95db077b3d038448af4dc1305e
Author: Liang Mingqiang <[email protected]>
AuthorDate: Fri Nov 19 16:16:46 2021 -0800

    Simplify the usage of ThreadTimer (#7800)
---
 .../core/common/datatable/DataTableImplV3.java     |  3 +--
 .../core/operator/InstanceResponseOperator.java    |  3 +--
 .../core/operator/combine/BaseCombineOperator.java |  3 +--
 .../core/query/request/context/ThreadTimer.java    | 23 +++-------------------
 4 files changed, 6 insertions(+), 26 deletions(-)

diff --git 
a/pinot-core/src/main/java/org/apache/pinot/core/common/datatable/DataTableImplV3.java
 
b/pinot-core/src/main/java/org/apache/pinot/core/common/datatable/DataTableImplV3.java
index 930c1dd..1b1de8e 100644
--- 
a/pinot-core/src/main/java/org/apache/pinot/core/common/datatable/DataTableImplV3.java
+++ 
b/pinot-core/src/main/java/org/apache/pinot/core/common/datatable/DataTableImplV3.java
@@ -188,7 +188,6 @@ public class DataTableImplV3 extends BaseDataTable {
   public byte[] toBytes()
       throws IOException {
     ThreadTimer threadTimer = new ThreadTimer();
-    threadTimer.start();
 
     ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
     DataOutputStream dataOutputStream = new 
DataOutputStream(byteArrayOutputStream);
@@ -196,7 +195,7 @@ public class DataTableImplV3 extends BaseDataTable {
 
     // Add table serialization time metadata if thread timer is enabled.
     if (ThreadTimer.isThreadCpuTimeMeasurementEnabled()) {
-      long responseSerializationCpuTimeNs = 
threadTimer.stopAndGetThreadTimeNs();
+      long responseSerializationCpuTimeNs = threadTimer.getThreadTimeNs();
       getMetadata().put(MetadataKey.RESPONSE_SER_CPU_TIME_NS.getName(), 
String.valueOf(responseSerializationCpuTimeNs));
     }
 
diff --git 
a/pinot-core/src/main/java/org/apache/pinot/core/operator/InstanceResponseOperator.java
 
b/pinot-core/src/main/java/org/apache/pinot/core/operator/InstanceResponseOperator.java
index a6b8630..61dbfdc 100644
--- 
a/pinot-core/src/main/java/org/apache/pinot/core/operator/InstanceResponseOperator.java
+++ 
b/pinot-core/src/main/java/org/apache/pinot/core/operator/InstanceResponseOperator.java
@@ -72,13 +72,12 @@ public class InstanceResponseOperator extends 
BaseOperator<InstanceResponseBlock
   protected InstanceResponseBlock getNextBlock() {
     if (ThreadTimer.isThreadCpuTimeMeasurementEnabled()) {
       ThreadTimer mainThreadTimer = new ThreadTimer();
-      mainThreadTimer.start();
 
       long startWallClockTimeNs = System.nanoTime();
       IntermediateResultsBlock intermediateResultsBlock = getCombinedResults();
       InstanceResponseBlock instanceResponseBlock = new 
InstanceResponseBlock(intermediateResultsBlock);
       long totalWallClockTimeNs = System.nanoTime() - startWallClockTimeNs;
-      long mainThreadCpuTimeNs = mainThreadTimer.stopAndGetThreadTimeNs();
+      long mainThreadCpuTimeNs = mainThreadTimer.getThreadTimeNs();
       /*
        * If/when the threadCpuTime based instrumentation is done for other 
parts of execution (planning, pruning etc),
        * we will have to change the wallClockTime computation accordingly. 
Right now everything under
diff --git 
a/pinot-core/src/main/java/org/apache/pinot/core/operator/combine/BaseCombineOperator.java
 
b/pinot-core/src/main/java/org/apache/pinot/core/operator/combine/BaseCombineOperator.java
index c27138a..d7398d7 100644
--- 
a/pinot-core/src/main/java/org/apache/pinot/core/operator/combine/BaseCombineOperator.java
+++ 
b/pinot-core/src/main/java/org/apache/pinot/core/operator/combine/BaseCombineOperator.java
@@ -88,7 +88,6 @@ public abstract class BaseCombineOperator extends 
BaseOperator<IntermediateResul
         @Override
         public void runJob() {
           ThreadTimer executionThreadTimer = new ThreadTimer();
-          executionThreadTimer.start();
 
           // Register the task to the phaser
           // NOTE: If the phaser is terminated (returning negative value) when 
trying to register the task, that means
@@ -110,7 +109,7 @@ public abstract class BaseCombineOperator extends 
BaseOperator<IntermediateResul
             phaser.arriveAndDeregister();
           }
 
-          
_totalWorkerThreadCpuTimeNs.getAndAdd(executionThreadTimer.stopAndGetThreadTimeNs());
+          
_totalWorkerThreadCpuTimeNs.getAndAdd(executionThreadTimer.getThreadTimeNs());
         }
       });
     }
diff --git 
a/pinot-core/src/main/java/org/apache/pinot/core/query/request/context/ThreadTimer.java
 
b/pinot-core/src/main/java/org/apache/pinot/core/query/request/context/ThreadTimer.java
index 7816587..42d9557 100644
--- 
a/pinot-core/src/main/java/org/apache/pinot/core/query/request/context/ThreadTimer.java
+++ 
b/pinot-core/src/main/java/org/apache/pinot/core/query/request/context/ThreadTimer.java
@@ -32,10 +32,10 @@ public class ThreadTimer {
   private static final boolean IS_CURRENT_THREAD_CPU_TIME_SUPPORTED = 
MX_BEAN.isCurrentThreadCpuTimeSupported();
   private static final Logger LOGGER = 
LoggerFactory.getLogger(ThreadTimer.class);
   private static boolean _isThreadCpuTimeMeasurementEnabled = false;
-  private long _startTimeNs = -1;
-  private long _endTimeNs = -1;
+  private final long _startTimeNs;
 
   public ThreadTimer() {
+    _startTimeNs = _isThreadCpuTimeMeasurementEnabled ? 
MX_BEAN.getCurrentThreadCpuTime() : -1;
   }
 
   public static void setThreadCpuTimeMeasurementEnabled(boolean enable) {
@@ -46,25 +46,8 @@ public class ThreadTimer {
     return _isThreadCpuTimeMeasurementEnabled;
   }
 
-  public void start() {
-    if (_isThreadCpuTimeMeasurementEnabled) {
-      _startTimeNs = MX_BEAN.getCurrentThreadCpuTime();
-    }
-  }
-
-  public void stop() {
-    if (_isThreadCpuTimeMeasurementEnabled) {
-      _endTimeNs = MX_BEAN.getCurrentThreadCpuTime();
-    }
-  }
-
   public long getThreadTimeNs() {
-    return _endTimeNs - _startTimeNs;
-  }
-
-  public long stopAndGetThreadTimeNs() {
-    stop();
-    return getThreadTimeNs();
+    return _isThreadCpuTimeMeasurementEnabled ? 
MX_BEAN.getCurrentThreadCpuTime() - _startTimeNs : 0;
   }
 
   static {

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to