r9973 - in helma/helma/trunk/src/helma/scripting/rhino: . debug
[email protected] Mon, 28 Sep 2009 15:54:15 +0200 (CEST)
| Newsgroups | gmane.comp.java.helma.cvs |
|---|---|
| Message-ID | <20090928135415.1655B3D0E2@mia> |
Author: hannes
Date: 2009-09-28 15:54:14 +0200 (Mon, 28 Sep 2009)
New Revision: 9973
Modified:
helma/helma/trunk/src/helma/scripting/rhino/RhinoEngine.java
helma/helma/trunk/src/helma/scripting/rhino/debug/Profiler.java
Log:
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.
Details at http://dev.helma.org/trac/helma/changeset/9973
Modified: helma/helma/trunk/src/helma/scripting/rhino/RhinoEngine.java
===================================================================
--- helma/helma/trunk/src/helma/scripting/rhino/RhinoEngine.java 2009-09-28 13:07:59 UTC (rev 9972)
+++ helma/helma/trunk/src/helma/scripting/rhino/RhinoEngine.java 2009-09-28 13:54:14 UTC (rev 9973)
@@ -164,7 +164,7 @@
if (core.hasTracer) {
context.setDebugger(new Tracer(getResponse()), null);
- } else if (core.hasProfiler) {
+ } else if (useProfiler()) {
context.setDebugger(new Profiler(), null);
}
@@ -212,7 +212,7 @@
* execution context has terminated.
*/
public synchronized void exitContext() {
- if (core.hasProfiler) {
+ if (useProfiler()) {
try {
Profiler profiler = (Profiler) Context.getCurrentContext().getDebugger();
String result = profiler.getResult();
@@ -718,4 +718,24 @@
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;
+ }
+
}
Modified: helma/helma/trunk/src/helma/scripting/rhino/debug/Profiler.java
===================================================================
--- helma/helma/trunk/src/helma/scripting/rhino/debug/Profiler.java 2009-09-28 13:07:59 UTC (rev 9972)
+++ helma/helma/trunk/src/helma/scripting/rhino/debug/Profiler.java 2009-09-28 13:54:14 UTC (rev 9973)
@@ -15,10 +15,9 @@
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