Bug 1507344 - Add configure machinery for MOZ_PROFILE_USE and merging profile. r=nalexander
authorChris Manchester <cmanchester@mozilla.com>
Fri, 21 Dec 2018 19:02:11 +0000
changeset 512447 3b1c7ad601ba81805e5de271f91c6892e42c2091
parent 512446 8ad51093f3f0d76ec3aeed125a112103c3f074ca
child 512448 df23b1fa16f500545bb1c319b078788f842a94fa
push id1953
push userffxbld-merge
push dateMon, 11 Mar 2019 12:10:20 +0000
treeherdermozilla-release@9c35dcbaa899 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnalexander
bugs1507344
milestone66.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 1507344 - Add configure machinery for MOZ_PROFILE_USE and merging profile. r=nalexander Differential Revision: https://phabricator.services.mozilla.com/D13863
build/merge_profdata.py
build/moz.configure/toolchain.configure
moz.build
python/mozbuild/mozbuild/frontend/data.py
new file mode 100644
--- /dev/null
+++ b/build/merge_profdata.py
@@ -0,0 +1,11 @@
+# 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/.
+
+import subprocess
+import buildconfig
+
+
+def main(_, profile_file):
+    subprocess.check_call([buildconfig.substs['LLVM_PROFDATA'], 'merge',
+                           '-o', 'merged.profdata', profile_file])
--- a/build/moz.configure/toolchain.configure
+++ b/build/moz.configure/toolchain.configure
@@ -14,35 +14,66 @@ js_option('--enable-release',
 
 
 @depends('--enable-release')
 def developer_options(value):
     if not value:
         return True
 
 
+llvm_profdata = check_prog('LLVM_PROFDATA', ['llvm-profdata'],
+                           allow_missing=True)
+
+add_old_configure_assignment('LLVM_PROFDATA', llvm_profdata)
+
+
 add_old_configure_assignment('DEVELOPER_OPTIONS', developer_options)
 set_config('DEVELOPER_OPTIONS', developer_options)
 
 # PGO
 # ==============================================================
 js_option('--enable-profile-generate',
           help='Build a PGO instrumented binary')
 
 imply_option('MOZ_PGO',
              depends_if('--enable-profile-generate')(lambda _: True))
 
 set_config('MOZ_PROFILE_GENERATE',
            depends_if('--enable-profile-generate')(lambda _: True))
 
+js_option('--enable-profile-use',
+          help='Use a generated profile during the build')
+
+js_option('--with-pgo-profile-path',
+          help='Path to the (unmerged) profile path to use during the build',
+          nargs=1)
+
+imply_option('MOZ_PGO',
+             depends_if('--enable-profile-use')(lambda _: True))
+
+set_config('MOZ_PROFILE_USE',
+           depends_if('--enable-profile-use')(lambda _: True))
+
 js_option(env='MOZ_PGO', help='Build with profile guided optimizations')
 
 set_config('MOZ_PGO', depends('MOZ_PGO')(lambda x: bool(x)))
 add_old_configure_assignment('MOZ_PGO', depends('MOZ_PGO')(lambda x: bool(x)))
 
+@depends('--with-pgo-profile-path', '--enable-profile-use', 'LLVM_PROFDATA')
+def pgo_profile_path(path, pgo_use, profdata):
+    if not path:
+        return
+    if path and not pgo_use:
+        die('Pass --enable-profile-use to use --with-pgo-profile-path.')
+    if path and not profdata:
+        die('LLVM_PROFDATA must be set to process the pgo profile.')
+    return path[0]
+
+set_config('PGO_PROFILE_PATH', pgo_profile_path)
+
 # Code optimization
 # ==============================================================
 
 js_option('--disable-optimize',
           nargs='?',
           help='Disable optimizations via compiler flags')
 
 
@@ -1468,21 +1499,16 @@ def pgo_flags(compiler, build_env, targe
         )
 
 
 set_config('PROFILE_GEN_CFLAGS', pgo_flags.gen_cflags)
 set_config('PROFILE_GEN_LDFLAGS', pgo_flags.gen_ldflags)
 set_config('PROFILE_USE_CFLAGS', pgo_flags.use_cflags)
 set_config('PROFILE_USE_LDFLAGS', pgo_flags.use_ldflags)
 
-llvm_profdata = check_prog('LLVM_PROFDATA', ['llvm-profdata'],
-                           allow_missing=True)
-
-add_old_configure_assignment('LLVM_PROFDATA', llvm_profdata)
-
 
 @depends(c_compiler)
 def preprocess_option(compiler):
     # The uses of PREPROCESS_OPTION depend on the spacing for -o/-Fi.
     if compiler.type in ('gcc', 'clang'):
         return '-E -o '
     else:
         return '-P -Fi'
--- a/moz.build
+++ b/moz.build
@@ -112,16 +112,26 @@ if not CONFIG['JS_STANDALONE'] or not CO
 
     GENERATED_FILES['buildid.h'].script = 'build/variables.py:buildid_header'
     GENERATED_FILES['source-repo.h'].script = 'build/variables.py:source_repo_header'
 
     DIRS += [
         'build',
     ]
 
+if CONFIG['PGO_PROFILE_PATH']:
+    profdata_gen = ('merged.profdata.stub', 'merged.profdata')
+    GENERATED_FILES += [
+        profdata_gen
+    ]
+    GENERATED_FILES[profdata_gen].script = 'build/merge_profdata.py'
+    GENERATED_FILES[profdata_gen].inputs = [
+        CONFIG['PGO_PROFILE_PATH'],
+    ]
+
 DIRS += [
     'mfbt',
 ]
 
 if CONFIG['MOZ_BUILD_APP']:
     # Bring in the configuration for the configured application.
     include('/' + CONFIG['MOZ_BUILD_APP'] + '/app.mozbuild')
 else:
--- a/python/mozbuild/mozbuild/frontend/data.py
+++ b/python/mozbuild/mozbuild/frontend/data.py
@@ -1169,16 +1169,17 @@ class GeneratedFile(ContextDerived):
             '.c',
             '.cpp',
             '.h',
             '.inc',
             '.py',
             '.rs',
             'node.stub', # To avoid VPATH issues with installing node files: https://bugzilla.mozilla.org/show_bug.cgi?id=1461714#c55
             'android_apks', # We need to compile Java to generate JNI wrappers for native code compilation to consume.
+            '.profdata',
         )
         self.required_for_compile = [f for f in self.outputs if f.endswith(suffixes) or 'stl_wrappers/' in f]
 
 
 class ChromeManifestEntry(ContextDerived):
     """Represents a chrome.manifest entry."""
 
     __slots__ = (