Fallback to display thread id of no name was assigned, OpenVulkano::Utils::GetThreadId()
This commit is contained in:
@@ -11,6 +11,7 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <csignal>
|
#include <csignal>
|
||||||
|
#include <inttypes.h>
|
||||||
#include <spdlog/sinks/rotating_file_sink.h>
|
#include <spdlog/sinks/rotating_file_sink.h>
|
||||||
#include <spdlog/sinks/null_sink.h>
|
#include <spdlog/sinks/null_sink.h>
|
||||||
#ifndef NO_CONSOLE_LOG
|
#ifndef NO_CONSOLE_LOG
|
||||||
@@ -182,9 +183,18 @@ namespace OpenVulkano
|
|||||||
void CustomThreadNameFormatterFlag::format(const spdlog::details::log_msg &msg, const std::tm &tmTime, spdlog::memory_buf_t &dest)
|
void CustomThreadNameFormatterFlag::format(const spdlog::details::log_msg &msg, const std::tm &tmTime, spdlog::memory_buf_t &dest)
|
||||||
{
|
{
|
||||||
std::string threadName = OpenVulkano::Utils::GetThreadName();
|
std::string threadName = OpenVulkano::Utils::GetThreadName();
|
||||||
// NOTE(vb): What should be displayed if the thread name wasn't specified?
|
if(threadName.length())
|
||||||
|
{
|
||||||
dest.append(threadName.c_str(), threadName.c_str() + threadName.length());
|
dest.append(threadName.c_str(), threadName.c_str() + threadName.length());
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
uint64_t threadId = OpenVulkano::Utils::GetThreadId();
|
||||||
|
char buffer[64];
|
||||||
|
snprintf(buffer, sizeof(buffer), "%" PRIu64, threadId);
|
||||||
|
dest.append(buffer, buffer + strlen(buffer));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
std::unique_ptr<spdlog::custom_flag_formatter> CustomThreadNameFormatterFlag::clone() const
|
std::unique_ptr<spdlog::custom_flag_formatter> CustomThreadNameFormatterFlag::clone() const
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -43,14 +43,22 @@ namespace OpenVulkano
|
|||||||
return str;
|
return str;
|
||||||
#else
|
#else
|
||||||
// NOTE(vb): Accoring to linux man page size of this array must be _at least_ 16 bytes...
|
// NOTE(vb): Accoring to linux man page size of this array must be _at least_ 16 bytes...
|
||||||
// But I don't know whether is it applicable to have the buffer of bigger size
|
char threadName[64];
|
||||||
char threadName[16];
|
|
||||||
pthread_getname_np(pthread_self(), threadName, sizeof(threadName));
|
pthread_getname_np(pthread_self(), threadName, sizeof(threadName));
|
||||||
std::string str = threadName;
|
std::string str = threadName;
|
||||||
return str;
|
return str;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint64_t Utils::GetThreadId()
|
||||||
|
{
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
return (uint64_t)::GetThreadId(::GetCurrentThread());
|
||||||
|
#else
|
||||||
|
return (uint64_t)pthread_self();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
Array<char> Utils::ReadFile(const std::string& filePath, bool emptyOnMissing)
|
Array<char> Utils::ReadFile(const std::string& filePath, bool emptyOnMissing)
|
||||||
{
|
{
|
||||||
std::ifstream file(filePath, std::ios::ate | std::ios::binary);
|
std::ifstream file(filePath, std::ios::ate | std::ios::binary);
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ namespace OpenVulkano
|
|||||||
public:
|
public:
|
||||||
static void SetThreadName(const std::string& name);
|
static void SetThreadName(const std::string& name);
|
||||||
static std::string GetThreadName();
|
static std::string GetThreadName();
|
||||||
|
static uint64_t GetThreadId();
|
||||||
|
|
||||||
static inline std::vector<const char*> toCString(const std::vector<std::string>& values)
|
static inline std::vector<const char*> toCString(const std::vector<std::string>& values)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user