Bug 1298541: Tracelogger: Part 4: Enable jit-tests/tests/tracelogger/drainTraceLogger.js again, r=bbouvier
authorHannes Verschore <hv1989@gmail.com>
Fri, 02 Sep 2016 18:19:27 +0200
changeset 312535 035fb1b1352986fd15ec827eb38e0a5e6dfc9a93
parent 312534 6586e827265a4abb6d9a69b2380bbd6edc016dd4
child 312536 2b1c3cb1a648b1e3e43f6b1e4d5098330da8eab9
push id30646
push userryanvm@gmail.com
push dateSat, 03 Sep 2016 15:33:40 +0000
treeherdermozilla-central@1789229965bf [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbbouvier
bugs1298541
milestone51.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1298541: Tracelogger: Part 4: Enable jit-tests/tests/tracelogger/drainTraceLogger.js again, r=bbouvier
js/src/jit-test/tests/tracelogger/drainTraceLogger.js
js/src/vm/Debugger.cpp
js/src/vm/TraceLogging.h
js/src/vm/TraceLoggingTypes.h
--- a/js/src/jit-test/tests/tracelogger/drainTraceLogger.js
+++ b/js/src/jit-test/tests/tracelogger/drainTraceLogger.js
@@ -1,28 +1,30 @@
 function TestDrainTraceLoggerInvariants(obj) {
     var scripts = 0;
     var stops = 0;
     for (var i = 0; i < objs.length; i++) {
-        if (objs[i].logType == "Scripts") {
+        if (objs[i].logType == "Script") {
             scripts++;
-            assertEq("fileName" in objs[i], true); 
-            assertEq("lineNumber" in objs[i], true); 
-            assertEq("columnNumber" in objs[i], true); 
+            assertEq("fileName" in objs[i], true);
+            assertEq("lineNumber" in objs[i], true);
+            assertEq("columnNumber" in objs[i], true);
         } else if (objs[i].logType == "Stop") {
             stops++;
         } else {
             assertEq(true, false);
         }
     }
-    assertEq(scripts, stops);
+    assertEq(scripts, stops + 1);
+    // "+ 1" because we get a start for drainTraceLogger.js:1, but not the stop.
 }
 
 function GetMaxScriptDepth(obj) {
     var max_depth = 0;
+    var depth = 0;
     for (var i = 0; i < objs.length; i++) {
         if (objs[i].logType == "Stop")
             depth--;
         else {
             depth++;
             if (depth > max_depth)
                 max_depth = depth;
         }
@@ -33,56 +35,54 @@ function GetMaxScriptDepth(obj) {
 function foo1() {
     foo2();
 }
 function foo2() {
 
 }
 
 var du = new Debugger();
-if (typeof du.drainTraceLoggerTraces == "function") {
-print(1);
+if (typeof du.drainTraceLoggerScriptCalls == "function") {
     // Test normal setup.
     du = new Debugger();
-    du.setupTraceLoggerForTraces();
+    du.setupTraceLoggerScriptCalls();
 
     du.startTraceLogger();
     du.endTraceLogger();
 
-    var objs = du.drainTraceLoggerTraces();
+    var objs = du.drainTraceLoggerScriptCalls();
     TestDrainTraceLoggerInvariants(objs);
-    var empty_depth = GetMaxScriptDepth(objs);
-    var empty_length = objs.length;
 
     // Test basic script.
     for (var i=0; i<20; i++)
         foo1();
 
     du = new Debugger();
-    du.setupTraceLoggerTraces();
+    du.setupTraceLoggerScriptCalls();
 
     du.startTraceLogger();
     foo1();
     du.endTraceLogger();
 
-    var objs = du.drainTraceLoggerTraces();
+    var objs = du.drainTraceLoggerScriptCalls();
     TestDrainTraceLoggerInvariants(objs);
-    assertEq(empty_depth + 2 == GetMaxScriptDepth(objs));
-    assertEq(empty_length + 4 == GetMaxScriptDepth(objs));
-    
+    assertEq(3, GetMaxScriptDepth(objs), "drainTraceLogger.js:0 + foo1 + foo2");
+    assertEq(5, objs.length, "drainTraceLogger.js:0 + foo1 + foo2 + stop + stop");
+
     // Test basic script.
     for (var i=0; i<20; i++)
         foo1();
 
     du = new Debugger();
-    du.setupTraceLoggerForTraces();
+    du.setupTraceLoggerScriptCalls();
 
     du.startTraceLogger();
     for (var i=0; i<100; i++) {
         foo1();
     }
     du.endTraceLogger();
 
-    var objs = du.drainTraceLoggerTraces();
+    var objs = du.drainTraceLoggerScriptCalls();
     TestDrainTraceLoggerInvariants(objs);
-    assertEq(empty_depth + 2 == GetMaxScriptDepth(objs));
-    assertEq(empty_length + 4*100 == GetMaxScriptDepth(objs));
+    assertEq(3, GetMaxScriptDepth(objs), "drainTraceLogger.js:0 + foo1 + foo2");
+    assertEq(4*100 + 1, objs.length);
+    assertEq(1 + 4*100, objs.length, "drainTraceLogger.js:0 + 4 * ( foo1 + foo2 + stop + stop )");
 }
--- a/js/src/vm/Debugger.cpp
+++ b/js/src/vm/Debugger.cpp
@@ -645,16 +645,27 @@ Debugger::Debugger(JSContext* cx, Native
 #endif
     traceLoggerScriptedCallsLastDrainedSize(0),
     traceLoggerScriptedCallsLastDrainedIteration(0)
 {
     assertSameCompartment(cx, dbg);
 
     JS_INIT_CLIST(&breakpoints);
     JS_INIT_CLIST(&onNewGlobalObjectWatchersLink);
+
+#ifdef JS_TRACE_LOGGING
+    TraceLoggerThread* logger = TraceLoggerForMainThread(cx->runtime());
+    if (logger) {
+#ifdef NIGHTLY_BUILD
+        logger->getIterationAndSize(&traceLoggerLastDrainedIteration, &traceLoggerLastDrainedSize);
+#endif
+        logger->getIterationAndSize(&traceLoggerScriptedCallsLastDrainedIteration,
+                                    &traceLoggerScriptedCallsLastDrainedSize);
+    }
+#endif
 }
 
 Debugger::~Debugger()
 {
     MOZ_ASSERT_IF(debuggees.initialized(), debuggees.empty());
     allocationsLog.clear();
 
     /*
--- a/js/src/vm/TraceLogging.h
+++ b/js/src/vm/TraceLogging.h
@@ -223,21 +223,25 @@ class TraceLoggerThread
             MOZ_ASSERT(*lastSize <= events.size());
             *num = events.size() - *lastSize;
             start = events.data() + *lastSize;
         } else {
             *num = events.size();
             start = events.data();
         }
 
-        *lastIteration = iteration_;
-        *lastSize = events.size();
+        getIterationAndSize(lastIteration, lastSize);
         return start;
     }
 
+    void getIterationAndSize(uint32_t* iteration, uint32_t* size) const {
+        *iteration = iteration_;
+        *size = events.size();
+    }
+
     // Extract the details filename, lineNumber and columnNumber out of a event
     // containing script information.
     void extractScriptDetails(uint32_t textId, const char** filename, size_t* filename_len,
                               const char** lineno, size_t* lineno_len, const char** colno,
                               size_t* colno_len);
 
     bool lostEvents(uint32_t lastIteration, uint32_t lastSize) {
         // If still logging in the same iteration, there are no lost events.
--- a/js/src/vm/TraceLoggingTypes.h
+++ b/js/src/vm/TraceLoggingTypes.h
@@ -173,29 +173,29 @@ class ContinuousSpace {
     static uint32_t maxSize() {
         return LIMIT / sizeof(T);
     }
 
     T* data() {
         return data_;
     }
 
-    uint32_t capacity() {
+    uint32_t capacity() const {
         return capacity_;
     }
 
-    uint32_t size() {
+    uint32_t size() const {
         return size_;
     }
 
-    bool empty() {
+    bool empty() const {
         return size_ == 0;
     }
 
-    uint32_t lastEntryId() {
+    uint32_t lastEntryId() const {
         MOZ_ASSERT(!empty());
         return size_ - 1;
     }
 
     T& lastEntry() {
         return data()[lastEntryId()];
     }