Skip to content

Commit

Permalink
vjtop 打印线程时输出更多信息 #127
Browse files Browse the repository at this point in the history
  • Loading branch information
calvin1978 committed Sep 21, 2018
1 parent e4de802 commit 34f3ea0
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 11 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
.project
.settings/


# Intellij project files
*.iml
.idea/
Expand All @@ -16,4 +15,4 @@ vip-java-standard.md
release.sh
vjmap/vjmap/
vjtop/vjtop/
release.properties
vjmxcli/vjmxcli
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ public TopCpuResult topCpuThreads(ThreadInfoMode mode, int threadLimit) throws I
try {
long tids[] = vmInfo.getAllThreadIds();


int mapSize = tids.length * 2;
result.threadCpuTotalTimes = new LongObjectHashMap<>(mapSize);
result.threadCpuDeltaTimes = new LongObjectHashMap<>(mapSize);
Expand Down
24 changes: 20 additions & 4 deletions vjtop/src/main/java/com/vip/vjtools/vjtop/VMDetailView.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

@SuppressWarnings("restriction")
public class VMDetailView {

private static final int DEFAULT_WIDTH = 100;
private static final int MIN_WIDTH = 80;

Expand Down Expand Up @@ -51,6 +50,10 @@ public VMDetailView(VMInfo vmInfo, OutputFormat format, ContentMode contentMode,

this.interval = interval;
setWidth(width);

if (contentMode == ContentMode.all || contentMode == ContentMode.thread) {
vmInfo.initThreadInfoAbility();
}
}

public void printView() throws Exception {
Expand Down Expand Up @@ -491,11 +494,25 @@ public void printTopStack() throws IOException {

public StackTraceElement[] printSingleThread(ThreadInfo info) {
StackTraceElement[] trace = info.getStackTrace();
System.out.println(" " + info.getThreadId() + ": \"" + info.getThreadName() + "\"" + System.lineSeparator()
+ " java.lang.Thread.State: " + info.getThreadState().toString());
String blockedMsg;
if (vmInfo.threadContentionMonitoringSupported) {
blockedMsg = " (blocked:" + info.getBlockedCount() + "/" + info.getBlockedTime() + "ms, wait:"
+ info.getWaitedCount() + "/" + info.getWaitedTime() + "ms)";
} else {
blockedMsg = " (blocked:" + info.getBlockedCount() + ",wait:" + info.getWaitedCount() + ")";
}

System.out.println(" " + info.getThreadId() + ": \"" + info.getThreadName() + "\"" + blockedMsg
+ System.lineSeparator() + " java.lang.Thread.State: " + info.getThreadState().toString());

for (StackTraceElement traceElement : trace) {
System.out.println("\tat " + traceElement);
}

if (info.getLockOwnerId() != -1) {
System.out.println(" blocked by thread:" + info.getLockOwnerId() + ":" + info.getLockOwnerName());
}

return trace;
}

Expand Down Expand Up @@ -542,7 +559,6 @@ public void printBlockedThreads() throws IOException {
printSingleThread(info);
counter++;
}

}

System.out.println(" Total " + counter + " blocked threads");
Expand Down
10 changes: 6 additions & 4 deletions vjtop/src/main/java/com/vip/vjtools/vjtop/VMInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public class VMInfo {
public boolean processDataSupport = true;
public boolean threadCpuTimeSupported;
public boolean threadMemoryAllocatedSupported;
public boolean threadContentionMonitoringSupported;

public WarningRule warningRule = new WarningRule();

Expand Down Expand Up @@ -187,15 +188,17 @@ private void init() throws IOException {
.parseLong(jmxClient.getHotSpotDiagnosticMXBean().getVMOption("MaxDirectMemorySize").getValue());
maxDirectMemorySize = maxDirectMemorySize == 0 ? -1 : maxDirectMemorySize;

threadCpuTimeSupported = jmxClient.getThreadMXBean().isThreadCpuTimeSupported();
threadMemoryAllocatedSupported = jmxClient.getThreadMXBean().isThreadAllocatedMemorySupported();

processors = jmxClient.getOperatingSystemMXBean().getAvailableProcessors();
warningRule.updateProcessor(processors);

isLinux = System.getProperty("os.name").toLowerCase(Locale.US).contains("linux");
}

public void initThreadInfoAbility() throws IOException {
threadCpuTimeSupported = jmxClient.getThreadMXBean().isThreadCpuTimeSupported();
threadMemoryAllocatedSupported = jmxClient.getThreadMXBean().isThreadAllocatedMemorySupported();
threadContentionMonitoringSupported = jmxClient.getThreadMXBean().isThreadContentionMonitoringEnabled();
}

/**
* Updates all jvm metrics to the most recent remote values
Expand Down Expand Up @@ -439,7 +442,6 @@ public long[] getThreadAllocatedBytes(long[] tids) throws IOException {
return jmxClient.getThreadMXBean().getThreadAllocatedBytes(tids);
}


private void initPerfCounters(Map<String, Counter> perfCounters) {
threadLiveCounter = (LongCounter) perfCounters.get("java.threads.live");
threadDaemonCounter = (LongCounter) perfCounters.get("java.threads.daemon");
Expand Down

0 comments on commit 34f3ea0

Please sign in to comment.