Skip to content

Commit 45a45dd

Browse files
Add logging verbosity level flag to extract_ir.py (#278)
* 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. * Address reviewer feedback - Don't change logging verbosity back to info to print the status message if the verbosity has been set lower. * Address reviewer feedback - Log subprocess output directly rather than having subprocess write directly to STDOUT/STDERR. * Address reviewer feedback - Switch to using subprocess.check_output
1 parent b476595 commit 45a45dd

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

compiler_opt/tools/extract_ir.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@
2828
2929
In a local ThinLTO case, the compilation is assumedto have been performed
3030
specifying -Wl,--save-temps=import -Wl,--thinlto-emit-index-files
31+
32+
To change the logging verbosity, pass an integer representing the desired
33+
verbosity to the --verbosity flag. Use 0 for all logs, status information,
34+
and detailed debug information, -1 for solely warnings, and -2 to not produce
35+
any output.
3136
"""
3237

3338
import json

compiler_opt/tools/extract_ir_lib.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,10 @@ def _extract_clang_artifacts(self, llvm_objcopy_path: str, cmd_filter: str,
135135
return None
136136
os.makedirs(self.dest_dir(), exist_ok=True)
137137
try:
138-
subprocess.run(
138+
subprocess.check_output(
139139
self._get_extraction_cmd_command(llvm_objcopy_path, cmd_section_name),
140-
check=True)
140+
stderr=subprocess.STDOUT,
141+
encoding='utf-8')
141142
if cmd_filter is not None or is_thinlto:
142143
with open(self.cmd_file(), encoding='utf-8') as f:
143144
lines = f.readlines()
@@ -153,13 +154,15 @@ def _extract_clang_artifacts(self, llvm_objcopy_path: str, cmd_filter: str,
153154
index_file = get_thinlto_index(cmdline, self.obj_base_dir())
154155
shutil.copy(index_file, self.thinlto_index_file())
155156

156-
subprocess.run(
157+
subprocess.check_output(
157158
self._get_extraction_bc_command(llvm_objcopy_path,
158159
bitcode_section_name),
159-
check=True)
160+
stderr=subprocess.STDOUT,
161+
encoding='utf-8')
160162
except subprocess.CalledProcessError as e:
161163
# This may happen if .o file was build from asm (.S source).
162164
logging.warning('%s was not processed: %s', self.input_obj(), e)
165+
logging.info(e.output)
163166
return None
164167
assert (os.path.exists(self.cmd_file()) and
165168
os.path.exists(self.bc_file()) and

0 commit comments

Comments
 (0)