[Comgr] Create a Global Logger Class for Comgr#3116
Conversation
MixedMatched
left a comment
There was a problem hiding this comment.
Just a few things. Overall great work!
|
Nit: Title should be updated with prefix |
| static const char *LogLevel = getenv("AMD_COMGR_LOG_LEVEL"); | ||
| return LogLevel ? StringRef(LogLevel) : StringRef(); |
There was a problem hiding this comment.
We probably want to be case-insensitive here ?
There was a problem hiding this comment.
Also, whats the rationale behind using strings over numbers to denote severity ?
I would lean more to using numbers since thats what we currently do in runtime.
Its also easier to think about IMO
There was a problem hiding this comment.
Internally Comgr can map an integer to a severity level. But externally I think we should just expose them as numbers
There was a problem hiding this comment.
There was a problem hiding this comment.
the case insensitivity is handled in comgr-logger.cpp, are you saying to move that the case lower to here?
There was a problem hiding this comment.
I suppose the sensitivity discussion is irrelevant if we're exposing numbers instead
There was a problem hiding this comment.
Oh sorry, when I posted that comment, I didn't see the more recent ones. Personally, I think that these labels make it more clear for both assigning LogLevels to a particular output and for toggling the threshold for what logs a user would like to see.
There was a problem hiding this comment.
I disagree. There's a few reasons:
-
The precedent has already been set by various other projects in the ROCm / HIP ecosystem. See 1, 2, 3 etc. Since Comgr is a member of the ROCm ecosystem we want to play along.
-
Its intuitive to think about "big number = more logging". This way you dont have to worry about the exact number assigned to the level of logging. You can just say
COMGR_LOG_LEVEL = 100and the user gets what they want. Very likely, they are not going to be choosing between these levels. They'd want the maximum possible logging when debugging an error. In fact, I have been usingAMD_LOG_LEVEL=7for runtime and I have no clue what the individual numbers map to. -
Tangential to point 2, you cant really establish an intuitive relationship between the various levels. How are "info" and "warning" related ? Does "error" give me more or less logging than "debug" ? Its confusing.
There was a problem hiding this comment.
That makes sense, thanks for the clarification. I'll do a 0-20 level logging and let the users have autonomy.
There was a problem hiding this comment.
We dont want to do 0-100 exactly. We still want to do 0-4 or 0-5 (depending on the available levels).
However, we do want to perform numeric comparison rather than equality when checking against the parsed value.
|
|
||
| // The capture stream is per-thread so that a captured Action on one thread does | ||
| // not collect log output emitted by an unrelated API on another thread. | ||
| thread_local raw_ostream *ThreadCaptureStream = nullptr; |
There was a problem hiding this comment.
Comgr doesnt support multithreaded execution yet. Do we need thread_local ?
There was a problem hiding this comment.
Comgr can be run in multiple threads and is thread safe, via a mutex around LLVM calls that cause issues
| return LogLevel::None; | ||
| if (Requested.equals_insensitive("error")) | ||
| return LogLevel::Error; | ||
| if (Requested.equals_insensitive("warning")) | ||
| return LogLevel::Warning; | ||
| if (Requested.equals_insensitive("info")) | ||
| return LogLevel::Info; | ||
| if (Requested.equals_insensitive("debug")) | ||
| return LogLevel::Debug; | ||
|
|
There was a problem hiding this comment.
Commented out code should be removed
|
Nice, we are starting to get there! Whats the reasoning behind the 0-20? We should just advertise the 4 levels (1-4) and leave everything else to numeric comparison. I'm counting the We should take inspiration from other projects in the ecosystem that I've linked. I'm not a fan of the verbose comment strategy that LLMs have. We should keep them to a minimum unless absolutely necessary. Some other review points (LLM generated, but I think they make sense):
|
| // Record the failure rather than writing it to stderr here. The Logger is | ||
| // constructed before any action's log buffer exists; the action layer | ||
| // surfaces this message into the returned comgr.log via getSinkError(), | ||
| // restoring the pre-Logger behavior of reporting it to the caller. |
| /// Severity of a log message, and the logger's configured threshold, expressed | ||
| /// on a 0-to-4 scale where 0 silences logging and higher values are more | ||
| /// verbose. A message is emitted only when its severity is non-zero and does | ||
| /// not exceed the configured level (see Logger::isEnabled). Callers choose the | ||
| /// numeric severity passed to Logger::emit; larger numbers are reserved for | ||
| /// more detailed diagnostics. |
There was a problem hiding this comment.
Same for the other function definitions in this file.
There was a problem hiding this comment.
+1 need to shorten more. I think this is mostly okay, but could use some concise language
|
Can we use a named enum (None=0, Error=1, Warning=2, Info=3, Debug=4) with the Severity <= Level checks? |
|
Some LLM comments:
|
|
@lamb-j @chinmaydd my last commits just addressed all of your recent comments, please check when you're able to |
| returned to the caller as normal. If this is set to "stdout"/"-" or "stderr", | ||
| logs are instead redirected to the standard output or error stream, | ||
| logs are additionally copied to the standard output or error stream, | ||
| respectively. If this is set to any other value, it is interpreted as a |
There was a problem hiding this comment.
Should explain what the log levels denote
|
|
||
| StringRef getLogLevel() { | ||
| static const char *LogLevel = getenv("AMD_COMGR_LOG_LEVEL"); | ||
| return LogLevel ? StringRef(LogLevel) : StringRef(); |
There was a problem hiding this comment.
LogLevel should be an enum as @lamb-j mentioned. This function should return that enum
There was a problem hiding this comment.
Check how Sam is trying to do something similar at #2478
There was a problem hiding this comment.
just to confirm, this means to revert LogLevel away from using numbers (suggested here #3116 (comment)) and back to using the original None, Error, Warning, Debug, Info enum, correct?
| /// not exceed the configured level (see Logger::isEnabled). Callers choose the | ||
| /// numeric severity passed to Logger::emit; larger numbers are reserved for | ||
| /// more detailed diagnostics. | ||
| using LogLevel = uint32_t; |
| // Tee Logger output emitted during this action into the in-memory buffer | ||
| // backing the AMD_COMGR_DATA_KIND_LOG data object, so emit() calls (here and | ||
| // in any Logger-aware API reached from this action) are collected for the | ||
| // caller alongside the global redirect sink. |
There was a problem hiding this comment.
comments too verbose in this file. please fix
| << " Comgr Branch-Commit: " << xstringify(AMD_COMGR_GIT_BRANCH) | ||
| << '-' << xstringify(AMD_COMGR_GIT_COMMIT) << '\n' | ||
| << "\t LLVM Commit: " << clang::getLLVMRevision(); | ||
| Log.emit(/*Severity=*/4, HeaderStr); |
Addresses this Jira Issue https://amd-hub.atlassian.net/browse/LCOMPILER-1886