1#include <xrpld/perflog/detail/PerfLogImp.h>
3#include <xrpl/basics/BasicConfig.h>
4#include <xrpl/beast/core/CurrentThreadName.h>
5#include <xrpl/beast/utility/Journal.h>
6#include <xrpl/core/JobTypes.h>
7#include <xrpl/json/json_writer.h>
31 auto const inserted =
rpc_.emplace(label,
Rpc()).second;
37 "xrpl::perf::PerfLogImp::Counters::Counters : failed to "
46 for (
auto const& [jobType, _] : jobTypes)
48 auto const inserted =
jq_.emplace(jobType,
Jq()).second;
54 "xrpl::perf::PerfLogImp::Counters::Counters : failed to "
68 for (
auto const& proc : rpc_)
73 if ((proc.second.value.started == 0u) && (proc.second.value.finished == 0u) &&
74 (proc.second.value.errored == 0u))
78 value = proc.second.value;
90 rpcobj[proc.first] = p;
100 rpcobj[jss::total] = totalRpcJson;
106 for (
auto const& proc : jq_)
111 if ((proc.second.value.queued == 0u) && (proc.second.value.started == 0u) &&
112 (proc.second.value.finished == 0u))
116 value = proc.second.value;
141 jobQueueObj[jss::total] = totalJqJson;
147 counters[jss::rpc] = rpcobj;
148 counters[jss::job_queue] = jobQueueObj;
158 auto const jobs = [
this] {
163 for (
auto const& j : jobs)
169 jobj[jss::duration_us] =
170 std::to_string(std::chrono::duration_cast<microseconds>(present - j.second).count());
178 methods.
reserve(methods_.size());
179 for (
auto const& m : methods_)
182 for (
auto m : methods)
185 methodobj[jss::method] = m.first;
186 methodobj[jss::duration_us] =
187 std::to_string(std::chrono::duration_cast<microseconds>(present - m.second).count());
188 methodsArray.
append(methodobj);
192 current[jss::jobs] = jobsArray;
193 current[jss::methods] = methodsArray;
209 if (!boost::filesystem::is_directory(logDir))
211 boost::system::error_code ec;
212 boost::filesystem::create_directories(logDir, ec);
215 JLOG(
j_.
fatal()) <<
"Unable to create performance log "
217 << logDir <<
": " << ec.message();
271 report[jss::time] =
to_string(std::chrono::floor<microseconds>(present));
308 UNREACHABLE(
"xrpl::perf::PerfLogImp::rpcStart : valid method input");
315 ++counter->second.value.started;
328 UNREACHABLE(
"xrpl::perf::PerfLogImp::rpcEnd : valid method input");
338 startTime = e->second.second;
344 UNREACHABLE(
"xrpl::perf::PerfLogImp::rpcEnd : valid requestId input");
351 ++counter->second.value.finished;
355 ++counter->second.value.errored;
357 counter->second.value.duration +=
368 UNREACHABLE(
"xrpl::perf::PerfLogImp::jobQueue : valid job type input");
373 ++counter->second.value.queued;
387 UNREACHABLE(
"xrpl::perf::PerfLogImp::jobStart : valid job type input");
394 ++counter->second.value.started;
395 counter->second.value.queuedDuration += dur;
409 UNREACHABLE(
"xrpl::perf::PerfLogImp::jobFinish : valid job type input");
416 ++counter->second.value.finished;
417 counter->second.value.runningDuration += dur;
471 set(perfLog,
"perf_log", section);
472 if (!perfLog.
empty())
474 setup.
perfLog = boost::filesystem::path(perfLog);
475 if (setup.
perfLog.is_relative())
477 setup.
perfLog = boost::filesystem::absolute(setup.
perfLog, configDir);
Decorator for streaming out compact json.
Value & append(Value const &value)
Append value to array at the end.
A generic endpoint for log messages.
Map::size_type size() const
static std::string const & name(JobType jt)
virtual void stateAccounting(Json::Value &obj)=0
void getCountsJson(Json::Value &obj)
Holds a collection of configuration values.
virtual NetworkOPs & getOPs()=0
virtual NodeStore::Database & getNodeStore()=0
std::condition_variable cond_
void jobFinish(JobType const type, microseconds dur, int instance) override
Log job finishing.
void rpcStart(std::string const &method, std::uint64_t const requestId) override
Log start of RPC call.
void jobQueue(JobType const type) override
Log queued job.
void resizeJobs(int const resize) override
Ensure enough room to store each currently executing job.
system_time_point lastLog_
void rpcEnd(std::string const &method, std::uint64_t const requestId, bool finish)
void rotate() override
Rotate perf log file.
std::function< void()> const signalStop_
PerfLogImp(Setup const &setup, Application &app, beast::Journal journal, std::function< void()> &&signalStop)
void jobStart(JobType const type, microseconds dur, steady_time_point startTime, int instance) override
Log job executing.
std::string const hostname_
std::chrono::time_point< steady_clock > steady_time_point
@ arrayValue
array value (ordered list)
@ objectValue
object value (collection of name/value pairs).
void setCurrentThreadName(std::string_view newThreadName)
Changes the name of the caller thread.
std::unique_ptr< PerfLog > make_PerfLog(PerfLog::Setup const &setup, Application &app, beast::Journal journal, std::function< void()> &&signalStop)
PerfLog::Setup setup_PerfLog(Section const §ion, boost::filesystem::path const &configDir)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
bool set(T &target, std::string const &name, Section const §ion)
Set a value from a configuration Section If the named value is not found or doesn't parse as a T,...
std::string to_string(base_uint< Bits, Tag > const &a)
@ current
This was a new validation and was added.
bool get_if_exists(Section const §ion, std::string const &name, T &v)
Job Queue task performance counters.
microseconds queuedDuration
microseconds runningDuration
RPC performance counters.
std::unordered_map< JobType, Locked< Jq > > jq_
std::vector< std::pair< JobType, steady_time_point > > jobs_
Json::Value currentJson() const
std::unordered_map< std::uint64_t, MethodStart > methods_
std::unordered_map< std::string, Locked< Rpc > > rpc_
Json::Value countersJson() const
Counters(std::set< char const * > const &labels, JobTypes const &jobTypes)
Configuration from [perf] section of xrpld.cfg.
boost::filesystem::path perfLog