[llvm] [MLGO] Fix logging verbosity in scripts (PR #107818)
Aiden Grossman via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 9 00:48:50 PDT 2024
https://github.com/boomanaiden154 created https://github.com/llvm/llvm-project/pull/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.
>From 3e0876e9410e55db1233f6d798733fbd06525f57 Mon Sep 17 00:00:00 2001
From: Aiden Grossman <aidengrossman at google.com>
Date: Mon, 9 Sep 2024 07:47:12 +0000
Subject: [PATCH] [MLGO] Fix logging verbosity in scripts
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.
---
.../mlgo/corpus/combine_training_corpus.py | 10 ++++++++++
llvm/utils/mlgo-utils/mlgo/corpus/extract_ir.py | 13 +++++++++++--
2 files changed, 21 insertions(+), 2 deletions(-)
diff --git a/llvm/utils/mlgo-utils/mlgo/corpus/combine_training_corpus.py b/llvm/utils/mlgo-utils/mlgo/corpus/combine_training_corpus.py
index 3b2077b4c0e0e6..85b58d44e01fe0 100644
--- a/llvm/utils/mlgo-utils/mlgo/corpus/combine_training_corpus.py
+++ b/llvm/utils/mlgo-utils/mlgo/corpus/combine_training_corpus.py
@@ -24,6 +24,7 @@
"""
import argparse
+import logging
from mlgo.corpus import combine_training_corpus_lib
@@ -35,11 +36,20 @@ def parse_args_and_run():
parser.add_argument(
"--root_dir", type=str, help="The root dir of module paths to combine."
)
+ parser.add_argument(
+ "--verbosity",
+ type=int,
+ help="The verbosity level to use for logging",
+ default=0,
+ nargs="?",
+ )
args = parser.parse_args()
main(args)
def main(args):
+ logging.basicConfig(level=args.verbosity)
+
combine_training_corpus_lib.combine_corpus(args.root_dir)
diff --git a/llvm/utils/mlgo-utils/mlgo/corpus/extract_ir.py b/llvm/utils/mlgo-utils/mlgo/corpus/extract_ir.py
index a7d52daaedba3b..11f7bca796b22d 100644
--- a/llvm/utils/mlgo-utils/mlgo/corpus/extract_ir.py
+++ b/llvm/utils/mlgo-utils/mlgo/corpus/extract_ir.py
@@ -20,8 +20,8 @@
To change the logging verbosity, pass an integer representing the desired
verbosity to the --verbosity flag. Use 0 for all logs, status information,
-and detailed debug information, -1 for solely warnings, and -2 to not produce
-any output.
+and detailed debug information, 30 for solely warnings, and 50 or higher to
+not produce any output.
"""
import argparse
@@ -113,11 +113,20 @@ def parse_args_and_run():
default=".llvmbc",
nargs="?",
)
+ parser.add_argument(
+ "--verbosity",
+ type=int,
+ help="The verbosity level to use for logging",
+ default=0,
+ nargs="?",
+ )
args = parser.parse_args()
main(args)
def main(args):
+ logging.basicConfig(level=args.verbosity)
+
objs = []
if args.input is not None and args.thinlto_build == "local":
raise ValueError("--thinlto_build=local cannot be run with --input")
More information about the llvm-commits
mailing list