Bug 1498164 - Generate stores for histograms r=chutten
authorJan-Erik Rediger <jrediger@mozilla.com>
Wed, 07 Nov 2018 12:35:30 +0000
changeset 501275 4407a6d3e3742173cb60c95981fa27e369a39c1f
parent 501274 b7563042430d6bb11b3f08f89d4fe57de5a10908
child 501286 d87537833fcfd8d18f4d1c2782631c79c161a281
child 501287 6343e6061b9e14085b5cb3fa1851348ea042773e
push id10290
push userffxbld-merge
push dateMon, 03 Dec 2018 16:23:23 +0000
treeherdermozilla-beta@700bed2445e6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerschutten
bugs1498164
milestone65.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 1498164 - Generate stores for histograms r=chutten This generates several new things: * store_count and store_offset in the HistogramInfo struct. store_count indicates the number of stores the histogram is registered in. store_offset is an offset into the gHistogramStoresTable array. If store_count == 1 && store_offset == UINT16_MAX, then the histogram is only in the main store. * gHistogramStoresTable: An array containing the actual offsets into gHistogramStringTable to get a store's name Depends on D10921 Differential Revision: https://phabricator.services.mozilla.com/D10922
toolkit/components/telemetry/Histograms.json
toolkit/components/telemetry/build_scripts/gen_histogram_data.py
toolkit/components/telemetry/core/TelemetryHistogram.cpp
--- a/toolkit/components/telemetry/Histograms.json
+++ b/toolkit/components/telemetry/Histograms.json
@@ -7728,16 +7728,52 @@
     "kind": "linear",
     "low": 1,
     "high": 10000,
     "n_buckets": 10,
     "bug_numbers": [1477213],
     "description": "a testing histogram; not meant to be touched",
     "operating_systems": ["mac"]
   },
