쓰레드 덤프보는 JSP (threaddump.jsp)
Notice : 해당 자료가 저작권등에 의해서 문제가 있다면 바로 삭제하겠습니다. 연구목적으로 사용하지 않고 악의적인 목적으로 이용할 경우 발생할 수 있는 법적은 책임은 모두 본인에게 있습니다. 쓰레드 덤프보는 JSP (threaddump.jsp) 완전 멋지다!ㅋ
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <%-- This source is under a creative common license. (Attribution Non-Commercial) You can use it for non-commercial purposes only. Author: Dongyoul Kim Blog: http://greatkim91.tistory.com Twitter: greatkim91 --%> <%@ page contentType="text/html; charset=UTF-8" %> <%@ page import="java.util.List"%> <%@ page import="java.util.ArrayList"%> <%@ page import="java.util.Collections"%> <%@ page import="java.util.Comparator"%> <%@ page import="java.lang.management.ManagementFactory"%> <%@ page import="java.lang.management.MemoryMXBean"%> <%@ page import="java.lang.management.MemoryUsage"%> <%@ page import="java.text.DecimalFormat"%> <%@ page import="java.text.NumberFormat"%> <%@ page import="java.lang.management.ThreadInfo"%> <%@ page import="java.lang.management.ThreadMXBean"%> <%! private static String kbytes(long l) { NumberFormat nf = new DecimalFormat("#,###"); return nf.format(l/1000); } private static String percent(double l) { NumberFormat nf = new DecimalFormat("#.#"); return nf.format(l); } private static List<ThreadInfo> loadThreadInfo() { ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean(); ThreadInfo[] threadInfoArray = threadMXBean.getThreadInfo(threadMXBean.getAllThreadIds(), Integer.MAX_VALUE); List<ThreadInfo> threadInfos = new ArrayList<ThreadInfo>(threadInfoArray.length); for (ThreadInfo threadInfo : threadInfoArray) { threadInfos.add(threadInfo); } Collections.sort( threadInfos, new Comparator() { public int compare(Object o1, Object o2) { if (o1 == null || o2 == null) return 0; ThreadInfo t1 = (ThreadInfo) o1; ThreadInfo t2 = (ThreadInfo) o2; return t1.getThreadName().compareTo(t2.getThreadName()); } } ); return threadInfos; } %> <html> <head> <title>Thread dump</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="cache-control" content="no-cache" /> <meta http-equiv="Pragma" content="no-cache" /> <style type="text/css"> <!-- body { font: 12px sans-serif; } table { border: 0px solid #DEDEDE; } td, th { border: 1px solid #DEDEDE; padding: 1px 10px; } .right { text-align: right; } --> </style> </head> <body> <% String uri = request.getRequestURI(); String namePrefix = request.getParameter("name"); String stateParam = request.getParameter("state"); long threadId; try { threadId = Long.parseLong(request.getParameter("tid")); } catch(Exception e) { threadId = -1; } // Memory Info MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean(); MemoryUsage heapMemoryUsage = memoryMXBean.getHeapMemoryUsage(); MemoryUsage nonHeapMemoryUsage = memoryMXBean.getNonHeapMemoryUsage(); double heapUsedPercent = ((double)heapMemoryUsage.getUsed()/(double)heapMemoryUsage.getMax()) * 100.0D; double nonHeapUsedPercent = ((double)nonHeapMemoryUsage.getUsed()/(double)nonHeapMemoryUsage.getMax()) * 100.0D; %> <table> <tr> <th>Area</th> <th>Init (KB)</th> <th>Max (KB)</th> <th>Used (KB)</th> <th>Used(%)</th> </tr> <tr> <td>Heap</td> <td class="right"><%=kbytes(heapMemoryUsage.getInit())%></td> <td class="right"><%=kbytes(heapMemoryUsage.getMax())%></td> <td class="right"><%=kbytes(heapMemoryUsage.getUsed())%></td> <td class="right"><%=percent(heapUsedPercent)%></td> </tr> <tr> <td>Non Heap</td> <td class="right"><%=kbytes(nonHeapMemoryUsage.getInit())%></td> <td class="right"><%=kbytes(nonHeapMemoryUsage.getMax())%></td> <td class="right"><%=kbytes(nonHeapMemoryUsage.getUsed())%></td> <td class="right"><%=percent(nonHeapUsedPercent)%></td> </tr> </table> <hr/> <form method="get"> Show only what thread name starts with <input type="text" name="name" value="<%=(namePrefix != null ? namePrefix : "")%>"/> and thread state is <select name="state"> <option value="all">All</option> <% for(Thread.State threadState: Thread.State.values()) { boolean selected = threadState.toString().equals(stateParam); %> <option value="<%=threadState%>"<%=selected ? " selected=\"true\"" : ""%>><%=threadState%></option> <% } %> </select> <input type="submit" value="go!"/> </form> <% if(threadId != -1 || (namePrefix != null && namePrefix.trim().length() > 0)) { %> <a href="<%=uri%>">Show all threads</a> <% } %> <% // Thread info for(ThreadInfo threadInfo : loadThreadInfo()) { StackTraceElement[] stackTraces = threadInfo.getStackTrace(); // filter the current thread if (threadInfo.getThreadId() == Thread.currentThread().getId()) continue; // filter name if (namePrefix != null && namePrefix.trim().length() > 0) { if (!threadInfo.getThreadName().startsWith(namePrefix)) continue; } // filter state if (stateParam != null && !stateParam.equals("all")) { if (!threadInfo.getThreadState().toString().equals(stateParam)) continue; } // show only specific thread id if (threadId != -1) { if (threadInfo.getThreadId() != threadId) continue; } %> <dl> <dt> <b><%=threadInfo.getThreadName()%> (<%=threadInfo.getThreadState()%>)</b> - <a href="<%=uri%>?tid=<%=threadInfo.getThreadId()%>"><%=threadInfo.getThreadId()%></a> </dt> <dd> <pre> <% for(int i = 0; i < stackTraces.length; i++) { out.println(stackTraces[i]); } %> </pre> </dd> </dl> <% } %> </body> </html> |
간단한 메모리 정보와 현재 쓰레드들의 스택들을 보여줍니다. … Continue reading