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 14cd2a1 commit 52c20e6
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 21 deletions.
21 changes: 13 additions & 8 deletions vjtop/src/main/java/com/vip/vjtools/vjtop/InteractiveTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class InteractiveTask implements Runnable {
private VJTop app;
private Console console;
private PrintStream tty;
private String inputWhenWaitForEnter;

public InteractiveTask(VJTop app) {
this.app = app;
Expand All @@ -34,9 +35,15 @@ public void run() {

while (true) {
try {
String command = readLine("");
if (command == null) {
break;
String command;
if (inputWhenWaitForEnter != null && inputWhenWaitForEnter.length() > 0) {
command = inputWhenWaitForEnter;
inputWhenWaitForEnter = null;
} else {
command = readLine("");
if (command == null) {
break;
}
}

handleCommand(command.toLowerCase());
Expand Down Expand Up @@ -129,7 +136,6 @@ private void printBlockedThreadsStack() throws IOException {
}
}


private void changeDisplayMode() {
app.preventFlush();

Expand Down Expand Up @@ -230,25 +236,24 @@ private void printHelp() throws Exception {
tty.println(" t : print stack trace of top " + app.view.threadLimit + " threads");
tty.println(" b : print stack trace of blocked threads");
tty.println(" a : list id and name of all threads");
tty.println(" -------------------------------------");
tty.println(" ---------------");
tty.println(" m : change threads display mode and ordering");
tty.println(" i [num]: change flush interval seconds");
tty.println(" l [num]: change number of display threads");
tty.println(" f [name]: set thread name filter");
tty.println(" -------------------------------------");
tty.println(" ---------------");
tty.println(" q : quit");
tty.println(" h : print help");
waitForEnter();
app.continueFlush();
}

private void waitForEnter() {
readLine(" Please hit <ENTER> to continue...");
inputWhenWaitForEnter = readLine(" Please hit <ENTER> to continue...");
}

private String readLine(String hints) {
String result = console.readLine(hints);

if (result != null) {
return result.trim();
}
Expand Down
29 changes: 16 additions & 13 deletions vjtop/src/main/java/com/vip/vjtools/vjtop/VMDetailView.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.vip.vjtools.vjtop;

import java.io.IOException;
import java.lang.management.LockInfo;
import java.lang.management.ManagementFactory;
import java.lang.management.ThreadInfo;
import java.util.Date;
Expand Down Expand Up @@ -501,27 +502,29 @@ public StackTraceElement[] printSingleThread(ThreadInfo info) {
if (vmInfo.threadContentionMonitoringSupported) {
sb.append(" (blocked:").append(info.getBlockedCount()).append("/").append(info.getBlockedTime())
.append("ms, wait:").append(info.getWaitedCount()).append("/").append(info.getWaitedTime())
.append("ms)");
.append("ms");
} else {
sb.append(" (blocked:").append(info.getBlockedCount()).append(",wait:").append(info.getWaitedCount())
.append(")");
sb.append(" (blocked:").append(info.getBlockedCount()).append(" times, wait:").append(info.getWaitedCount())
.append(" times");
}

if (info.getLockName() != null) {
sb.append(" on " + info.getLockName());
}
if (info.getLockOwnerName() != null) {
sb.append(" owned by " + info.getLockOwnerId() + ":\"" + info.getLockOwnerName() + "\"");
}
if (info.isSuspended()) {
sb.append(" (suspended)");
sb.append(" ,suspended");
}
if (info.isInNative()) {
sb.append(" (in native)");
sb.append(" ,in native");
}
sb.append('\n');
sb.append("\n java.lang.Thread.State: " + info.getThreadState().toString()).append("\n");
sb.append(")\n");

sb.append(" java.lang.Thread.State: " + info.getThreadState().toString());
LockInfo lockInfo = info.getLockInfo();
if (lockInfo != null) {
sb.append("(on " + lockInfo + ")");
}
if (info.getLockOwnerName() != null) {
sb.append(" owned by " + info.getLockOwnerId() + ":\"" + info.getLockOwnerName() + "\"");
}
sb.append("\n");
for (StackTraceElement traceElement : trace) {
sb.append("\tat ").append(traceElement).append("\n");
}
Expand Down

0 comments on commit 52c20e6

Please sign in to comment.