<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.io.*,
java.util.*,
java.net.*,
java.lang.management.*"
%>
<html>
<head>
<title>DeProfile</title>
<style type="text/css">
body{font-size:14px;font-family:Arial;}
.stack{font-size:12px; font-family:Arial; margin:10px}
</style>
</head>
<body>
<%
final long DEFAULT_MAX_TIME=1000;
final long DEFAULT_THEAD_ID=0;
/* Get parameter*/
Long overtime =Long.parseLong(request.getParameter("t")==null?"0":request.getParameter("t"));//.getAttribute("t");
Long theadid =Long.parseLong(request.getParameter("i")==null?"0":request.getParameter("i"));//(Long)request.getAttribute("i");
if(overtime==null || overtime<=0){
overtime =DEFAULT_MAX_TIME;
}
if(theadid==null || theadid<=0){
theadid =DEFAULT_THEAD_ID;
}
%>
<form action="" method="POST">
<table cellpadding="0">
<tr>
<td><input type="hidden" name="dir" value="<%=request.getAttribute("dir")%>">
<input type="file" name="myFile"></td>
<td><input type="Submit" class="button" name="Submit" value="上传"></td>
</tr>
</table>
</form>
<%
ThreadMXBean tm = ManagementFactory.getThreadMXBean();
tm.setThreadContentionMonitoringEnabled(true);
long [] tid = tm.getAllThreadIds();
ThreadInfo [] tia = tm.getThreadInfo(tid, Integer.MAX_VALUE);
for (int i = tia.length-1; i > 0; i--) {
long threadId = tia[i].getThreadId();
long cpuTime = tm.getThreadCpuTime(tia[i].getThreadId())/(1000*1000*1000);
out.println("<div>ThreadId:"+threadId+" CPU Time:"+cpuTime+"</div>");
if(cpuTime >= overtime || threadId ==theadid){
out.println("<div>"+"==================================================================="+"</div>");
out.println("<div class=stack>");
out.println("<div>Stack Info - Thread ID: "+threadId+"</div>");
StackTraceElement[] stackElements = tia[i].getStackTrace();
if (stackElements != null) {
for (int s = 0; s < stackElements.length; s++) {
out.println("<div>"+"" + stackElements[s]+"</div>");
}
}
out.println("</div>");
}
}
%>
</body>
</html>
arc-04-09-简单的性能调优
最新推荐文章于 2013-12-30 00:15:40 发布