Improve formatting of compiler output
This commit is contained in:
parent
3cef3759a8
commit
6af9357ba1
2 changed files with 32 additions and 3 deletions
|
@ -8,6 +8,8 @@ import org.mozilla.javascript.Scriptable;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
|
import helma.util.StringUtils;
|
||||||
|
|
||||||
public class Profiler implements Debugger {
|
public class Profiler implements Debugger {
|
||||||
|
|
||||||
HashMap frames = new HashMap();
|
HashMap frames = new HashMap();
|
||||||
|
@ -64,10 +66,16 @@ public class Profiler implements Debugger {
|
||||||
return ((ProfilerFrame)o2).runtime - ((ProfilerFrame)o1).runtime;
|
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");
|
StringBuffer buffer = new StringBuffer(" total average calls path\n");
|
||||||
buffer.append("==================================================================\n");
|
buffer.append("==================================================================\n");
|
||||||
for (int i = 0; i < Math.min(100, f.length); i++) {
|
for (int i = 0; i < length; i++) {
|
||||||
buffer.append(f[i].renderLine(0));
|
buffer.append(f[i].renderLine(prefixLength));
|
||||||
}
|
}
|
||||||
return buffer.toString();
|
return buffer.toString();
|
||||||
}
|
}
|
||||||
|
|
|
@ -84,4 +84,25 @@ public class StringUtils {
|
||||||
return (String[]) list.toArray(new String[list.size()]);
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue