SWDEV-301667 - Logging upgrades

- Use AMD_LOG_LEVEL_SIZE in MBs to set log file size truncation, by default its 2048 MB

Change-Id: Ia2f87e8c6b94148e30edfb602b279f93630817c3


[ROCm/clr commit: 35e03ea0d0]
This commit is contained in:
Saleel Kudchadker
2024-09-28 16:42:29 +00:00
parent 91b343c758
commit 5296c77138
3 changed files with 29 additions and 8 deletions
+1 -1
View File
@@ -3766,7 +3766,7 @@ hipError_t hipPointerGetAttributes(hipPointerAttribute_t* attributes, const void
attributes->isManaged = false;
attributes->allocationFlags = 0;
attributes->device = hipInvalidDeviceId;
LogPrintfError("Cannot get amd_mem_obj for ptr: 0x%x", ptr);
LogPrintfError("Cannot get amd_mem_obj for ptr: %p", ptr);
}
HIP_RETURN(hipSuccess);
}
+24 -5
View File
@@ -40,15 +40,33 @@
namespace amd {
FILE* outFile = stderr;
const size_t maxLogSize = AMD_LOG_LEVEL_SIZE * Mi;
// ================================================================================================
void report_warning(const char* message) { fprintf(outFile, "Warning: %s\n", message); }
void truncate_log_file() {
if (outFile != stderr) {
fseek(outFile, 0, SEEK_END);
long size = ftell(outFile);
if (size > maxLogSize) {
if (nullptr == freopen(NULL, "w", outFile)) {
outFile = stderr;
}
}
}
}
// ================================================================================================
void report_warning(const char* message) {
truncate_log_file();
fprintf(outFile, "Warning: %s\n", message);
}
// ================================================================================================
void log_entry(LogLevel level, const char* file, int line, const char* message) {
if (level == LOG_NONE) {
return;
}
truncate_log_file();
fprintf(outFile, ":%d:%s:%d: %s\n", level, file, line, message);
fflush(outFile);
}
@@ -67,12 +85,10 @@ void log_timestamped(LogLevel level, const char* file, int line, const char* mes
if (level == LOG_NONE) {
return;
}
#if 0
fprintf(outFile, ":%d:%s:%d: (%010lld) %s\n", level, file, line, time, message);
#else // if you prefer fixed-width fields
truncate_log_file();
fprintf(outFile, ":% 2d:%15s:% 5d: (%010lld) us %s\n", level, file, line, time / 1000ULL,
message);
#endif
fflush(outFile);
}
@@ -91,6 +107,7 @@ void log_printf(LogLevel level, const char* file, int line, const char* format,
va_end(ap);
uint64_t timeUs = Os::timeNanos() / 1000ULL;
truncate_log_file();
fprintf(outFile, ":%d:%-25s:%-4d: %010lu us: %s %s\n", level, file, line,
timeUs, pidtid.str().c_str(),message);
@@ -112,6 +129,8 @@ void log_printf(LogLevel level, const char* file, int line, uint64_t* start,
va_end(ap);
uint64_t timeUs = Os::timeNanos() / 1000ULL;
truncate_log_file();
if (start == 0 || *start == 0) {
fprintf(outFile, ":%d:%-25s:%-4d: %010lu us: %s %s\n", level, file, line,
timeUs, pidtid.str().c_str(), message);
+4 -2
View File
@@ -28,6 +28,10 @@ release(int, AMD_LOG_LEVEL, 0, \
"The default log level") \
release(uint, AMD_LOG_MASK, 0X7FFFFFFF, \
"The mask to enable specific kinds of logs") \
release(cstring, AMD_LOG_LEVEL_FILE, "", \
"Set output file for AMD_LOG_LEVEL, Default is stderr") \
release(size_t, AMD_LOG_LEVEL_SIZE, 2048, \
"The max size of AMD_LOG generated in MB if printed to a file") \
debug(uint, DEBUG_GPU_FLAGS, 0, \
"The debug options for GPU device") \
release(size_t, CQ_THREAD_STACK_SIZE, 256*Ki, /* @todo: that much! */ \
@@ -207,8 +211,6 @@ release(bool, PAL_EMBED_KERNEL_MD, false, \
release(cstring, ROC_GLOBAL_CU_MASK, "", \
"Sets a global CU mask (entered as hex value) for all queues," \
"Each active bit represents using one CU (e.g., 0xf enables only 4 CUs)") \
release(cstring, AMD_LOG_LEVEL_FILE, "", \
"Set output file for AMD_LOG_LEVEL, Default is stderr") \
release(size_t, PAL_PREPINNED_MEMORY_SIZE, 64, \
"Size in KBytes of prepinned memory") \
release(bool, AMD_CPU_AFFINITY, false, \