OSDN Git Service

Revert r312719 "[MachineCombiner] Update instruction depths incrementally for large...
[android-x86/external-llvm.git] / utils / prepare-code-coverage-artifact.py
index 293323a..883cdd7 100644 (file)
@@ -1,9 +1,14 @@
 #!/usr/bin/env python
 
+from __future__ import print_function
+
 '''Prepare a code coverage artifact.
 
 - Collate raw profiles into one indexed profile.
 - Generate html reports for the given binaries.
+
+Caution: The positional arguments to this script must be specified before any 
+optional arguments, such as --restrict.
 '''
 
 import argparse
@@ -13,7 +18,7 @@ import subprocess
 import sys
 
 def merge_raw_profiles(host_llvm_profdata, profile_data_dir, preserve_profiles):
-    print ':: Merging raw profiles...',
+    print(':: Merging raw profiles...', end='')
     sys.stdout.flush()
     raw_profiles = glob.glob(os.path.join(profile_data_dir, '*.profraw'))
     manifest_path = os.path.join(profile_data_dir, 'profiles.manifest')
@@ -26,29 +31,40 @@ def merge_raw_profiles(host_llvm_profdata, profile_data_dir, preserve_profiles):
         for raw_profile in raw_profiles:
             os.remove(raw_profile)
     os.remove(manifest_path)
-    print 'Done!'
+    print('Done!')
     return profdata_path
 
-def prepare_html_report(host_llvm_cov, profile, report_dir, binary,
+def prepare_html_report(host_llvm_cov, profile, report_dir, binaries,
                         restricted_dirs):
-    print ':: Preparing html report for {0}...'.format(binary),
+    print(':: Preparing html report for {0}...'.format(binaries), end='')
     sys.stdout.flush()
-    binary_report_dir = os.path.join(report_dir, os.path.basename(binary))
-    invocation = [host_llvm_cov, 'show', binary, '-format', 'html',
-                  '-instr-profile', profile, '-o', binary_report_dir,
+    objects = []
+    for i, binary in enumerate(binaries):
+        if i == 0:
+            objects.append(binary)
+        else:
+            objects.extend(('-object', binary))
+    invocation = [host_llvm_cov, 'show'] + objects + ['-format', 'html',
+                  '-instr-profile', profile, '-o', report_dir,
                   '-show-line-counts-or-regions', '-Xdemangler', 'c++filt',
                   '-Xdemangler', '-n'] + restricted_dirs
     subprocess.check_call(invocation)
-    with open(os.path.join(binary_report_dir, 'summary.txt'), 'wb') as Summary:
-        subprocess.check_call([host_llvm_cov, 'report', binary,
-                               '-instr-profile', profile], stdout=Summary)
-    print 'Done!'
+    with open(os.path.join(report_dir, 'summary.txt'), 'wb') as Summary:
+        subprocess.check_call([host_llvm_cov, 'report'] + objects +
+                               ['-instr-profile', profile], stdout=Summary)
+    print('Done!')
 
 def prepare_html_reports(host_llvm_cov, profdata_path, report_dir, binaries,
-                         restricted_dirs):
-    for binary in binaries:
-        prepare_html_report(host_llvm_cov, profdata_path, report_dir, binary,
+                         unified_report, restricted_dirs):
+    if unified_report:
+        prepare_html_report(host_llvm_cov, profdata_path, report_dir, binaries,
                             restricted_dirs)
+    else:
+        for binary in binaries:
+            binary_report_dir = os.path.join(report_dir,
+                                             os.path.basename(binary))
+            prepare_html_report(host_llvm_cov, profdata_path, binary_report_dir,
+                                [binary], restricted_dirs)
 
 if __name__ == '__main__':
     parser = argparse.ArgumentParser(description=__doc__)
@@ -67,13 +83,16 @@ if __name__ == '__main__':
                        help='Do not delete raw profiles', action='store_true')
     parser.add_argument('--use-existing-profdata',
                        help='Specify an existing indexed profile to use')
+    parser.add_argument('--unified-report', action='store_true',
+                       help='Emit a unified report for all binaries')
     parser.add_argument('--restrict', metavar='R', type=str, nargs='*',
                        default=[],
-                       help='Restrict the reporting to the given source paths')
+                       help='Restrict the reporting to the given source paths'
+                   ' (must be specified after all other positional arguments)')
     args = parser.parse_args()
 
     if args.use_existing_profdata and args.only_merge:
-        print '--use-existing-profdata and --only-merge are incompatible'
+        print('--use-existing-profdata and --only-merge are incompatible')
         exit(1)
 
     if args.use_existing_profdata:
@@ -83,6 +102,10 @@ if __name__ == '__main__':
                                            args.profile_data_dir,
                                            args.preserve_profiles)
 
+    if not len(args.binaries):
+        print('No binaries specified, no work to do!')
+        exit(1)
+
     if not args.only_merge:
         prepare_html_reports(args.host_llvm_cov, profdata_path, args.report_dir,
-                            args.binaries, args.restrict)
+                            args.binaries, args.unified_report, args.restrict)