Skip to content

Commit

Permalink
Add logging verbosity level flag to extract_ir.py
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
boomanaiden154 committed Jul 19, 2023
1 parent b476595 commit 2e8454e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
16 changes: 16 additions & 0 deletions compiler_opt/tools/extract_ir.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand All @@ -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')
Expand Down Expand Up @@ -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))

Expand Down
6 changes: 5 additions & 1 deletion compiler_opt/tools/extract_ir_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 2e8454e

Please sign in to comment.