提交 7aacf725 authored 作者: Thomas Mueller's avatar Thomas Mueller

--no commit message

--no commit message
上级 8c586588
...@@ -18,7 +18,7 @@ import org.h2.engine.Constants; ...@@ -18,7 +18,7 @@ import org.h2.engine.Constants;
*/ */
public class Profiler implements Runnable { public class Profiler implements Runnable {
private static final int MAX_ELEMENTS = 1000; private static final int MAX_ELEMENTS = 1000;
private int interval = 10; private int interval = 50;
private int depth = 16; private int depth = 16;
private String[] ignoreLines = StringUtils.arraySplit("", ',', true); private String[] ignoreLines = StringUtils.arraySplit("", ',', true);
private String[] ignoreThreads = StringUtils.arraySplit( private String[] ignoreThreads = StringUtils.arraySplit(
...@@ -48,55 +48,63 @@ public class Profiler implements Runnable { ...@@ -48,55 +48,63 @@ public class Profiler implements Runnable {
public void run() { public void run() {
while (!stop) { while (!stop) {
if (interval > 0) { try {
try { tick();
Thread.sleep(interval); } catch (Throwable t) {
} catch (Exception e) { break;
// ignore
}
} }
Map<Thread, StackTraceElement[]> map = Thread.getAllStackTraces(); }
for (Map.Entry<Thread, StackTraceElement[]> entry : map.entrySet()) { }
Thread t = entry.getKey();
if (t.getState() != Thread.State.RUNNABLE) { private void tick() {
continue; if (interval > 0) {
} try {
StackTraceElement[] dump = entry.getValue(); Thread.sleep(interval);
if (dump.length == 0) { } catch (Exception e) {
continue; // ignore
}
}
Map<Thread, StackTraceElement[]> map = Thread.getAllStackTraces();
for (Map.Entry<Thread, StackTraceElement[]> entry : map.entrySet()) {
Thread t = entry.getKey();
if (t.getState() != Thread.State.RUNNABLE) {
continue;
}
StackTraceElement[] dump = entry.getValue();
if (dump.length == 0) {
continue;
}
boolean ignoreThis = false;
for (String ig : ignoreThreads) {
if (ig.length() > 0 && dump[0].toString().startsWith(ig)) {
ignoreThis = true;
break;
} }
boolean ignoreThis = false; }
for (String ig : ignoreThreads) { if (ignoreThis) {
if (ig.length() > 0 && dump[0].toString().startsWith(ig)) { continue;
}
StringBuilder buff = new StringBuilder();
// simple recursive calls are ignored
String last = null;
for (int j = 0, i = 0; i < dump.length && j < depth; i++) {
String el = dump[i].toString();
ignoreThis = false;
for (String ig : ignoreLines) {
if (ig.length() > 0 && el.startsWith(ig)) {
ignoreThis = true; ignoreThis = true;
break; break;
} }
} }
if (ignoreThis) { if (!ignoreThis && !el.equals(last)) {
continue; last = el;
} buff.append("at ").append(el).append('\n');
StringBuilder buff = new StringBuilder(); j++;
// simple recursive calls are ignored
String last = null;
for (int j = 0, i = 0; i < dump.length && j < depth; i++) {
String el = dump[i].toString();
ignoreThis = false;
for (String ig : ignoreLines) {
if (ig.length() > 0 && el.startsWith(ig)) {
ignoreThis = true;
break;
}
}
if (!ignoreThis && !el.equals(last)) {
last = el;
buff.append("at ").append(el).append('\n');
j++;
}
}
if (buff.length() > 0) {
increment(buff.toString());
} }
} }
if (buff.length() > 0) {
increment(buff.toString());
}
} }
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论