Add rhino.profile.session property to limit profiling to certain user sessions. If set, the indexOf method of the current session id is called with the property as argument, and the profiler is disabled unless the result is 0.

To only profile sessions from localhost (but beware of local proxies!):

    rhino.profile = true
    rhino.profile.session = 127.0.0.1

To only profile a particular user session:

    rhino.profile = true
    rhino.profile.session = 127.0.0.1n5guagu2sdl2jslf

Note that for the profiler to work you need to start helma with rhino.profile = true since Helma 1 doesn't support mixed compiled/interpreted mode like Helma NG.
This commit is contained in:
hns 2009-09-28 13:54:14 +00:00
parent 6af9357ba1
commit bd1e9dcc25
2 changed files with 24 additions and 5 deletions

View file

@ -164,7 +164,7 @@ public class RhinoEngine implements ScriptingEngine {
if (core.hasTracer) { if (core.hasTracer) {
context.setDebugger(new Tracer(getResponse()), null); context.setDebugger(new Tracer(getResponse()), null);
} else if (core.hasProfiler) { } else if (useProfiler()) {
context.setDebugger(new Profiler(), null); context.setDebugger(new Profiler(), null);
} }
@ -212,7 +212,7 @@ public class RhinoEngine implements ScriptingEngine {
* execution context has terminated. * execution context has terminated.
*/ */
public synchronized void exitContext() { public synchronized void exitContext() {
if (core.hasProfiler) { if (useProfiler()) {
try { try {
Profiler profiler = (Profiler) Context.getCurrentContext().getDebugger(); Profiler profiler = (Profiler) Context.getCurrentContext().getDebugger();
String result = profiler.getResult(); String result = profiler.getResult();
@ -718,4 +718,24 @@ public class RhinoEngine implements ScriptingEngine {
return skin; return skin;
} }
/**
* Determine if we should use a profiler on the current thread. This returns true if
* the rhino.profile app property is set to true (requires restart) and the
* rhino.profile.session property is either unset, or set to "all", or matching
* the session id of the current request.
* @return true if the current request should be profiled
*/
private boolean useProfiler() {
if (!core.hasProfiler) {
return false;
}
String profilerSession = app.getProperty("rhino.profile.session");
if (profilerSession == null || "all".equalsIgnoreCase(profilerSession)) {
return true;
}
RequestTrans req = getRequest();
return req != null && req.getSession() != null
&& req.getSession().indexOf(profilerSession) == 0;
}
} }

View file

@ -15,10 +15,9 @@ public class Profiler implements Debugger {
HashMap frames = new HashMap(); HashMap frames = new HashMap();
/** /**
* Create a profiler that writes to this response object * Create a new profiler.
*/ */
public Profiler() { public Profiler() {}
}
/** /**
* Implementws handleCompilationDone in interface org.mozilla.javascript.debug.Debugger * Implementws handleCompilationDone in interface org.mozilla.javascript.debug.Debugger