From 2e8454e64762e3ef56032fd318721593cb436cf8 Mon Sep 17 00:00:00 2001 From: Aiden Grossman Date: Wed, 19 Jul 2023 02:00:00 +0000 Subject: [PATCH] Add logging verbosity level flag to extract_ir.py This commit adds a logging verbosity level flag to extract_ir.py and the appropriate plumbing/implementation in extract_ir_lib.py. This is primarily motivated by these errors coming up quite often in non-trivial builds (as it is fairly often there is some assembly or some flags don't get passed around somewhere) and not providing a very high signal to noise ratio, especially when used as a library against a bunch of projects at once. --- compiler_opt/tools/extract_ir.py | 16 ++++++++++++++++ compiler_opt/tools/extract_ir_lib.py | 6 +++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/compiler_opt/tools/extract_ir.py b/compiler_opt/tools/extract_ir.py index e55913ab..b9cc342f 100644 --- a/compiler_opt/tools/extract_ir.py +++ b/compiler_opt/tools/extract_ir.py @@ -79,6 +79,12 @@ 'The section name passed to llvm-objcopy. For ELF object files, the ' 'default .llvmbc is correct. For Mach-O object files, one should use ' '__LLVM,__bitcode') +flags.DEFINE_enum( + 'logging_verbosity', 'normal', ['quiet', 'normal', 'verbose'], + 'The logging verbosity to use. Quiet does not log any failures, only ' + 'printing the status at the end. Normal prints failures as they occur. ' + 'Verbose prints failures as they occur along with detailed information ' + 'about the failure.') flags.mark_flag_as_required('output_dir') @@ -89,6 +95,13 @@ def main(argv): if len(argv) > 1: raise app.UsageError('Too many command-line arguments.') + if (FLAGS.logging_verbosity == 'quiet'): + logging.set_verbosity(logging.ERROR) + elif (FLAGS.logging_verbosity == 'normal'): + logging.set_verbosity(logging.WARNING) + elif (FLAGS.logging_verbosity == 'verbose'): + logging.set_verbosity(logging.INFO) + objs = [] if FLAGS.input is not None and FLAGS.thinlto_build == 'local': raise ValueError('--thinlto_build=local cannot be run with --input') @@ -128,6 +141,9 @@ def main(argv): extract_ir_lib.write_corpus_manifest(FLAGS.thinlto_build, relative_output_paths, FLAGS.output_dir) + # Reset logging verbosity so that we print status messages + logging.set_verbosity(logging.INFO) + logging.info('Converted %d files out of %d', len(objs) - relative_output_paths.count(None), len(objs)) diff --git a/compiler_opt/tools/extract_ir_lib.py b/compiler_opt/tools/extract_ir_lib.py index 9be0ad7c..3eeff567 100644 --- a/compiler_opt/tools/extract_ir_lib.py +++ b/compiler_opt/tools/extract_ir_lib.py @@ -135,9 +135,13 @@ def _extract_clang_artifacts(self, llvm_objcopy_path: str, cmd_filter: str, return None os.makedirs(self.dest_dir(), exist_ok=True) try: + subprocess_output = None if logging.get_verbosity( + ) == logging.INFO else subprocess.DEVNULL subprocess.run( self._get_extraction_cmd_command(llvm_objcopy_path, cmd_section_name), - check=True) + check=True, + stdout=subprocess_output, + stderr=subprocess_output) if cmd_filter is not None or is_thinlto: with open(self.cmd_file(), encoding='utf-8') as f: lines = f.readlines()