Bug 1448945 - Generate JSON definitions for dynamic builtin events. r=chutten,froydnj
authorJan-Erik Rediger <jrediger@mozilla.com>
Mon, 09 Apr 2018 15:07:14 +0200
changeset 414285 d7199d45cfd921f22049185555b84cafd9d2761b
parent 414284 4badb094b348d6939e946983e68fecf7f43b9e9a
child 414286 441de7a08d1cc193118c8a3804769ba861369c03
push id33865
push userbtara@mozilla.com
push dateWed, 18 Apr 2018 22:35:14 +0000
treeherdermozilla-central@e4c4c8159924 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerschutten, froydnj
bugs1448945
milestone61.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 1448945 - Generate JSON definitions for dynamic builtin events. r=chutten,froydnj This patch enables the build system to generate the JSON definition file that is loaded, on developer builds, when Firefox starts and is built from artifact builds. MozReview-Commit-ID: 1nSQi7exRtL
toolkit/components/telemetry/gen_event_data.py
toolkit/components/telemetry/moz.build
--- a/toolkit/components/telemetry/gen_event_data.py
+++ b/toolkit/components/telemetry/gen_event_data.py
@@ -1,18 +1,20 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 # Write out event information for C++. The events are defined
 # in a file provided as a command-line argument.
 
 from __future__ import print_function
+from collections import OrderedDict
 from shared_telemetry_utils import StringTable, static_assert, ParserError
 
+import json
 import parse_events
 import sys
 import itertools
 
 # The banner/text at the top of the generated file.
 banner = """/* This file is auto-generated, only for internal use in TelemetryEvent.h,
    see gen_event_data.py. */
 """
@@ -104,16 +106,52 @@ def write_event_table(events, output, st
                    string_table.stringIndex(object_name)),
                   file=output)
 
     print("};", file=output)
     static_assert(output, "sizeof(%s) <= UINT32_MAX" % table_name,
                   "index overflow")
 
 
+def generate_JSON_definitions(output, *filenames):
+    """ Write the event definitions to a JSON file.
+
+    :param output: the file to write the content to.
+    :param filenames: a list of filenames provided by the build system.
+           We only support a single file.
+    """
+    # Load the event data.
+    if len(filenames) > 1:
+        raise Exception('We don\'t support loading from more than one file.')
+    try:
+        events = parse_events.load_events(filenames[0], True)
+    except ParserError as ex:
+        print("\nError processing events:\n" + str(ex) + "\n")
+        sys.exit(1)
+
+    event_definitions = OrderedDict()
+    for event in events:
+        category = event.category
+
+        if category not in event_definitions:
+            event_definitions[category] = OrderedDict()
+
+        event_definitions[category][event.name] = OrderedDict({
+            'methods': event.methods,
+            'objects': event.objects,
+            'extra_keys': event.extra_keys,
+            'record_on_release': True if event.dataset == 'opt-out' else False,
+            # We don't expire dynamic-builtin scalars: they're only meant for
+            # use in local developer builds anyway. They will expire when rebuilding.
+            'expired': False,
+        })
+
+    json.dump(event_definitions, output)
+
+
 def main(output, *filenames):
     # Load the event data.
     if len(filenames) > 1:
         raise Exception('We don\'t support loading from more than one file.')
     try:
         events = parse_events.load_events(filenames[0], True)
     except ParserError as ex:
         print("\nError processing events:\n" + str(ex) + "\n")
--- a/toolkit/components/telemetry/moz.build
+++ b/toolkit/components/telemetry/moz.build
@@ -104,16 +104,17 @@ TESTING_JS_MODULES += [
   'tests/unit/TelemetryArchiveTesting.jsm',
 ]
 
 PYTHON_UNITTEST_MANIFESTS += [
     'tests/python/python.ini',
 ]
 
 GENERATED_FILES = [
+    'EventArtifactDefinitions.json',
     'ScalarArtifactDefinitions.json',
     'TelemetryEventData.h',
     'TelemetryEventEnums.h',
     'TelemetryHistogramData.inc',
     'TelemetryHistogramEnums.h',
     'TelemetryProcessData.h',
     'TelemetryProcessEnums.h',
     'TelemetryScalarData.h',
@@ -165,16 +166,25 @@ event_files = [
 event_data = GENERATED_FILES['TelemetryEventData.h']
 event_data.script = 'gen_event_data.py'
 event_data.inputs = event_files
 
 event_enums = GENERATED_FILES['TelemetryEventEnums.h']
 event_enums.script = 'gen_event_enum.py'
 event_enums.inputs = event_files
 
+# Generate the JSON event definitions. They will only be
+# used in artifact or "build faster" builds.
+event_json_data = GENERATED_FILES['EventArtifactDefinitions.json']
+event_json_data.script = 'gen_event_data.py:generate_JSON_definitions'
+event_json_data.inputs = event_files
+
+# Move the events JSON file to the directory where the Firefox binary is.
+FINAL_TARGET_FILES += ['!EventArtifactDefinitions.json']
+
 # Generate data from Processes.yaml
 processes_files = [
     'Processes.yaml',
 ]
 
 processes_enum = GENERATED_FILES['TelemetryProcessEnums.h']
 processes_enum.script = 'gen_process_enum.py'
 processes_enum.inputs = processes_files