Source

jsprobes-patches / js-run-probes

Full commit
# HG changeset patch
# Parent f083cea597c9dd89209302d6739c18a648620b12

diff --git a/js/src/jsinterp.cpp b/js/src/jsinterp.cpp
--- a/js/src/jsinterp.cpp
+++ b/js/src/jsinterp.cpp
@@ -509,17 +509,23 @@ js::InvokeKernel(JSContext *cx, CallArgs
     StackFrame *fp = ifg.fp();
     if (!fp->functionPrologue(cx))
         return false;
 
     /* Run function until JSOP_STOP, JSOP_RETURN or error. */
     JSBool ok;
     {
         AutoPreserveEnumerators preserve(cx);
-        ok = RunScript(cx, fun->script(), fp);
+        JSScript *script = fun->script();
+
+        Probes::startExecution(cx, script);
+
+        ok = RunScript(cx, script, fp);
+
+        Probes::stopExecution(cx, script);
     }
 
     args.rval() = fp->returnValue();
     JS_ASSERT_IF(ok && construct, !args.rval().isPrimitive());
     return ok;
 }
 
 bool
diff --git a/js/src/jsprobedefs.cpp b/js/src/jsprobedefs.cpp
--- a/js/src/jsprobedefs.cpp
+++ b/js/src/jsprobedefs.cpp
@@ -213,16 +213,44 @@ compartment_id(JSRuntime *rt, ProbeValue
 bool
 env_currentTimeMS(JSRuntime *rt, ProbeValue *arg)
 {
     JS_ASSERT(arg->ty == ProbeType_DummyGlobal);
     PROBE_VALUE_SET(arg, double, (double)(PR_Now()/PR_USEC_PER_MSEC));
     return true;
 }
 
+bool
+env_currentTimeUS(JSRuntime *rt, ProbeValue *arg)
+{
+    JS_ASSERT(arg->ty == ProbeType_DummyGlobal);
+    PROBE_VALUE_SET(arg, double, (double)PR_Now());
+    return true;
+}
+
+bool
+env_threadId(JSRuntime *rt, ProbeValue *arg)
+{
+    JS_ASSERT(arg->ty == ProbeType_DummyGlobal);
+    PROBE_VALUE_SET(arg, intptr_t, (intptr_t)PR_GetCurrentThread());
+    return true;
+}
+
+bool
+context_to_compartment(JSRuntime *rt, ProbeValue *arg)
+{
+    JS_ASSERT(arg);
+    JS_ASSERT(arg->ty == ProbeType_JSContextPtr);
+    JS_ASSERT(arg->data.as_JSContextPtr);
+    PROBE_VALUE_SET(arg, intptr_t,
+                    (intptr_t)arg->data.as_JSContextPtr->compartment);
+    return true;
+}
+
+
 js::Value
 deserialize_size_t(JSContext *cx, ProbeValue v)
 {
     return js::DoubleValue((double)v.data.as_size_t);
 }
 
 js::Value
 deserialize_intptr_t(JSContext *cx, ProbeValue v)
diff --git a/js/src/jsprobedefs.h b/js/src/jsprobedefs.h
--- a/js/src/jsprobedefs.h
+++ b/js/src/jsprobedefs.h
@@ -151,16 +151,19 @@ bool runtime_gcBytes(JSRuntime *rt, Prob
 bool runtime_gcMaxBytes(JSRuntime *rt, ProbeValue *val);
 bool runtime_gcMaxMallocBytes(JSRuntime *rt, ProbeValue *val);
 bool compartment_runtime(JSRuntime *rt, ProbeValue *val);
 bool compartment_gcBytes(JSRuntime *rt, ProbeValue *val);
 bool compartment_gcTriggerBytes(JSRuntime *rt, ProbeValue *val);
 bool compartment_gcLastBytes(JSRuntime *rt, ProbeValue *val);
 bool compartment_id(JSRuntime *rt, ProbeValue *val);
 bool env_currentTimeMS(JSRuntime *rt, ProbeValue *val);
+bool env_currentTimeUS(JSRuntime *rt, ProbeValue *val);
+bool env_threadId(JSRuntime *rt, ProbeValue *val);
+bool context_to_compartment(JSRuntime *rt, ProbeValue *val);
 
 js::Value deserialize_size_t(JSContext *cx, ProbeValue val);
 js::Value deserialize_intptr_t(JSContext *cx, ProbeValue val);
 js::Value deserialize_int(JSContext *cx, ProbeValue val);
 js::Value deserialize_double(JSContext *cx, ProbeValue val);
 js::Value deserialize_OwnedSCBufferPtr(JSContext *cx, ProbeValue val);    
 js::Value deserialize_OwnedConstCharPtr(JSContext *cx, ProbeValue val);
     
diff --git a/js/src/jsprobes.h b/js/src/jsprobes.h
--- a/js/src/jsprobes.h
+++ b/js/src/jsprobes.h
@@ -829,16 +829,23 @@ Probes::startExecution(JSContext *cx, JS
     if (JAVASCRIPT_EXECUTE_START_ENABLED())
         JAVASCRIPT_EXECUTE_START((script->filename ? (char *)script->filename : nullName),
                                  script->lineno);
 #endif
 #ifdef MOZ_ETW
     if (ProfilingActive && !ETWStartExecution(cx, script))
         ok = false;
 #endif
+#ifdef MOZ_JSPROBES
+    ProbeManager *mgr = ProbeManager::manager();
+    if (!mgr
+        || mgr->isProbeRuntime(cx->compartment->rt) 
+        || !mgr->fireProbe(JS_WILL_EXECUTE_SCRIPT, cx, script))
+        ok = false;
+#endif
 
     return ok;
 }
 
 inline bool
 Probes::stopExecution(JSContext *cx, JSScript *script)
 {
     bool ok = true;
@@ -847,16 +854,23 @@ Probes::stopExecution(JSContext *cx, JSS
     if (JAVASCRIPT_EXECUTE_DONE_ENABLED())
         JAVASCRIPT_EXECUTE_DONE((script->filename ? (char *)script->filename : nullName),
                                 script->lineno);
 #endif
 #ifdef MOZ_ETW
     if (ProfilingActive && !ETWStopExecution(cx, script))
         ok = false;
 #endif
+#ifdef MOZ_JSPROBES
+    ProbeManager *mgr = ProbeManager::manager();
+    if (!mgr
+        || mgr->isProbeRuntime(cx->compartment->rt) 
+        || !mgr->fireProbe(JS_DID_EXECUTE_SCRIPT, cx, script))
+        ok = false;
+#endif
 
     return ok;
 }
 
 struct AutoFunctionCallProbe {
     JSContext * const cx;
     JSFunction *fun;
     JSScript *script;
diff --git a/js/src/jsprobes.tbl b/js/src/jsprobes.tbl
--- a/js/src/jsprobes.tbl
+++ b/js/src/jsprobes.tbl
@@ -198,16 +198,19 @@ PROBE_TRANS(runtime_gcBytes,            
 PROBE_TRANS(runtime_gcMaxBytes,            gcMaxBytes,         2,  JSRuntimePtr,        size_t)
 PROBE_TRANS(runtime_gcMaxMallocBytes,      gcMaxMallocBytes,   3,  JSRuntimePtr,        size_t)
 PROBE_TRANS(compartment_runtime,           runtime,            4,  JSCompartmentPtr,    JSRuntimePtr)
 PROBE_TRANS(compartment_gcBytes,           gcBytes,            5,  JSCompartmentPtr,    size_t)
 PROBE_TRANS(compartment_gcTriggerBytes,    gcTriggerBytes,     6,  JSCompartmentPtr,    size_t)
 PROBE_TRANS(compartment_gcLastBytes,       gcLastBytes,        7,  JSCompartmentPtr,    size_t)
 PROBE_TRANS(compartment_id,                id,                 8,  JSCompartmentPtr,    intptr_t)
 PROBE_TRANS(env_currentTimeMS,             currentTimeMS,      9,  DummyGlobal,         double)
+PROBE_TRANS(env_currentTimeUS,             currentTimeUS,     10,  DummyGlobal,         double)
+PROBE_TRANS(env_threadId,                  threadId,          11,  DummyGlobal,         intptr_t)
+PROBE_TRANS(context_to_compartment,        compartment,       12,  JSContextPtr,        JSCompartmentPtr)
 
 /* teardown PROBE_POINT helpers */
 #undef _NO_ARGS
 #undef _ARG
 #undef _ARG_1
 #undef _ARG_2
 #undef _ARG_3
 #undef _ARG_4
diff --git a/toolkit/components/probes/ProbeService.cpp b/toolkit/components/probes/ProbeService.cpp
--- a/toolkit/components/probes/ProbeService.cpp
+++ b/toolkit/components/probes/ProbeService.cpp
@@ -396,17 +396,17 @@ ProbeServiceImpl::AsyncQuery(const nsASt
         return NS_ERROR_FAILURE;
 
     nsIScriptContext *scriptCx = GetScriptContextFromJSContext(cx);
     if (!scriptCx)
         return NS_ERROR_FAILURE;
 
     mListeners.Put(codeCookie, listener);
     mListenerContexts.Put(codeCookie, scriptCx);
-    StartDrainTimer(1000);
+    StartDrainTimer(400);
 
     return NS_OK;
 }
 
 NS_IMPL_THREADSAFE_ISUPPORTS1(ProbeServiceImpl, nsIProbeService)
 NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsIProbeService, ProbeServiceImpl::CreateInstance)
 
 #define NS_PROBESERVICE_CID \