Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve logging #335

Merged
merged 4 commits into from
Apr 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions src/omniperf_profile/profiler_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,10 @@ def join_prof(self, out=None):
msg = "Detected differing {} values while joining pmc_perf.csv".format(
key
)
console_warning(msg + "\n")
console_warning(msg)
else:
msg = "Successfully joined {} in pmc_perf.csv".format(key)
console_debug(msg + "\n")
if test_df_column_equality(_df) and self.__args.verbose:
console_log("profiling", msg)
console_debug(msg)

# now, we can:
#   A) throw away any of the "boring" duplicates
Expand Down
31 changes: 18 additions & 13 deletions src/utils/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@
# Define the colors
BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE = range(8)
RESET_SEQ = "\033[0m"
COLOR_SEQ = "\033[1;%dm"
COLOR_SEQ = "\033[%dm"

COLORS = {
"WARNING": YELLOW,
"INFO": GREEN,
"INFO": WHITE,
"DEBUG": BLUE,
"CRITICAL": YELLOW,
"CRITICAL": RED,
"ERROR": RED,
"TRACE": MAGENTA,
}
Expand All @@ -47,9 +47,12 @@ class ColoredFormatter(logging.Formatter):
def format(self, record):
levelname = record.levelname
if levelname in COLORS:
levelname_color = COLOR_SEQ % (30 + COLORS[levelname]) + levelname + RESET_SEQ
record.levelname = levelname_color
return logging.Formatter.format(self, record)
if levelname == "WARNING" or levelname == "ERROR" or levelname == "DEBUG":
log_fmt = f"{COLOR_SEQ % (30 + COLORS[levelname])}%(levelname)s: %(message)s{RESET_SEQ}"
else:
log_fmt = f"{COLOR_SEQ % (30 + COLORS[levelname])}%(message)s{RESET_SEQ}"
formatter = logging.Formatter(log_fmt)
return formatter.format(record)


class PlainFormatter(logging.Formatter):
Expand All @@ -70,17 +73,19 @@ def setup_console_handler():
setattr(logging, "TRACE", logging.TRACE)
setattr(logging, "trace", trace_logger)

# setup log formatting
color_setting = 0
color_setting = 1
if "OMNIPERF_COLOR" in os.environ.keys():
if type(os.environ["OMNIPERF_COLOR"]) != int:
raise TypeError(
"OMNIPERF_COLOR must be of type int. Detected: {}".format(
type(os.environ["OMNIPERF_COLOR"])
)
)
color_setting = int(os.environ["OMNIPERF_COLOR"])

if color_setting == 1:
# colored levelname
formatter = ColoredFormatter("%(levelname)16s %(message)s")
elif color_setting == 2:
# non-colored levelname
formatter = logging.Formatter("%(levelname)5s %(message)s")
# colored loglevel and message
formatter = ColoredFormatter()
else:
# non-colored
formatter = PlainFormatter()
Expand Down
8 changes: 6 additions & 2 deletions src/utils/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -928,7 +928,9 @@ def load_kernel_top(workload, dir):
if file.exists():
tmp[id] = pd.read_csv(file)
else:
console_warning("Issue loading top kernels. Check pmc_kernel_top.csv")
console_warning(
f"Couldn't load {file.name}. This may result in missing analysis data."
)
# NB: Special case for sysinfo. Probably room for improvement in this whole function design
elif "from_csv_columnwise" in df.columns and id == 101:
tmp[id] = workload.sys_info.transpose()
Expand All @@ -946,7 +948,9 @@ def load_kernel_top(workload, dir):
# so tty could detect them and show them correctly in comparison.
tmp[id].columns = ["Info"]
else:
console_warning("Issue loading top kernels. Check pmc_kernel_top.csv")
console_warning(
f"Couldn't load {file.name}. This may result in missing analysis data."
)
workload.dfs.update(tmp)


Expand Down
Loading