r9972 - in helma/helma/trunk/src/helma: scripting/rhino/debug util
[email protected] Mon, 28 Sep 2009 15:07:59 +0200 (CEST)
| Newsgroups | gmane.comp.java.helma.cvs |
|---|---|
| Message-ID | <20090928130759.40DF93D0E2@mia> |
Author: hannes
Date: 2009-09-28 15:07:59 +0200 (Mon, 28 Sep 2009)
New Revision: 9972
Modified:
helma/helma/trunk/src/helma/scripting/rhino/debug/Profiler.java
helma/helma/trunk/src/helma/util/StringUtils.java
Log:
Improve formatting of compiler output
Details at http://dev.helma.org/trac/helma/changeset/9972
Modified: helma/helma/trunk/src/helma/scripting/rhino/debug/Profiler.java
===================================================================
--- helma/helma/trunk/src/helma/scripting/rhino/debug/Profiler.java 2009-09-28 12:55:24 UTC (rev 9971)
+++ helma/helma/trunk/src/helma/scripting/rhino/debug/Profiler.java 2009-09-28 13:07:59 UTC (rev 9972)
@@ -8,6 +8,8 @@
import java.util.*;
+import helma.util.StringUtils;
+
public class Profiler implements Debugger {
HashMap frames = new HashMap();
@@ -64,10 +66,16 @@
return ((ProfilerFrame)o2).runtime - ((ProfilerFrame)o1).runtime;
}
});
+ int length = Math.min(100, f.length);
+ int prefixLength = Integer.MAX_VALUE;
+ for (int i = 0; i < length - 1; i++) {
+ prefixLength = Math.min(prefixLength,
+ StringUtils.getCommonPrefix(f[i].name, f[i+1].name).length());
+ }
StringBuffer buffer = new StringBuffer(" total average calls path\n");
buffer.append("==================================================================\n");
- for (int i = 0; i < Math.min(100, f.length); i++) {
- buffer.append(f[i].renderLine(0));
+ for (int i = 0; i < length; i++) {
+ buffer.append(f[i].renderLine(prefixLength));
}
return buffer.toString();
}
@@ -134,7 +142,7 @@
Integer.valueOf(invocations),
name.substring(prefixLength)
};
- formatter.format("%1$7d ms %2$5d ms %3$6d %4$s%n", args);
+ formatter.format("%1$7d ms %2$5d ms %3$6d %4$s%n", args);
return formatter.toString();
}
}
Modified: helma/helma/trunk/src/helma/util/StringUtils.java
===================================================================
--- helma/helma/trunk/src/helma/util/StringUtils.java 2009-09-28 12:55:24 UTC (rev 9971)
+++ helma/helma/trunk/src/helma/util/StringUtils.java 2009-09-28 13:07:59 UTC (rev 9972)
@@ -84,4 +84,25 @@
return (String[]) list.toArray(new String[list.size()]);
}
+ /**
+ * Get the largest common prefix of Strings s1 and s2
+ * @param s1 a string
+ * @param s2 another string
+ * @return the largest prefix shared by both strings
+ */
+ public static String getCommonPrefix(String s1, String s2) {
+ if (s1.indexOf(s2) == 0) {
+ return s2;
+ } else if (s2.indexOf(s1) == 0) {
+ return s1;
+ }
+ int length = Math.min(s1.length(), s2.length());
+ for (int i = 0; i < length; i++) {
+ if (s1.charAt(i) != s2.charAt(i)) {
+ return s1.substring(0, i);
+ }
+ }
+ return s1.substring(0, length);
+ }
+
}