提交 d5c70e16 编写于 作者: K kohsuke

thread dump is added to slave.


git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@3087 71c3de6d-444a-0410-be80-ed276b4c234a
上级 ece952dc
......@@ -434,17 +434,17 @@ public class Functions {
}
}
public Map<Thread,StackTraceElement[]> dumpAllThreads() {
public static Map<Thread,StackTraceElement[]> dumpAllThreads() {
return Thread.getAllStackTraces();
}
public ThreadInfo[] getThreadInfos() {
public static ThreadInfo[] getThreadInfos() {
ThreadMXBean mbean = ManagementFactory.getThreadMXBean();
return mbean.getThreadInfo(mbean.getAllThreadIds(),mbean.isObjectMonitorUsageSupported(),mbean.isSynchronizerUsageSupported());
}
// ThreadInfo.toString() truncates the stack trace by first 8, so needed my own version
public String dumpThreadInfo(ThreadInfo ti) {
public static String dumpThreadInfo(ThreadInfo ti) {
StringBuilder sb = new StringBuilder("\"" + ti.getThreadName() + "\"" +
" Id=" + ti.getThreadId() + " " +
ti.getThreadState());
......
package hudson.model;
import hudson.EnvVars;
import hudson.Functions;
import hudson.remoting.Callable;
import hudson.remoting.VirtualChannel;
import hudson.util.DaemonThreadFactory;
......@@ -15,8 +16,10 @@ import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.lang.management.ThreadInfo;
/**
* Represents a set of {@link Executor}s on the same computer.
......@@ -264,6 +267,28 @@ public abstract class Computer implements ModelObject {
private static final long serialVersionUID = 1L;
}
/**
* Gets the thread dump of the slave JVM.
* @return
* key is the thread name, and the value is the pre-formatted dump.
*/
public Map<String,String> getThreadDump() throws IOException, InterruptedException {
VirtualChannel channel = getChannel();
if(channel==null)
return Collections.singletonMap("N/A","N/A");
return channel.call(new GetThreadDump());
}
private static final class GetThreadDump implements Callable<Map<String,String>,RuntimeException> {
public Map<String,String> call() {
Map<String,String> r = new LinkedHashMap<String,String>();
for (ThreadInfo ti : Functions.getThreadInfos())
r.put(ti.getThreadName(),Functions.dumpThreadInfo(ti));
return r;
}
private static final long serialVersionUID = 1L;
}
public static final ExecutorService threadPoolForRemoting = Executors.newCachedThreadPool(new DaemonThreadFactory());
......
......@@ -13,6 +13,11 @@
<t:propertyTable items="${it.systemProperties}" />
<h1>Environment Variables</h1>
<t:propertyTable items="${it.envVars}" />
<h1>Thread Dump</h1>
<j:forEach var="t" items="${it.getThreadDump().entrySet()}">
<h2>${t.key}</h2>
<pre>${t.value}</pre>
</j:forEach>
</l:isAdmin>
</l:main-panel>
</l:layout>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册