提交 dbce1ba0 authored 作者: Thomas Mueller's avatar Thomas Mueller

Profiler: allow to create a summary per class and not just per package

上级 ee7b8646
...@@ -24,6 +24,7 @@ public class Profiler implements Runnable { ...@@ -24,6 +24,7 @@ public class Profiler implements Runnable {
public int interval = 2; public int interval = 2;
public int depth = 32; public int depth = 32;
public boolean paused; public boolean paused;
public boolean sumClasses;
private String[] ignoreLines = StringUtils.arraySplit("", ',', true); private String[] ignoreLines = StringUtils.arraySplit("", ',', true);
private String[] ignorePackages = StringUtils.arraySplit( private String[] ignorePackages = StringUtils.arraySplit(
...@@ -48,7 +49,12 @@ public class Profiler implements Runnable { ...@@ -48,7 +49,12 @@ public class Profiler implements Runnable {
, ',', true); , ',', true);
private volatile boolean stop; private volatile boolean stop;
private HashMap<String, Integer> counts = new HashMap<String, Integer>(); private HashMap<String, Integer> counts = new HashMap<String, Integer>();
private HashMap<String, Integer> packages = new HashMap<String, Integer>();
/**
* The summary (usually one entry per package, unless sumClasses is enabled,
* in which case it's one entry per class).
*/
private HashMap<String, Integer> summary = new HashMap<String, Integer>();
private int minCount = 1; private int minCount = 1;
private int total; private int total;
private Thread thread; private Thread thread;
...@@ -147,15 +153,19 @@ public class Profiler implements Runnable { ...@@ -147,15 +153,19 @@ public class Profiler implements Runnable {
int index = 0; int index = 0;
for (; index < el.length(); index++) { for (; index < el.length(); index++) {
char c = el.charAt(index); char c = el.charAt(index);
if (Character.isUpperCase(c) || c == '(') { if (c == '(' || Character.isUpperCase(c)) {
break; break;
} }
} }
if (index > 0 && el.charAt(index - 1) == '.') { if (index > 0 && el.charAt(index - 1) == '.') {
index--; index--;
} }
String packageName = el.substring(0, index); if (sumClasses) {
increment(packages, packageName, 0); int m = el.indexOf('.', index + 1);
index = m >= 0 ? m : index;
}
String groupName = el.substring(0, index);
increment(summary, groupName, 0);
} }
j++; j++;
} }
...@@ -212,8 +222,8 @@ public class Profiler implements Runnable { ...@@ -212,8 +222,8 @@ public class Profiler implements Runnable {
buff.append("(none)").append(SysProperties.LINE_SEPARATOR); buff.append("(none)").append(SysProperties.LINE_SEPARATOR);
} }
appendTop(buff, counts, count, total, false); appendTop(buff, counts, count, total, false);
buff.append("packages:").append(SysProperties.LINE_SEPARATOR); buff.append("summary:").append(SysProperties.LINE_SEPARATOR);
appendTop(buff, packages, count, total, true); appendTop(buff, summary, count, total, true);
buff.append('.'); buff.append('.');
return buff.toString(); return buff.toString();
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论