From 1a3b2230431095bdaa3e0f5db3a33c574ae47068 Mon Sep 17 00:00:00 2001 From: Gagan Juneja Date: Thu, 18 Jul 2024 12:47:34 +0530 Subject: [PATCH] test changes Signed-off-by: Gagan Juneja --- .../RTFPerformanceAnalyzerTransportChannel.java | 9 +++++++-- .../org/opensearch/performanceanalyzer/util/Utils.java | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/opensearch/performanceanalyzer/transport/RTFPerformanceAnalyzerTransportChannel.java b/src/main/java/org/opensearch/performanceanalyzer/transport/RTFPerformanceAnalyzerTransportChannel.java index d1b9b04d..c6994eb4 100644 --- a/src/main/java/org/opensearch/performanceanalyzer/transport/RTFPerformanceAnalyzerTransportChannel.java +++ b/src/main/java/org/opensearch/performanceanalyzer/transport/RTFPerformanceAnalyzerTransportChannel.java @@ -42,6 +42,8 @@ public final class RTFPerformanceAnalyzerTransportChannel implements TransportCh private ShardId shardId; private boolean primary; + private long threadID; + void set( TransportChannel original, Histogram cpuUtilizationHistogram, @@ -55,7 +57,9 @@ void set( this.primary = bPrimary; this.operationStartTime = System.nanoTime(); - this.cpuStartTime = threadMXBean.getCurrentThreadCpuTime(); + threadID = Thread.currentThread().getId(); + this.cpuStartTime = threadMXBean.getThreadCpuTime(threadID); + LOG.info("111 - Thread Name {}", Thread.currentThread().getName()); this.scClkTck = OSGlobals.getScClkTck(); } @@ -88,8 +92,9 @@ private void emitMetrics(Exception exception) { } private double calculateCPUUtilization(long phaseStartTime, long phaseCPUStartTime) { + LOG.info("111 - Thread Name-1 {}", Thread.currentThread().getName()); long totalCpuTime = - Math.min(0, (threadMXBean.getCurrentThreadCpuTime() - phaseCPUStartTime)); + Math.max(0, (threadMXBean.getThreadCpuTime(threadID) - phaseCPUStartTime)); return Utils.calculateCPUUtilization( totalCpuTime, scClkTck, System.nanoTime() - phaseStartTime); } diff --git a/src/main/java/org/opensearch/performanceanalyzer/util/Utils.java b/src/main/java/org/opensearch/performanceanalyzer/util/Utils.java index 2f8e6a98..9597a377 100644 --- a/src/main/java/org/opensearch/performanceanalyzer/util/Utils.java +++ b/src/main/java/org/opensearch/performanceanalyzer/util/Utils.java @@ -116,6 +116,6 @@ public static double calculateCPUUtilization(long totalCpuTime, long scClkTck, l LOG.debug("totalCpuTime {}", totalCpuTime); LOG.debug("scClkTck {}", scClkTck); LOG.debug("totalTime {}", totalTime); - return (1.0e3 * totalCpuTime / Math.max(1, scClkTck)) / Math.max(1, totalTime); + return (1.0e3 * Math.max(0, totalCpuTime) / Math.max(1, scClkTck)) / Math.max(1, totalTime); } }