| 62 | } // namespace |
| 63 | |
| 64 | std::string ThreadName(const char* exe_name) |
| 65 | { |
| 66 | char thread_name[16] = {0}; |
| 67 | #ifdef HAVE_PTHREAD_GETNAME_NP |
| 68 | pthread_getname_np(pthread_self(), thread_name, sizeof(thread_name)); |
| 69 | #endif // HAVE_PTHREAD_GETNAME_NP |
| 70 | |
| 71 | std::ostringstream buffer; |
| 72 | buffer << (exe_name ? exe_name : "") << "-" << getpid() << "/"; |
| 73 | |
| 74 | if (thread_name[0] != '\0') { |
| 75 | buffer << thread_name << "-"; |
| 76 | } |
| 77 | |
| 78 | // Prefer platform specific thread ids over the standard C++11 ones because |
| 79 | // the former are shorter and are the same as what gdb prints "LWP ...". |
| 80 | #ifdef __linux__ |
| 81 | buffer << syscall(SYS_gettid); |
| 82 | #elif defined(HAVE_PTHREAD_THREADID_NP) |
| 83 | uint64_t tid = 0; |
| 84 | pthread_threadid_np(nullptr, &tid); |
| 85 | buffer << tid; |
| 86 | #elif defined(HAVE_PTHREAD_GETTHREADID_NP) |
| 87 | buffer << pthread_getthreadid_np(); |
| 88 | #else |
| 89 | buffer << std::this_thread::get_id(); |
| 90 | #endif |
| 91 | |
| 92 | return std::move(buffer).str(); |
| 93 | } |
| 94 | |
| 95 | std::string LogEscape(const kj::StringTree& string, size_t max_size) |
| 96 | { |
no test coverage detected