Skip to content

Commit

Permalink
test changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Gagan Juneja committed May 7, 2024
1 parent 6774aff commit 11c192e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ protected void innerOnResponse(Task task) {
Tags.create()
.addTag(
"shardId",
searchContext.getTask().getId())
searchContext.shardTarget().getShardId().getId())
.addTag(
"indexName",
searchContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

package org.opensearch.performanceanalyzer.transport;

import com.sun.management.ThreadMXBean;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
Expand Down Expand Up @@ -46,6 +47,7 @@ public class PerformanceAnalyzerTransportChannel implements TransportChannel, Me
private String threadID;
private Counter throughputCounter;
private Long startCpuTimeNanos;
private long jvmThreadID;

void set(
TransportChannel original,
Expand All @@ -64,6 +66,8 @@ void set(
this.startValue = getIOUsage(threadID);
this.throughputCounter = throughputCounter;
this.startCpuTimeNanos = ManagementFactory.getThreadMXBean().getCurrentThreadCpuTime();
jvmThreadID = Thread.currentThread().getId();
LOG.info("Updating the counter Start thread {} {}", jvmThreadID, Thread.currentThread().getName());
}

@Override
Expand All @@ -78,10 +82,11 @@ public String getChannelType() {

@Override
public void sendResponse(TransportResponse response) throws IOException {
LOG.info("Updating the counter Finish thread {}", Thread.currentThread().getName());
if (throughputCounter != null) {
long updatedValue = ManagementFactory.getThreadMXBean().getCurrentThreadCpuTime()
- startCpuTimeNanos;
LOG.info("Updating the counter inside PATransportChannel {}", updatedValue);
long timeNow = ((ThreadMXBean)ManagementFactory.getThreadMXBean()).getThreadCpuTime(jvmThreadID);
long updatedValue = timeNow - startCpuTimeNanos;
LOG.info("Updating the counter inside PATransportChannel {} start time {}, now {}", updatedValue, startCpuTimeNanos, timeNow);
throughputCounter.add(
Math.max(updatedValue, 0),
Tags.create().addTag("indexName", indexName).addTag("shardId", shardId));
Expand Down

0 comments on commit 11c192e

Please sign in to comment.