Source

jsprobes-patches / jsshell-integration

Full commit
# HG changeset patch
# Parent 1fbf4f7de60e01edc61f6ce4dc898c53aec681ba

diff --git a/js/src/shell/js.cpp b/js/src/shell/js.cpp
--- a/js/src/shell/js.cpp
+++ b/js/src/shell/js.cpp
@@ -102,6 +102,8 @@
 #include "jsscriptinlines.h"
 #include "methodjit/MethodJIT.h"
 
+#include "jsprobemgr.h"
+
 #ifdef XP_UNIX
 #include <unistd.h>
 #include <sys/types.h>
@@ -5756,6 +5758,44 @@
     if (!cx)
         return 1;
 
+#ifdef MOZ_JSPROBES
+    using namespace js::probes;
+    ProbeManager *pm = ProbeManager::create();
+    pm->start();
+
+    ScriptDescriptor oneShot;
+    const char *asyncstr1 = "total = 0;\n";
+    size_t asyncstr1_len = strlen(asyncstr1);
+    oneShot.body = InflateString(cx, asyncstr1, &asyncstr1_len);
+    oneShot.length = asyncstr1_len;
+    oneShot.filename = "<imaginary>";
+    oneShot.lineno = 1;
+
+    ScriptDescriptor handler;
+    HandlerCookie unusedIdent;
+    
+    const char *handlerstr1 = "total += runtime.gcMaxBytes; date = new Date(env.currentTimeMS);\n";
+    size_t handlerstr1_len = strlen(handlerstr1);
+    handler.body = InflateString(cx, handlerstr1, &handlerstr1_len);
+    handler.length = handlerstr1_len;
+    handler.filename = "<imaginary>";
+    handler.lineno = 1;
+
+    ScriptDescriptor dataSpec;
+    const char *dataspecstr1 = "using(runtime.gcMaxBytes); using(env.currentTimeMS)\n";
+    size_t dataspecstr1_len = strlen(dataspecstr1);
+    dataSpec.body = InflateString(cx, dataspecstr1, &dataspecstr1_len);
+    dataSpec.length = dataspecstr1_len;
+    dataSpec.filename = "<data spec>";
+    dataSpec.lineno = 1;
+
+    ScriptCookie unusedCookie;
+    pm->runScriptOnce(oneShot, &unusedCookie);
+    pm->addProbeHandler(JS_RUNTIME_DESTROY, handler, dataSpec, &unusedIdent);
+
+
+#endif /* MOZ_JSPROBES */
+
     JS_SetGCParameter(rt, JSGC_MODE, JSGC_MODE_COMPARTMENT);
     JS_SetGCParameterForThread(cx, JSGC_MAX_CODE_CACHE_BYTES, 16 * 1024 * 1024);
 
@@ -5776,5 +5816,19 @@
 
     JS_DestroyRuntime(rt);
     JS_ShutDown();
+
+#ifdef MOZ_JSPROBES
+    const char *asyncstr2 = "print(\"counted total = \" + total); print(\"last timestamp: \" + date);\n";
+    size_t asyncstr2_len = strlen(asyncstr2);
+    oneShot.body = InflateString(cx, asyncstr2, &asyncstr2_len);
+    oneShot.length = asyncstr2_len;
+    oneShot.filename = "<imaginary>";
+    oneShot.lineno = 1;
+
+    ScriptCookie unusedCookie2;
+    pm->runScriptOnce(oneShot, &unusedCookie2);
+    pm->shutdown();
+#endif
+
     return result;
 }