Skip to content

Commit

Permalink
test changes
Browse files Browse the repository at this point in the history
Signed-off-by: Gagan Juneja <[email protected]>
  • Loading branch information
Gagan Juneja committed Jul 18, 2024
1 parent 82c9e82 commit 1a3b223
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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();
}

Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit 1a3b223

Please sign in to comment.