diff --git a/rocclr/os/os.hpp b/rocclr/os/os.hpp index b66e4777e6..ab026bcac5 100644 --- a/rocclr/os/os.hpp +++ b/rocclr/os/os.hpp @@ -317,6 +317,9 @@ class Os : AllStatic { //! Uninstall SIGFPE handler for CPU device static void uninstallSigfpeHandler(); + + //! Return the current process id + static int getProcessId(); }; /*@}*/ diff --git a/rocclr/os/os_posix.cpp b/rocclr/os/os_posix.cpp index d4fcc9662d..21b00e7ae8 100644 --- a/rocclr/os/os_posix.cpp +++ b/rocclr/os/os_posix.cpp @@ -919,6 +919,10 @@ bool Os::MemoryMapFileTruncated(const char* fname, const void** mmap_ptr, size_t return true; } +int Os::getProcessId() { + return ::getpid(); +} + } // namespace amd #endif // !defined(_WIN32) && !defined(__CYGWIN__) diff --git a/rocclr/os/os_win32.cpp b/rocclr/os/os_win32.cpp index bb5f4d0766..5b9c3ec1b7 100644 --- a/rocclr/os/os_win32.cpp +++ b/rocclr/os/os_win32.cpp @@ -941,6 +941,10 @@ bool Os::FindFileNameFromAddress(const void* image, std::string* fname_ptr, size return false; } +int Os::getProcessId() { + return ::_getpid(); +} + } // namespace amd #endif // _WIN32 || __CYGWIN__ diff --git a/rocclr/utils/debug.cpp b/rocclr/utils/debug.cpp index 8127128030..fc60756455 100644 --- a/rocclr/utils/debug.cpp +++ b/rocclr/utils/debug.cpp @@ -106,7 +106,7 @@ void log_printf(LogLevel level, const char* file, int line, const char* format, va_end(ap); uint64_t timeUs = Os::timeNanos() / 1000ULL; fprintf(outFile, ":%d:%-25s:%-4d: %010lld us: %-5d: [tid:0x%s] %s\n", level, file, line, - timeUs/1ULL, getpid(), str_thrd_id.str().c_str(), message); + timeUs/1ULL, Os::getProcessId(), str_thrd_id.str().c_str(), message); fflush(outFile); } @@ -123,10 +123,10 @@ void log_printf(LogLevel level, const char* file, int line, uint64_t* start, uint64_t timeUs = Os::timeNanos() / 1000ULL; if (start == 0 || *start == 0) { fprintf(outFile, ":%d:%-25s:%-4d: %010lld us: %-5d: [tid:0x%s] %s\n", level, file, line, - timeUs/1ULL, getpid(), str_thrd_id.str().c_str(), message); + timeUs/1ULL, Os::getProcessId(), str_thrd_id.str().c_str(), message); } else { fprintf(outFile, ":%d:%-25s:%-4d: %010lld us: %-5d: [tid:0x%s] %s: duration: %lld us\n", - level, file, line, timeUs/1ULL, getpid(), str_thrd_id.str().c_str(), message, + level, file, line, timeUs/1ULL, Os::getProcessId(), str_thrd_id.str().c_str(), message, (timeUs - *start)/1ULL); } fflush(outFile); diff --git a/rocclr/utils/flags.cpp b/rocclr/utils/flags.cpp index 3897f4d0e4..f19d26a6cf 100644 --- a/rocclr/utils/flags.cpp +++ b/rocclr/utils/flags.cpp @@ -20,6 +20,7 @@ #include "top.hpp" #include "utils/flags.hpp" +#include "os/os.hpp" #include #include @@ -156,7 +157,7 @@ bool Flag::init() { if (!flagIsDefault(AMD_LOG_LEVEL)) { if (!flagIsDefault(AMD_LOG_LEVEL_FILE)) { std::string fileName = AMD_LOG_LEVEL_FILE; - fileName = fileName + "_" + std::to_string(getpid()); + fileName = fileName + "_" + std::to_string(Os::getProcessId()); outFile = fopen(fileName.c_str(), "w"); } }