Bug 1072903 - TraceLogger: Part 5: Log whenever tracelogger gets enabled or disabled, r=bbouvier
authorHannes Verschore <hv1989@gmail.com>
Thu, 20 Nov 2014 17:44:01 +0100
changeset 247495 aad64d6ad822f2c9a69e7fb81456161fcb590052
parent 247494 04988ab0c1dad724475c7d932ccf11edf28155bb
child 247496 20dc3d4a930353882f05243e01de935774f549a4
push id4489
push userraliiev@mozilla.com
push dateMon, 23 Feb 2015 15:17:55 +0000
treeherdermozilla-beta@fd7c3dc24146 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbbouvier
bugs1072903
milestone37.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 1072903 - TraceLogger: Part 5: Log whenever tracelogger gets enabled or disabled, r=bbouvier
js/src/vm/TraceLogging.cpp
js/src/vm/TraceLoggingGraph.cpp
js/src/vm/TraceLoggingGraph.h
js/src/vm/TraceLoggingTypes.h
--- a/js/src/vm/TraceLogging.cpp
+++ b/js/src/vm/TraceLogging.cpp
@@ -125,17 +125,17 @@ TraceLoggerThread::init()
 
     graph.addTextId(TraceLogger_LastTreeItem, "TraceLogger internal");
     for (uint32_t i = TraceLogger_LastTreeItem + 1; i < TraceLogger_Last; i++) {
         TraceLoggerTextId id = TraceLoggerTextId(i);
         graph.addTextId(i, TLTextIdString(id));
     }
 
     enabled = 1;
-    graph.enable();
+    logTimestamp(TraceLogger_Enable);
 
     return true;
 }
 
 TraceLoggerThread::~TraceLoggerThread()
 {
     if (!failed)
         graph.log(events);
@@ -152,22 +152,18 @@ TraceLoggerThread::enable()
     if (enabled > 0) {
         enabled++;
         return true;
     }
 
     if (failed)
         return false;
 
-    // TODO: Remove this. This is so the refactor works with mimimal changes,
-    // It is the intention to remove this by logging TraceLogger_Enable/TraceLogger_Disable.
-    events.clear();
-
     enabled = 1;
-    graph.enable();
+    logTimestamp(TraceLogger_Enable);
 
     return true;
 }
 
 bool
 TraceLoggerThread::enable(JSContext *cx)
 {
     if (!enable())
@@ -228,22 +224,17 @@ TraceLoggerThread::disable()
     if (enabled == 0)
         return true;
 
     if (enabled > 1) {
         enabled--;
         return true;
     }
 
-    graph.log(events);
-    events.clear();
-
-    uint64_t time = rdtsc() - traceLoggers.startupTime;
-    graph.disable(time);
-
+    logTimestamp(TraceLogger_Disable);
     enabled = 0;
 
     return true;
 }
 
 const char *
 TraceLoggerThread::eventText(uint32_t id) {
     if (id < TraceLogger_Last)
--- a/js/src/vm/TraceLoggingGraph.cpp
+++ b/js/src/vm/TraceLoggingGraph.cpp
@@ -372,34 +372,40 @@ TraceLoggerGraph::stopEvent(uint64_t tim
             return;
         }
     }
     if (stack.size() == 1) {
         if (!enabled)
             return;
 
         // Forcefully disable logging. We have no stack information anymore.
-        disable(timestamp);
+        logTimestamp(TraceLogger_Disable, timestamp);
         return;
     }
     stack.pop();
 }
 
 void
 TraceLoggerGraph::logTimestamp(uint32_t id, uint64_t timestamp)
 {
+    if (id == TraceLogger_Enable)
+        enabled = true;
+
     if (!enabled)
         return;
 
     if (!events.ensureSpaceBeforeAdd()) {
         fprintf(stderr, "TraceLogging: Disabled a tracelogger due to OOM.\n");
         enabled = 0;
         return;
     }
 
+    if (id == TraceLogger_Disable)
+        disable(timestamp);
+
     EventEntry &entry = events.pushUninitialized();
     entry.time = timestamp;
     entry.textId = id;
 }
 
 bool
 TraceLoggerGraph::getTreeEntry(uint32_t treeId, TreeEntry *entry)
 {
@@ -484,22 +490,16 @@ TraceLoggerGraph::updateStop(uint32_t tr
         return true;
     }
 
     tree[treeId - treeOffset].setStop(timestamp);
     return true;
 }
 
 void
-TraceLoggerGraph::enable()
-{
-    enabled = true;
-}
-
-void
 TraceLoggerGraph::disable(uint64_t timestamp)
 {
     MOZ_ASSERT(enabled);
     while (stack.size() > 1)
         stopEvent(timestamp);
 
     enabled = false;
 }
--- a/js/src/vm/TraceLoggingGraph.h
+++ b/js/src/vm/TraceLoggingGraph.h
@@ -195,20 +195,16 @@ class TraceLoggerGraph
     bool init(uint64_t timestamp);
 
     // Link a textId with a particular text.
     void addTextId(uint32_t id, const char *text);
 
     // Create a tree out of all the given events.
     void log(ContinuousSpace<EventEntry> &events);
 
-    // Disable/enable the logger.
-    void disable(uint64_t timestamp);
-    void enable();
-
   private:
     bool failed;
     bool enabled;
     mozilla::DebugOnly<uint32_t> nextTextId;
 
     FILE *dictFile;
     FILE *treeFile;
     FILE *eventFile;
@@ -246,11 +242,15 @@ class TraceLoggerGraph
     bool flush();
 
     // Stop a tree event.
     void stopEvent(uint32_t id, uint64_t timestamp);
     void stopEvent(uint64_t timestamp);
 
     // Log an (non-tree) event.
     void logTimestamp(uint32_t id, uint64_t timestamp);
+
+    // Disable logging and forcefully report all not yet stopped tree events
+    // as stopped.
+    void disable(uint64_t timestamp);
 };
 
 #endif /* TraceLoggingGraph_h */
--- a/js/src/vm/TraceLoggingTypes.h
+++ b/js/src/vm/TraceLoggingTypes.h
@@ -52,16 +52,18 @@
     _(EdgeCaseAnalysis)                               \
     _(EliminateRedundantChecks)                       \
     _(GenerateLIR)                                    \
     _(RegisterAllocation)                             \
     _(GenerateCode)
 
 #define TRACELOGGER_LOG_ITEMS(_)                      \
     _(Bailout)                                        \
+    _(Disable)                                        \
+    _(Enable)                                         \
     _(Stop)
 
 // Predefined IDs for common operations. These IDs can be used
 // without using TraceLogCreateTextId, because there are already created.
 enum TraceLoggerTextId {
     TraceLogger_Error = 0,
 #define DEFINE_TEXT_ID(textId) TraceLogger_ ## textId,
     TRACELOGGER_TREE_ITEMS(DEFINE_TEXT_ID)