From e50ce1951980fc8433f2c91af9e0c4504f201aaf Mon Sep 17 00:00:00 2001 From: pghafari Date: Thu, 15 Feb 2024 19:31:04 -0500 Subject: [PATCH] SWDEV-444447 - log print pid/tid only in verbose mode Change-Id: I2bbe9085d607e9d8d5acda1ed43e3245335d239f [ROCm/clr commit: 9e6e77b7dd57f72e67a842a30b482344032c7838] --- projects/clr/rocclr/utils/debug.cpp | 32 +++++++++++++++++++---------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/projects/clr/rocclr/utils/debug.cpp b/projects/clr/rocclr/utils/debug.cpp index 92cb5bc813..98954034bc 100644 --- a/projects/clr/rocclr/utils/debug.cpp +++ b/projects/clr/rocclr/utils/debug.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #ifdef _WIN32 #include @@ -78,15 +79,21 @@ void log_timestamped(LogLevel level, const char* file, int line, const char* mes // ================================================================================================ void log_printf(LogLevel level, const char* file, int line, const char* format, ...) { va_list ap; - std::stringstream str_thrd_id; - str_thrd_id << std::hex << std::this_thread::get_id(); + std::stringstream pidtid; + if (AMD_LOG_LEVEL > 4) { + pidtid << "[pid:" << Os::getProcessId() << " tid: " ; + pidtid << std::hex << std::setw(5) << std::this_thread::get_id() << "]"; + } + va_start(ap, format); char message[4096]; vsnprintf(message, sizeof(message), format, ap); va_end(ap); uint64_t timeUs = Os::timeNanos() / 1000ULL; - fprintf(outFile, ":%d:%-25s:%-4d: %010lld us: [pid:%-5d tid:0x%s] %s\n", level, file, line, - timeUs/1ULL, Os::getProcessId(), str_thrd_id.str().c_str(), message); + + fprintf(outFile, ":%d:%-25s:%-4d: %010lud us: %s %s\n", level, file, line, + timeUs, pidtid.str().c_str(),message); + fflush(outFile); } @@ -94,20 +101,23 @@ void log_printf(LogLevel level, const char* file, int line, const char* format, void log_printf(LogLevel level, const char* file, int line, uint64_t* start, const char* format, ...) { va_list ap; - std::stringstream str_thrd_id; - str_thrd_id << std::hex << std::this_thread::get_id(); + std::stringstream pidtid; + if (AMD_LOG_LEVEL > 4) { + pidtid << "[pid:" << Os::getProcessId() << " tid: " ; + pidtid << std::hex << std::setw(5) << std::this_thread::get_id() << "]"; + } va_start(ap, format); char message[4096]; vsnprintf(message, sizeof(message), format, ap); va_end(ap); uint64_t timeUs = Os::timeNanos() / 1000ULL; + if (start == 0 || *start == 0) { - fprintf(outFile, ":%d:%-25s:%-4d: %010lld us: [pid:%-5d tid:0x%s] %s\n", level, file, line, - timeUs/1ULL, Os::getProcessId(), str_thrd_id.str().c_str(), message); + fprintf(outFile, ":%d:%-25s:%-4d: %010lud us: %s %s\n", level, file, line, + timeUs, pidtid.str().c_str(), message); } else { - fprintf(outFile, ":%d:%-25s:%-4d: %010lld us: [pid:%-5d tid:0x%s] %s: duration: %lld us\n", - level, file, line, timeUs/1ULL, Os::getProcessId(), str_thrd_id.str().c_str(), message, - (timeUs - *start)/1ULL); + fprintf(outFile, ":%d:%-25s:%-4d: %010lud us: %s %s: duration: %lud us\n", + level, file, line, timeUs, pidtid.str().c_str(), message, timeUs - *start); } fflush(outFile); if (*start == 0) {