+  "TELEMETRY_TEST_MAIN_ONLY": {
+    "record_in_processes": ["main"],
+    "alert_emails": ["telemetry-client-dev@mozilla.com"],
+    "expires_in_version": "never",
+    "kind": "linear",
+    "low": 1,
+    "high": 2147483646,
+    "n_buckets": 10,
+    "bug_numbers": [1498164],
+    "description": "a testing histogram; not meant to be touched",
+    "record_into_store": ["main"]
+  },
+  "TELEMETRY_TEST_SYNC_ONLY": {
+    "record_in_processes": ["main"],
+    "alert_emails": ["telemetry-client-dev@mozilla.com"],
+    "expires_in_version": "never",
+    "kind": "linear",
+    "low": 1,
+    "high": 2147483646,
+    "n_buckets": 10,
+    "bug_numbers": [1498164],
+    "description": "a testing histogram; not meant to be touched",
+    "record_into_store": ["sync"]
+  },
+  "TELEMETRY_TEST_MULTIPLE_STORES": {
+    "record_in_processes": ["main"],
+    "alert_emails": ["telemetry-client-dev@mozilla.com"],
+    "expires_in_version": "never",
+    "kind": "linear",
+    "low": 1,
+    "high": 2147483646,
+    "n_buckets": 10,
+    "bug_numbers": [1498164],
+    "description": "a testing histogram; not meant to be touched",
+    "record_into_store": ["main", "sync"]
+  },
   "STARTUP_CRASH_DETECTED": {
     "record_in_processes": ["main", "content"],
     "expires_in_version": "never",
     "kind": "flag",
     "description": "Whether there was a crash during the last startup"
   },
   "SAFE_MODE_USAGE": {
     "record_in_processes": ["main", "content"],
--- a/toolkit/components/telemetry/build_scripts/gen_histogram_data.py
+++ b/toolkit/components/telemetry/build_scripts/gen_histogram_data.py
@@ -15,42 +15,49 @@ from mozparsers import parse_histograms
 
 import sys
 import buildconfig
 
 banner = """/* This file is auto-generated, see gen_histogram_data.py.  */
 """
 
 
-def print_array_entry(output, histogram, name_index, exp_index, label_index,
-                      label_count, key_index, key_count):
+def print_array_entry(output, histogram, name_index, exp_index,
+                      label_index, label_count,
+                      key_index, key_count,
+                      store_index, store_count):
     if histogram.record_on_os(buildconfig.substs["OS_TARGET"]):
-        print("  { %d, %d, %d, %d, %d, %d, %d, %d, %d, %s, %s, %s, %s, %s },"
+        print("  { %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %s, %s, %s, %s, %s, %s },"
               % (histogram.low(),
                  histogram.high(),
                  histogram.n_buckets(),
                  name_index,
                  exp_index,
                  label_count,
                  key_count,
+                 store_count,
                  label_index,
                  key_index,
+                 store_index,
                  "true" if histogram.keyed() else "false",
                  histogram.nsITelemetry_kind(),
                  histogram.dataset(),
                  " | ".join(histogram.record_in_processes_enum()),
                  " | ".join(histogram.products_enum())), file=output)
 
 
 def write_histogram_table(output, histograms):
     string_table = StringTable()
+
     label_table = []
     label_count = 0
     keys_table = []
     keys_count = 0
+    store_table = []
+    total_store_count = 0
 
     print("constexpr HistogramInfo gHistogramInfos[] = {", file=output)
     for histogram in histograms:
         name_index = string_table.stringIndex(histogram.name())
         exp_index = string_table.stringIndex(histogram.expiration())
 
         labels = histogram.labels()
         label_index = 0
@@ -61,18 +68,29 @@ def write_histogram_table(output, histog
 
         keys = histogram.keys()
         key_index = 0
         if len(keys) > 0:
             key_index = keys_count
             keys_table.append((histogram.name(), string_table.stringIndexes(keys)))
             keys_count += len(keys)
 
+        stores = histogram.record_into_store()
+        store_index = 0
+        if stores == ["main"]:
+            # if count == 1 && offset == UINT16_MAX -> only main store
+            store_index = 'UINT16_MAX'
+        else:
+            store_index = total_store_count
+            store_table.append((histogram.name(), string_table.stringIndexes(stores)))
+            total_store_count += len(stores)
+
         print_array_entry(output, histogram, name_index, exp_index,
-                          label_index, len(labels), key_index, len(keys))
+                          label_index, len(labels), key_index, len(keys),
+                          store_index, len(stores))
     print("};\n", file=output)
 
     strtab_name = "gHistogramStringTable"
     string_table.writeDefinition(output, strtab_name)
     static_assert(output, "sizeof(%s) <= UINT32_MAX" % strtab_name,
                   "index overflow")
 
     print("\n#if defined(_MSC_VER) && !defined(__clang__)", file=output)
@@ -90,16 +108,28 @@ def write_histogram_table(output, histog
     print("#else", file=output)
     print("constexpr uint32_t gHistogramKeyTable[] = {", file=output)
     print("#endif", file=output)
     for name, indexes in keys_table:
         print("/* %s */ %s," % (name, ", ".join(map(str, indexes))), file=output)
     print("};", file=output)
     static_assert(output, "sizeof(gHistogramKeyTable) <= UINT16_MAX", "index overflow")
 
+    store_table_name = "gHistogramStoresTable"
+    print("\n#if defined(_MSC_VER) && !defined(__clang__)", file=output)
+    print("const uint32_t {}[] = {{".format(store_table_name), file=output)
+    print("#else", file=output)
+    print("constexpr uint32_t {}[] = {{".format(store_table_name), file=output)
+    print("#endif", file=output)
+    for name, indexes in store_table:
+        print("/* %s */ %s," % (name, ", ".join(map(str, indexes))), file=output)
+    print("};", file=output)
+    static_assert(output, "sizeof(%s) <= UINT16_MAX" % store_table_name,
+                  "index overflow")
+
 
 # Write out static asserts for histogram data.  We'd prefer to perform
 # these checks in this script itself, but since several histograms
 # (generally enumerated histograms) use compile-time constants for
 # their upper bounds, we have to let the compiler do the checking.
 
 def static_asserts_for_boolean(output, histogram):
     pass
--- a/toolkit/components/telemetry/core/TelemetryHistogram.cpp
+++ b/toolkit/components/telemetry/core/TelemetryHistogram.cpp
@@ -135,18 +135,20 @@ typedef nsDataHashtable<nsCStringHashKey
 struct HistogramInfo {
   uint32_t min;
   uint32_t max;
   uint32_t bucketCount;
   uint32_t name_offset;
   uint32_t expiration_offset;
   uint32_t label_count;
   uint32_t key_count;
+  uint32_t store_count;
   uint16_t label_index;
   uint16_t key_index;
+  uint16_t store_index;
   bool keyed;
   uint8_t histogramType;
   uint8_t dataset;
   RecordedProcessType record_in_processes;
   SupportedProduct products;
 
   const char *name() const;
   const char *expiration() const;