Skip to content

Commit

Permalink
Enables thread contention monitoring. Fixes calculation of average th…
Browse files Browse the repository at this point in the history
…read blocked time and average thread waited time

Signed-off-by: Surya Sashank Nistala <snistala@amazon.com>
  • Loading branch information
eirsep committed Jan 24, 2022
1 parent 8b79f18 commit bbc6813
Showing 1 changed file with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ public class ThreadList {

private static Lock vmAttachLock = new ReentrantLock();

static {
if (threadBean.isThreadContentionMonitoringSupported()) {
threadBean.setThreadContentionMonitoringEnabled(true);
}
}

public static class ThreadState {
public long javaTid;
public long nativeTid;
Expand Down Expand Up @@ -284,6 +290,9 @@ private static void parseThreadInfo(final ThreadInfo info) {
1.0e-3
* (t.blockedTime - oldt.blockedTime)
/ (t.blockedCount - oldt.blockedCount);
} else if (t.blockedCount == oldt.blockedCount && t.blockedTime > oldt.blockedTime) {
t.avgBlockedTime =
1.0e-3 * (t.blockedTime - oldt.blockedTime + oldt.avgBlockedTime);
} else {
CircularLongArray arr = ThreadHistory.blockedTidHistoryMap.get(t.nativeTid);
// NOTE: this is an upper bound
Expand All @@ -296,6 +305,8 @@ private static void parseThreadInfo(final ThreadInfo info) {
1.0e-3
* (t.waitedTime - oldt.waitedTime)
/ (t.waitedCount - oldt.waitedCount);
} else if (t.waitedCount == oldt.waitedCount && t.waitedTime > oldt.waitedTime) {
t.avgWaitedTime = 1.0e-3 * (t.waitedTime - oldt.waitedTime + oldt.avgWaitedTime);
} else {
CircularLongArray arr = ThreadHistory.waitedTidHistoryMap.get(t.nativeTid);
// NOTE: this is an upper bound
Expand Down

0 comments on commit bbc6813

Please sign in to comment.