Skip to content

Commit 1f40d0c

Browse files
committed
log: concatenate thread names and print once per thread
Fixes: 0be8d01 Fixes: https://tracker.ceph.com/issues/68691 Signed-off-by: Patrick Donnelly <[email protected]>
1 parent df4367e commit 1f40d0c

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/log/Log.cc

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
#include <fmt/format.h>
3333
#include <fmt/ostream.h>
34+
#include <fmt/ranges.h>
3435

3536
#define MAX_LOG_BUF 65536
3637

@@ -493,13 +494,14 @@ void Log::dump_recent()
493494
_flush(m_flush, false);
494495

495496
_log_message("--- begin dump of recent events ---", true);
496-
std::set<std::pair<pthread_t, const char *>> recent_pthread_ids;
497+
std::map<pthread_t, std::set<std::string> > recent_pthread_ids;
497498
{
498499
EntryVector t;
499500
t.insert(t.end(), std::make_move_iterator(m_recent.begin()), std::make_move_iterator(m_recent.end()));
500501
m_recent.clear();
501502
for (const auto& e : t) {
502-
recent_pthread_ids.emplace(std::make_pair(e.m_thread, e.m_thread_name));
503+
auto& set = recent_pthread_ids[e.m_thread];
504+
set.insert(e.m_thread_name);
503505
}
504506
_flush(t, true);
505507
}
@@ -515,11 +517,14 @@ void Log::dump_recent()
515517
m_stderr_log, m_stderr_crash), true);
516518

517519
_log_message("--- pthread ID / name mapping for recent threads ---", true);
518-
for (auto& [pthread_id, pthread_name] : recent_pthread_ids)
520+
for (const auto& [pthread_id, pthread_names] : recent_pthread_ids)
519521
{
520522
// we want the ID to be printed in the same format as we use for a log entry.
521523
// The reason is easier grepping.
522-
_log_message(fmt::format(" {:x} / {}", tid_to_int(pthread_id), pthread_name), true);
524+
auto msg = fmt::format(" {:x} / {}",
525+
tid_to_int(pthread_id),
526+
fmt::join(pthread_names, ", "));
527+
_log_message(msg, true);
523528
}
524529

525530
_log_message(fmt::format(" max_recent {:9}", m_recent.capacity()), true);

0 commit comments

Comments
 (0)