提交 f9f030db 编写于 作者: K Kohsuke Kawaguchi

thread dump now reports all the threads from all the slaves, not just

the master.
上级 3676f0e5
......@@ -58,7 +58,8 @@ Upcoming changes</a>
<!-- Record your changes in the trunk here. -->
<div id="trunk" style="display:none"><!--=TRUNK-BEGIN=-->
<ul class=image>
<li class=>
<li class=rfe>
thread dump now reports all the threads from all the slaves, not just the master.
</ul>
</div><!--=TRUNK-END=-->
......
......@@ -189,6 +189,7 @@ import java.io.FileFilter;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.net.BindException;
import java.net.URL;
import java.nio.charset.Charset;
......@@ -2631,6 +2632,38 @@ public final class Hudson extends Node implements ItemGroup<TopLevelItem>, Stapl
rsp.sendRedirect2("threadDump");
}
/**
* Obtains the thread dump of all slaves (including the master.)
*
* <p>
* Since this is for diagnostics, it has a built-in precautionary measure against hang slaves.
*/
public Map<String,Map<String,String>> getAllThreadDumps() throws IOException, InterruptedException {
checkPermission(ADMINISTER);
// issue the requests all at once
Map<String,Future<Map<String,String>>> future = new HashMap<String, Future<Map<String, String>>>();
for (Computer c : getComputers()) {
future.put(c.getName(), RemotingDiagnostics.getThreadDumpAsync(c.getChannel()));
}
// if the result isn't available in 5 sec, ignore that.
// this is a precaution against hang nodes
long endTime = System.currentTimeMillis() + 5000;
Map<String,Map<String,String>> r = new HashMap<String, Map<String, String>>();
for (Entry<String, Future<Map<String, String>>> e : future.entrySet()) {
try {
r.put(e.getKey(), e.getValue().get(endTime-System.currentTimeMillis(), TimeUnit.MILLISECONDS));
} catch (Exception x) {
StringWriter sw = new StringWriter();
x.printStackTrace(new PrintWriter(sw,true));
r.put(e.getKey(), Collections.singletonMap("Failed to retrieve thread dump",sw.toString()));
}
}
return r;
}
public synchronized Item doCreateItem( StaplerRequest req, StaplerResponse rsp ) throws IOException, ServletException {
return itemGroupMixIn.createTopLevelItem(req, rsp);
}
......
......@@ -27,8 +27,10 @@ import groovy.lang.GroovyShell;
import hudson.FilePath;
import hudson.Functions;
import hudson.model.Hudson;
import hudson.remoting.AsyncFutureImpl;
import hudson.remoting.Callable;
import hudson.remoting.DelegatingCallable;
import hudson.remoting.Future;
import hudson.remoting.VirtualChannel;
import hudson.security.AccessControlled;
import org.kohsuke.stapler.StaplerRequest;
......@@ -78,6 +80,12 @@ public final class RemotingDiagnostics {
return channel.call(new GetThreadDump());
}
public static Future<Map<String,String>> getThreadDumpAsync(VirtualChannel channel) throws IOException, InterruptedException {
if(channel==null)
return new AsyncFutureImpl<Map<String, String>>(Collections.singletonMap("N/A","offline"));
return channel.callAsync(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>();
......
<!--
The MIT License
Copyright (c) 2004-2010, Sun Microsystems, Inc., Kohsuke Kawaguchi, Tom Huybrechts
Copyright (c) 2004-2010, Sun Microsystems, Inc., Kohsuke Kawaguchi, Tom Huybrechts, CloudBees, Inc.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
......@@ -31,9 +31,15 @@ THE SOFTWARE.
<l:main-panel>
<h1>${%Thread Dump}</h1>
<j:forEach var="t" items="${it.toComputer().getThreadDump().entrySet()}">
<h2>${t.key}</h2>
<pre>${t.value}</pre>
<j:forEach var="e" items="${it.getAllThreadDumps().entrySet()}" varStatus="loop">
<j:if test="${!loop.first}">
<hr style="margin-bottom:6em"/>
</j:if>
<h1>${e.key}</h1>
<j:forEach var="t" items="${e.value.entrySet()}">
<h2>${t.key}</h2>
<pre>${t.value}</pre>
</j:forEach>
</j:forEach>
</l:main-panel>
</l:layout>
......
/*
* The MIT License
*
* Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi
* Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi, CloudBees, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
......@@ -48,6 +48,14 @@ public class AsyncFutureImpl<V> implements Future<V> {
private Throwable problem;
private boolean cancelled;
public AsyncFutureImpl() {}
public AsyncFutureImpl(V value) {
set(value);
}
public AsyncFutureImpl(Throwable value) {
set(value);
}
public boolean cancel(boolean mayInterruptIfRunning) {
return false;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册