Bug 1322614 - TraceLogging: Don't compare text strings when they are already flushed, r=bbouvier
authorHannes Verschore <hv1989@gmail.com>
Fri, 09 Dec 2016 14:26:59 -1000
changeset 325623 edb24e0ff1e147e44f042f8d0dccf59eac6f6de0
parent 325622 b877875abb3afc917bef6a2a14d39449eaf53ccd
child 325624 c51e7406d7b2e2246a1ece0d8989282ca752039f
push id24
push usermaklebus@msu.edu
push dateTue, 20 Dec 2016 03:11:33 +0000
reviewersbbouvier
bugs1322614
milestone53.0a1
Bug 1322614 - TraceLogging: Don't compare text strings when they are already flushed, r=bbouvier
js/src/vm/TraceLogging.cpp
js/src/vm/TraceLogging.h
--- a/js/src/vm/TraceLogging.cpp
+++ b/js/src/vm/TraceLogging.cpp
@@ -273,23 +273,24 @@ TraceLoggerThread::disable(bool force, c
 
     logTimestamp(TraceLogger_Disable);
     enabled_ = 0;
 
     return true;
 }
 
 const char*
-TraceLoggerThread::eventText(uint32_t id)
+TraceLoggerThread::maybeEventText(uint32_t id)
 {
     if (id < TraceLogger_Last)
         return TLTextIdString(static_cast<TraceLoggerTextId>(id));
 
     TextIdHashMap::Ptr p = textIdPayloads.lookup(id);
-    MOZ_ASSERT(p);
+    if (!p)
+        return nullptr;
 
     return p->value()->string();
 }
 
 bool
 TraceLoggerThread::textIdIsScriptEvent(uint32_t id)
 {
     if (id < TraceLogger_Last)
@@ -565,17 +566,20 @@ TraceLoggerThread::stopEvent(uint32_t id
             // Ignore this.
         } else if (id == TraceLogger_Engine) {
             MOZ_ASSERT(prev == TraceLogger_IonMonkey || prev == TraceLogger_Baseline ||
                        prev == TraceLogger_Interpreter);
         } else if (id == TraceLogger_Scripts) {
             MOZ_ASSERT(prev >= TraceLogger_Last);
         } else if (id >= TraceLogger_Last) {
             MOZ_ASSERT(prev >= TraceLogger_Last);
-            MOZ_ASSERT_IF(prev != id, strcmp(eventText(id), eventText(prev)) == 0);
+            if (prev != id) {
+                // Ignore if the text has been flushed already.
+                MOZ_ASSERT_IF(maybeEventText(prev), strcmp(eventText(id), eventText(prev)) == 0);
+            }
         } else {
             MOZ_ASSERT(id == prev);
         }
     }
 #endif
 
     log(TraceLogger_Stop);
 }
--- a/js/src/vm/TraceLogging.h
+++ b/js/src/vm/TraceLogging.h
@@ -255,17 +255,24 @@ class TraceLoggerThread
         // didn't lose any events when the lastSize equals the maximum size
         // 'events' can get.
         if (lastIteration == iteration_ - 1 && lastSize == events.maxSize())
             return false;
 
         return true;
     }
 
-    const char* eventText(uint32_t id);
+  private:
+    const char* maybeEventText(uint32_t id);
+  public:
+    const char* eventText(uint32_t id) {
+        const char* text = maybeEventText(id);
+        MOZ_ASSERT(text);
+        return text;
+    };
     bool textIdIsScriptEvent(uint32_t id);
 
     // The createTextId functions map a unique input to a logger ID.
     // This can be used to give start and stop events. Calls to these functions should be
     // limited if possible, because of the overhead.
     // Note: it is not allowed to use them in logTimestamp.
     TraceLoggerEventPayload* getOrCreateEventPayload(TraceLoggerTextId textId);
     TraceLoggerEventPayload* getOrCreateEventPayload(const char* text);