20#include <xrpld/core/JobTypes.h>
21#include <xrpld/perflog/detail/PerfLogImp.h>
23#include <xrpl/basics/BasicConfig.h>
24#include <xrpl/beast/core/CurrentThreadName.h>
25#include <xrpl/beast/utility/Journal.h>
26#include <xrpl/json/json_writer.h>
52 auto const inserted =
rpc_.emplace(label,
Rpc()).second;
57 "ripple::perf::PerfLogImp::Counters::Counters : failed to "
65 for (
auto const& [jobType, _] : jobTypes)
67 auto const inserted =
jq_.emplace(jobType,
Jq()).second;
72 "ripple::perf::PerfLogImp::Counters::Counters : failed to "
85 for (
auto const& proc : rpc_)
90 if (!proc.second.value.started && !proc.second.value.finished &&
91 !proc.second.value.errored)
95 value = proc.second.value;
107 rpcobj[proc.first] = p;
116 totalRpcJson[jss::duration_us] =
118 rpcobj[jss::total] = totalRpcJson;
124 for (
auto const& proc : jq_)
129 if (!proc.second.value.queued && !proc.second.value.started &&
130 !proc.second.value.finished)
134 value = proc.second.value;
144 j[jss::queued_duration_us] =
147 j[jss::running_duration_us] =
159 totalJqJson[jss::queued_duration_us] =
161 totalJqJson[jss::running_duration_us] =
163 jqobj[jss::total] = totalJqJson;
169 counters[jss::rpc] = rpcobj;
170 counters[jss::job_queue] = jqobj;
180 auto const jobs = [
this] {
185 for (
auto const& j : jobs)
192 std::chrono::duration_cast<microseconds>(present - j.second)
201 methods.
reserve(methods_.size());
202 for (
auto const& m : methods_)
205 for (
auto m : methods)
208 methodobj[jss::method] = m.first;
210 std::chrono::duration_cast<microseconds>(present - m.second)
212 methodsArray.
append(methodobj);
216 current[jss::jobs] = jobsArray;
217 current[jss::methods] = methodsArray;
233 if (!boost::filesystem::is_directory(logDir))
235 boost::system::error_code ec;
236 boost::filesystem::create_directories(logDir, ec);
239 JLOG(
j_.
fatal()) <<
"Unable to create performance log "
241 << logDir <<
": " << ec.message();
295 report[jss::time] =
to_string(std::chrono::floor<microseconds>(present));
332 UNREACHABLE(
"ripple::perf::PerfLogImp::rpcStart : valid method input");
338 ++counter->second.value.started;
354 UNREACHABLE(
"ripple::perf::PerfLogImp::rpcEnd : valid method input");
363 startTime = e->second.second;
369 "ripple::perf::PerfLogImp::rpcEnd : valid requestId input");
374 ++counter->second.value.finished;
376 ++counter->second.value.errored;
377 counter->second.value.duration += std::chrono::duration_cast<microseconds>(
388 "ripple::perf::PerfLogImp::jobQueue : valid job type input");
392 ++counter->second.value.queued;
406 "ripple::perf::PerfLogImp::jobStart : valid job type input");
411 ++counter->second.value.started;
412 counter->second.value.queuedDuration += dur;
426 "ripple::perf::PerfLogImp::jobFinish : valid job type input");
431 ++counter->second.value.finished;
432 counter->second.value.runningDuration += dur;
486 set(perfLog,
"perf_log", section);
489 setup.
perfLog = boost::filesystem::path(perfLog);
490 if (setup.
perfLog.is_relative())
493 boost::filesystem::absolute(setup.
perfLog, configDir);
511 setup, app, journal, std::move(signalStop));
Decorator for streaming out compact json.
Value & append(Value const &value)
Append value to array at the end.
A generic endpoint for log messages.
virtual NodeStore::Database & getNodeStore()=0
virtual NetworkOPs & getOPs()=0
static std::string const & name(JobType jt)
Map::size_type size() const
virtual void stateAccounting(Json::Value &obj)=0
void getCountsJson(Json::Value &obj)
Holds a collection of configuration values.
std::string const hostname_
void rpcEnd(std::string const &method, std::uint64_t const requestId, bool finish)
void resizeJobs(int const resize) override
Ensure enough room to store each currently executing job.
std::function< void()> const signalStop_
void jobQueue(JobType const type) override
Log queued job.
void jobStart(JobType const type, microseconds dur, steady_time_point startTime, int instance) override
Log job executing.
void rpcStart(std::string const &method, std::uint64_t const requestId) override
Log start of RPC call.
void rotate() override
Rotate perf log file.
std::condition_variable cond_
PerfLogImp(Setup const &setup, Application &app, beast::Journal journal, std::function< void()> &&signalStop)
void jobFinish(JobType const type, microseconds dur, int instance) override
Log job finishing.
system_time_point lastLog_
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.
PerfLog::Setup setup_PerfLog(Section const §ion, boost::filesystem::path const &configDir)
std::unique_ptr< PerfLog > make_PerfLog(PerfLog::Setup const &setup, Application &app, beast::Journal journal, std::function< void()> &&signalStop)
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,...
bool get_if_exists(Section const §ion, std::string const &name, T &v)
@ current
This was a new validation and was added.
std::string to_string(base_uint< Bits, Tag > const &a)
Job Queue task performance counters.
microseconds runningDuration
microseconds queuedDuration
RPC performance counters.
Json::Value currentJson() const
std::unordered_map< std::string, Locked< Rpc > > rpc_
std::vector< std::pair< JobType, steady_time_point > > jobs_
std::unordered_map< std::uint64_t, MethodStart > methods_
Counters(std::set< char const * > const &labels, JobTypes const &jobTypes)
Json::Value countersJson() const
std::unordered_map< JobType, Locked< Jq > > jq_
Configuration from [perf] section of rippled.cfg.
boost::filesystem::path perfLog