Bug 1072903 - TraceLogger: Part 1: Remove static array and use function to retrieve the tracelogger text descriptions, r=bbouvier
authorHannes Verschore <hv1989@gmail.com>
Thu, 20 Nov 2014 17:43:59 +0100
changeset 247490 16aa61577e9536dcd1c328e43c22743840c9f921
parent 247489 648947a5a4452d154ced5b535513dfdbd4310aff
child 247491 37770c7a3f0ffe52968c2011a29ebf2611b5fa25
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 1: Remove static array and use function to retrieve the tracelogger text descriptions, r=bbouvier
js/src/vm/TraceLogging.cpp
--- a/js/src/vm/TraceLogging.cpp
+++ b/js/src/vm/TraceLogging.cpp
@@ -74,23 +74,29 @@ rdtsc(void)
     result = result|lower;
 
     return result;
 }
 #endif
 
 TraceLogging traceLoggers;
 
-static const char* const text[] =
+static const char *
+TLTextIdString(TraceLogger::TextId id)
 {
-    "TraceLogger failed to process text",
-#define NAME(x) #x,
-    TRACELOGGER_TEXT_ID_LIST(NAME)
+    switch (id) {
+      case TraceLogger::TL_Error:
+        return "TraceLogger failed to process text";
+#define NAME(textId) case TraceLogger::textId: return #textId;
+        TRACELOGGER_TEXT_ID_LIST(NAME)
 #undef NAME
-};
+      default:
+        MOZ_CRASH();
+    }
+}
 
 TraceLogger::TraceLogger()
  : enabled(0),
    failed(false),
    nextTextId(0),
    treeOffset(0),
    top(nullptr)
 { }
@@ -150,17 +156,18 @@ TraceLogger::init(uint32_t loggerId)
     stackEntry.setActive(true);
 
     int written = fprintf(dictFile, "[");
     if (written < 0)
         fprintf(stderr, "TraceLogging: Error while writing.\n");
 
     // Eagerly create the default textIds, to match their Tracelogger::TextId.
     for (uint32_t i = 0; i < LAST; i++) {
-        mozilla::DebugOnly<uint32_t> textId = createTextId(text[i]);
+        TraceLogger::TextId id = TraceLogger::TextId(i);
+        mozilla::DebugOnly<uint32_t> textId = createTextId(TLTextIdString(id));
         MOZ_ASSERT(textId == i);
     }
 
     enabled = 1;
     return true;
 }
 
 bool
@@ -798,28 +805,30 @@ TraceLogging::lazyInit()
             "\n"
             "Collections:\n"
             "  Default        Output all default\n"
             "  IonCompiler    Output all information about compilation\n"
             "\n"
             "Specific log items:\n"
         );
         for (uint32_t i = 1; i < TraceLogger::LAST; i++) {
-            if (!TraceLogger::textIdIsToggable(i))
+            TraceLogger::TextId id = TraceLogger::TextId(i);
+            if (!TraceLogger::textIdIsToggable(id))
                 continue;
-            printf("  %s\n", text[i]);
+            printf("  %s\n", TLTextIdString(id));
         }
         printf("\n");
         exit(0);
         /*NOTREACHED*/
     }
 
     for (uint32_t i = 1; i < TraceLogger::LAST; i++) {
-        if (TraceLogger::textIdIsToggable(i))
-            enabledTextIds[i] = ContainsFlag(env, text[i]);
+        TraceLogger::TextId id = TraceLogger::TextId(i);
+        if (TraceLogger::textIdIsToggable(id))
+            enabledTextIds[i] = ContainsFlag(env, TLTextIdString(id));
         else
             enabledTextIds[i] = true;
     }
 
     if (ContainsFlag(env, "Default")) {
         enabledTextIds[TraceLogger::Bailout] = true;
         enabledTextIds[TraceLogger::Baseline] = true;
         enabledTextIds[TraceLogger::BaselineCompilation] = true;