提交 05d4ee87 编写于 作者: K kohsuke

unified classicThreadDump and threadDump by auto-detecting the runtime version.


git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@3914 71c3de6d-444a-0410-be80-ed276b4c234a
上级 93b57b7c
......@@ -26,23 +26,23 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.lang.management.LockInfo;
import java.lang.management.ManagementFactory;
import java.lang.management.MonitorInfo;
import java.lang.management.ThreadInfo;
import java.lang.management.ThreadMXBean;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Calendar;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.SortedMap;
import java.util.TreeMap;
import java.util.Collection;
import java.util.Collections;
import java.util.logging.LogRecord;
import java.util.logging.SimpleFormatter;
import java.lang.management.ManagementFactory;
import java.lang.management.ThreadMXBean;
import java.lang.management.ThreadInfo;
import java.lang.management.MonitorInfo;
import java.lang.management.LockInfo;
/**
* Utility functions used in views.
......@@ -483,6 +483,18 @@ public class Functions {
return mbean.getThreadInfo(mbean.getAllThreadIds(),mbean.isObjectMonitorUsageSupported(),mbean.isSynchronizerUsageSupported());
}
/**
* Are we running on JRE6 or above?
*/
public static boolean isMustangOrAbove() {
try {
System.console();
return true;
} catch(LinkageError e) {
return false;
}
}
// ThreadInfo.toString() truncates the stack trace by first 8, so needed my own version
public static String dumpThreadInfo(ThreadInfo ti) {
StringBuilder sb = new StringBuilder("\"" + ti.getThreadName() + "\"" +
......
......@@ -1148,6 +1148,13 @@ public final class Hudson extends View implements ItemGroup<TopLevelItem>, Node
rsp.sendRedirect2(".");
}
/**
* Backward compatibility. Redirect to the thread dump.
*/
public void doClassicThreadDump( StaplerRequest req, StaplerResponse rsp ) throws IOException, ServletException {
rsp.sendRedirect2("threadDump");
}
public synchronized Item doCreateItem( StaplerRequest req, StaplerResponse rsp ) throws IOException, ServletException {
if(!Hudson.adminCheck(req,rsp))
return null;
......
<!--
Produces stack dump of all threads by using java.lang.Thread.
This only offers limited information but I feel more confidence in the
simple implementation, so left as-is.
-->
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
<l:layout secure="true">
<st:include page="sidepanel.jelly" />
<l:main-panel>
<h1>Thread Dump</h1>
<j:forEach var="e" items="${h.dumpAllThreads().entrySet()}">
<h2>${e.key} (${e.key.state})</h2>
<j:forEach var="f" items="${e.value}">
<div>${f}</div>
</j:forEach>
</j:forEach>
</l:main-panel>
</l:layout>
</j:jelly>
<!--
Produces stack dump of all threads by using JMX.
This uses new Tiger feature and offers more information
-->
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
<l:layout secure="true">
......@@ -9,10 +7,24 @@
<l:main-panel>
<h1>Thread Dump</h1>
<j:forEach var="t" items="${h.getThreadInfos()}">
<h2>${t.threadName}</h2>
<pre>${h.dumpThreadInfo(t)}</pre>
</j:forEach>
<j:choose>
<j:when test="${h.isMustangOrAbove()}">
<!-- use a new Mustang feature to get more detailed dump -->
<j:forEach var="t" items="${h.getThreadInfos()}">
<h2>${t.threadName}</h2>
<pre>${h.dumpThreadInfo(t)}</pre>
</j:forEach>
</j:when>
<j:otherwise>
<!-- fall back -->
<j:forEach var="e" items="${h.dumpAllThreads().entrySet()}">
<h2>${e.key} (${e.key.state})</h2>
<j:forEach var="f" items="${e.value}">
<div>${f}</div>
</j:forEach>
</j:forEach>
</j:otherwise>
</j:choose>
</l:main-panel>
</l:layout>
</j:jelly>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册