Skip to content

Commit 99ea357

Browse files
[MLGO] Fix logging verbosity in scripts (#107818)
This patch fixes issues related to logging verbosity in the MLGO python scripts. This was an oversight when converting from absl.logging to the python logging API as absl natively supports a --verbosity flag to set the desired logging level. This patch adds a flag to support similar functionality in Python's logging library and additionally updates docstrings where relevant to point to the new values.
1 parent a7c26aa commit 99ea357

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

llvm/utils/mlgo-utils/mlgo/corpus/combine_training_corpus.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"""
2525

2626
import argparse
27+
import logging
2728

2829
from mlgo.corpus import combine_training_corpus_lib
2930

@@ -35,11 +36,22 @@ def parse_args_and_run():
3536
parser.add_argument(
3637
"--root_dir", type=str, help="The root dir of module paths to combine."
3738
)
39+
# TODO(#107898): Refactor this into a common location.
40+
parser.add_argument(
41+
"--verbosity",
42+
type=str,
43+
help="The verbosity level to use for logging",
44+
default="INFO",
45+
nargs="?",
46+
choices=["DEBUG", "INFO", "WARNING", "ERROR"],
47+
)
3848
args = parser.parse_args()
3949
main(args)
4050

4151

4252
def main(args):
53+
logging.basicConfig(level=args.verbosity)
54+
4355
combine_training_corpus_lib.combine_corpus(args.root_dir)
4456

4557

llvm/utils/mlgo-utils/mlgo/corpus/extract_ir.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,9 @@
1818
In a local ThinLTO case, the compilation is assumedto have been performed
1919
specifying -Wl,--save-temps=import -Wl,--thinlto-emit-index-files
2020
21-
To change the logging verbosity, pass an integer representing the desired
22-
verbosity to the --verbosity flag. Use 0 for all logs, status information,
23-
and detailed debug information, -1 for solely warnings, and -2 to not produce
24-
any output.
21+
To change the logging verbosity, set the --verbosity flag to the desired level.
22+
Setting it to a specific level will enable all messages at that level and
23+
higher. Exact values can be found by invoking the script with --help.
2524
"""
2625

2726
import argparse
@@ -112,11 +111,22 @@ def parse_args_and_run():
112111
default=".llvmbc",
113112
nargs="?",
114113
)
114+
# TODO(#107898): Refactor this into a common location.
115+
parser.add_argument(
116+
"--verbosity",
117+
type=str,
118+
help="The verbosity level to use for logging",
119+
default="INFO",
120+
nargs="?",
121+
choices=["DEBUG", "INFO", "WARNING", "ERROR"],
122+
)
115123
args = parser.parse_args()
116124
main(args)
117125

118126

119127
def main(args):
128+
logging.basicConfig(level=args.verbosity)
129+
120130
objs = []
121131
if args.input is not None and args.thinlto_build == "local":
122132
raise ValueError("--thinlto_build=local cannot be run with --input")

0 commit comments

Comments
 (0)