if (pid && cpuid >= 0)
_set_affinity(cpuid);
- ceph_pthread_setname(pthread_self(), thread_name.c_str());
+ ceph_pthread_setname(pthread_self(), Thread::thread_name.c_str());
return entry();
}
void Thread::create(const char *name, size_t stacksize)
{
ceph_assert(strlen(name) < 16);
- thread_name = name;
+ Thread::thread_name = name;
int ret = try_create(stacksize);
if (ret != 0) {
#include <string_view>
#include <system_error>
#include <thread>
+#include <cstring>
#include <pthread.h>
#include <sys/types.h>
+#include "include/ceph_assert.h"
#include "include/compat.h"
+#include "include/spinlock.h"
extern pid_t ceph_gettid();
pthread_t thread_id;
pid_t pid;
int cpuid;
- std::string thread_name;
+ static inline thread_local std::string thread_name;
void *entry_wrapper();
int join(void **prval = 0);
int detach();
int set_affinity(int cpuid);
+ static const std::string get_thread_name() {
+ return Thread::thread_name;
+ }
};
// Functions for with std::thread
#ifndef __CEPH_LOG_ENTRY_H
#define __CEPH_LOG_ENTRY_H
+#include "include/compat.h"
+
#include "log/LogClock.h"
#include "common/StackStringStream.h"
+#include "common/Thread.h"
#include "boost/container/small_vector.hpp"
#include <string_view>
+
namespace ceph {
namespace logging {
m_thread(pthread_self()),
m_prio(pr),
m_subsys(sub)
- {}
+ {
+ strncpy(m_thread_name, Thread::get_thread_name().data(), 16);
+ m_thread_name[15] = '\0';
+ }
Entry(const Entry &) = default;
Entry& operator=(const Entry &) = default;
Entry(Entry &&e) = default;
time m_stamp;
pthread_t m_thread;
short m_prio, m_subsys;
+ char m_thread_name[16];
static log_clock& clock() {
static log_clock clock;
_flush(m_flush, false);
_log_message("--- begin dump of recent events ---", true);
- std::set<pthread_t> recent_pthread_ids;
+ std::set<std::pair<pthread_t, const char *>> recent_pthread_ids;
{
EntryVector t;
t.insert(t.end(), std::make_move_iterator(m_recent.begin()), std::make_move_iterator(m_recent.end()));
m_recent.clear();
for (const auto& e : t) {
- recent_pthread_ids.emplace(e.m_thread);
+ recent_pthread_ids.emplace(std::make_pair(e.m_thread, e.m_thread_name));
}
_flush(t, true);
}
m_stderr_log, m_stderr_crash), true);
_log_message("--- pthread ID / name mapping for recent threads ---", true);
- for (const auto pthread_id : recent_pthread_ids)
+ for (auto& [pthread_id, pthread_name] : recent_pthread_ids)
{
- char pthread_name[16] = {0}; //limited by 16B include terminating null byte.
- ceph_pthread_getname(pthread_id, pthread_name, sizeof(pthread_name));
// we want the ID to be printed in the same format as we use for a log entry.
// The reason is easier grepping.
- _log_message(fmt::format(" {:x} / {}",
- tid_to_int(pthread_id), pthread_name), true);
+ _log_message(fmt::format(" {:x} / {}", tid_to_int(pthread_id), pthread_name), true);
}
_log_message(fmt::format(" max_recent {:9}", m_recent.capacity()), true);