Files
rippled/src/libxrpl/core/detail/Job.cpp
Valentin Balaschenko 68c9d5ca0f refactor: Enforce 15-char limit and simplify labels for thread naming (#6212)
This change continues the thread naming work from #5691 and #5758, which enables more useful lock contention profiling by ensuring threads/jobs have short, stable, human-readable names (rather than being truncated/failing due to OS limits). This changes diagnostic naming only (thread names and job/load-event labels), not behavior.

Specific modifications are:
* Shortens all thread/job names used with `beast::setCurrentThreadName`, so the effective Linux thread name stays within the 15-character limit.
* Removes per-ledger sequence numbers from job/thread names to avoid long labels. This improves aggregation in lock contention profiling for short-lived job executions.
2026-01-22 08:19:29 -05:00

104 lines
1.6 KiB
C++

#include <xrpl/beast/core/CurrentThreadName.h>
#include <xrpl/core/Job.h>
namespace xrpl {
Job::Job() : mType(jtINVALID), mJobIndex(0)
{
}
Job::Job(JobType type, std::uint64_t index) : mType(type), mJobIndex(index)
{
}
Job::Job(
JobType type,
std::string const& name,
std::uint64_t index,
LoadMonitor& lm,
std::function<void()> const& job)
: mType(type)
, mJobIndex(index)
, mJob(job)
, mName(name)
, m_queue_time(clock_type::now())
{
m_loadEvent = std::make_shared<LoadEvent>(std::ref(lm), name, false);
}
JobType
Job::getType() const
{
return mType;
}
Job::clock_type::time_point const&
Job::queue_time() const
{
return m_queue_time;
}
void
Job::doJob()
{
beast::setCurrentThreadName("j:" + mName);
m_loadEvent->start();
m_loadEvent->setName(mName);
mJob();
// Destroy the lambda, otherwise we won't include
// its duration in the time measurement
mJob = nullptr;
}
bool
Job::operator>(Job const& j) const
{
if (mType < j.mType)
return true;
if (mType > j.mType)
return false;
return mJobIndex > j.mJobIndex;
}
bool
Job::operator>=(Job const& j) const
{
if (mType < j.mType)
return true;
if (mType > j.mType)
return false;
return mJobIndex >= j.mJobIndex;
}
bool
Job::operator<(Job const& j) const
{
if (mType < j.mType)
return false;
if (mType > j.mType)
return true;
return mJobIndex < j.mJobIndex;
}
bool
Job::operator<=(Job const& j) const
{
if (mType < j.mType)
return false;
if (mType > j.mType)
return true;
return mJobIndex <= j.mJobIndex;
}
} // namespace xrpl