mirror of
https://github.com/jenkinsci/jenkins.git
synced 2026-11-16 21:42:27 +00:00
thread dump now reports all the threads from all the slaves, not just
the master.
This commit is contained in:
1 parent
3676f0e51c
commit
f9f030db8f
5 files changed
+62
-6
No files matched your search
@@ -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>();
|
||||
|
||||
Reference in new issue
Block a user