diff --git a/hipamd/src/hip_memory.cpp b/hipamd/src/hip_memory.cpp index 791ee384ed..0ad2f35ea1 100644 --- a/hipamd/src/hip_memory.cpp +++ b/hipamd/src/hip_memory.cpp @@ -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); } diff --git a/rocclr/utils/debug.cpp b/rocclr/utils/debug.cpp index 60ef355bf3..60c6f1be38 100644 --- a/rocclr/utils/debug.cpp +++ b/rocclr/utils/debug.cpp @@ -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); diff --git a/rocclr/utils/flags.hpp b/rocclr/utils/flags.hpp index ea1ff2b7ed..c057a8cd6c 100644 --- a/rocclr/utils/flags.hpp +++ b/rocclr/utils/flags.hpp @@ -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, \