Bug 1188888 - Part 2 - Generate readable Telemetry string tables. r=froydnj
authorGeorg Fritzsche <georg.fritzsche@googlemail.com>
Wed, 20 Jul 2016 17:10:24 +0200
changeset 306069 58344005efca56b77c38459955f4099ad9f68f22
parent 306068 6a5f0538b3c907f9a9f5a4851aaae2494e08b165
child 306070 45b83bf04a2617969b8b5664f7dc3f11e118815f
push id79765
push usercbook@mozilla.com
push dateThu, 21 Jul 2016 14:26:34 +0000
treeherdermozilla-inbound@ab54bfc55266 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1188888
milestone50.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 1188888 - Part 2 - Generate readable Telemetry string tables. r=froydnj
toolkit/components/telemetry/shared_telemetry_utils.py
--- a/toolkit/components/telemetry/shared_telemetry_utils.py
+++ b/toolkit/components/telemetry/shared_telemetry_utils.py
@@ -32,40 +32,50 @@ class StringTable:
         else:
             result = self.current_index
             self.table[string] = result
             self.current_index += self.c_strlen(string)
             return result
 
     def writeDefinition(self, f, name):
         """Writes the string table to a file as a C const char array.
+
+        This writes out the string table as one single C char array for memory
+        size reasons, separating the individual strings with '\0' characters.
+        This way we can index directly into the string array and avoid the additional
+        storage costs for the pointers to them (and potential extra relocations for those).
+
         :param f: the output stream.
         :param name: the name of the output array.
         """
         entries = self.table.items()
         entries.sort(key=lambda x:x[1])
+
         # Avoid null-in-string warnings with GCC and potentially
         # overlong string constants; write everything out the long way.
         def explodeToCharArray(string):
             def toCChar(s):
                 if s == "'":
                     return "'\\''"
                 else:
                     return "'%s'" % s
             return ", ".join(map(toCChar, string))
+
         f.write("const char %s[] = {\n" % name)
-        for (string, offset) in entries[:-1]:
+        for (string, offset) in entries:
+            if "*/" in string:
+                raise ValueError, "String in string table contains unexpected sequence '*/': %s" % string
+
             e = explodeToCharArray(string)
             if e:
-                f.write("  /* %5d */ %s, '\\0',\n"
-                        % (offset, explodeToCharArray(string)))
+                f.write("  /* %5d - \"%s\" */ %s, '\\0',\n"
+                        % (offset, string, explodeToCharArray(string)))
             else:
-                f.write("  /* %5d */ '\\0',\n" % offset)
-        f.write("  /* %5d */ %s, '\\0' };\n\n"
-                % (entries[-1][1], explodeToCharArray(entries[-1][0])))
+                f.write("  /* %5d - \"%s\" */ '\\0',\n" % (offset, string))
+        f.write("};\n\n")
 
 def static_assert(output, expression, message):
     """Writes a C++ compile-time assertion expression to a file.
     :param output: the output stream.
     :param expression: the expression to check.
     :param message: the string literal that will appear if the expression evaluates to
         false.
     """