Minor profiler and logging tweaks

This commit is contained in:
hns 2009-09-29 13:51:26 +00:00
parent bd1e9dcc25
commit 5d130c9ecb
4 changed files with 20 additions and 7 deletions

View file

@ -621,6 +621,10 @@ public class RequestTrans implements Serializable {
} }
} }
public String toString() {
return method + ":" + path;
}
class ParameterMap extends SystemMap { class ParameterMap extends SystemMap {
public ParameterMap() { public ParameterMap() {

View file

@ -160,7 +160,7 @@ public final class RequestEvaluator implements Runnable {
// request path object // request path object
RequestPath requestPath = new RequestPath(app); RequestPath requestPath = new RequestPath(app);
String txname = req.getMethod().toLowerCase() + ":" + req.getPath(); String txname = req.getMethod() + ":" + req.getPath();
Log eventLog = app.getEventLog(); Log eventLog = app.getEventLog();
if (eventLog.isDebugEnabled()) { if (eventLog.isDebugEnabled()) {
eventLog.debug(txname + " starting"); eventLog.debug(txname + " starting");

View file

@ -220,7 +220,7 @@ public class RhinoEngine implements ScriptingEngine {
if (res != null) { if (res != null) {
getResponse().debug("<pre>" + result + "</pre>"); getResponse().debug("<pre>" + result + "</pre>");
} }
app.logEvent(result); app.logEvent("Profiler data for " + getRequest() + ":\n" + result);
} catch (Exception x) { } catch (Exception x) {
app.logError("Error in profiler: " + x, x); app.logError("Error in profiler: " + x, x);
} }

View file

@ -49,7 +49,8 @@ public class Profiler implements Debugger {
if (script.isFunction()) { if (script.isFunction()) {
StringBuffer b = new StringBuffer(script.getSourceName()).append(" #"); StringBuffer b = new StringBuffer(script.getSourceName()).append(" #");
b.append(script.getLineNumbers()[0]); b.append(script.getLineNumbers()[0]);
if (script.getFunctionName() != null) { String funcName = script.getFunctionName();
if (funcName != null && funcName.length() > 0) {
b.append(": ").append(script.getFunctionName()); b.append(": ").append(script.getFunctionName());
} }
return b.toString(); return b.toString();
@ -66,13 +67,21 @@ public class Profiler implements Debugger {
} }
}); });
int length = Math.min(100, f.length); int length = Math.min(100, f.length);
int prefixLength = Integer.MAX_VALUE; int prefixLength = length < 2 ? 0 : Integer.MAX_VALUE;
for (int i = 0; i < length - 1; i++) { int maxLength = 0;
prefixLength = Math.min(prefixLength, for (int i = 0; i < length; i++) {
maxLength = Math.max(maxLength, f[i].name.length());
if (i < length - 1) {
prefixLength = Math.min(prefixLength,
StringUtils.getCommonPrefix(f[i].name, f[i+1].name).length()); StringUtils.getCommonPrefix(f[i].name, f[i+1].name).length());
}
} }
maxLength = maxLength + 30 - prefixLength;
StringBuffer buffer = new StringBuffer(" total average calls path\n"); StringBuffer buffer = new StringBuffer(" total average calls path\n");
buffer.append("==================================================================\n"); for (int i = 0; i < maxLength; i++) {
buffer.append('-');
}
buffer.append('\n');
for (int i = 0; i < length; i++) { for (int i = 0; i < length; i++) {
buffer.append(f[i].renderLine(prefixLength)); buffer.append(f[i].renderLine(prefixLength));
} }