20 #include <ripple/basics/BasicConfig.h>
21 #include <ripple/basics/impl/PerfLogImp.h>
22 #include <ripple/beast/core/CurrentThreadName.h>
23 #include <ripple/beast/utility/Journal.h>
24 #include <ripple/json/json_writer.h>
25 #include <ripple/json/to_string.h>
26 #include <boost/optional.hpp>
50 auto const inserted =
rpc_.emplace(label,
Rpc()).second;
61 for (
auto const& [jobType, jobTypeInfo] : jobTypes)
64 jq_.emplace(jobType,
Jq(jobTypeInfo.name())).second;
80 for (
auto const& proc : rpc_)
85 [&proc]() -> boost::optional<Counters::Rpc::Sync> {
87 if (!proc.second.sync.started && !proc.second.sync.finished &&
88 !proc.second.sync.errored)
92 return proc.second.sync;
106 rpcobj[proc.first] = p;
115 totalRpcJson[jss::duration_us] =
117 rpcobj[jss::total] = totalRpcJson;
123 for (
auto const& proc : jq_)
127 auto const sync = [&proc]() -> boost::optional<Counters::Jq::Sync> {
129 if (!proc.second.sync.queued && !proc.second.sync.started &&
130 !proc.second.sync.finished)
134 return proc.second.sync;
145 j[jss::queued_duration_us] =
148 j[jss::running_duration_us] =
152 jqobj[proc.second.label] = j;
161 totalJqJson[jss::queued_duration_us] =
163 totalJqJson[jss::running_duration_us] =
165 jqobj[jss::total] = totalJqJson;
171 counters[jss::rpc] = rpcobj;
172 counters[jss::job_queue] = jqobj;
182 auto const jobs = [
this] {
187 for (
auto const& j : jobs)
192 auto const e = jq_.find(j.first);
199 jobj[jss::job] = e->second.label;
201 std::chrono::duration_cast<microseconds>(present - j.second)
210 methods.
reserve(methods_.size());
211 for (
auto const& m : methods_)
214 for (
auto m : methods)
217 methodobj[jss::method] = m.first;
219 std::chrono::duration_cast<microseconds>(present - m.second)
221 methodsArray.
append(methodobj);
225 current[jss::jobs] = jobsArray;
226 current[jss::methods] = methodsArray;
241 if (!boost::filesystem::is_directory(logDir))
243 boost::system::error_code ec;
244 boost::filesystem::create_directories(logDir, ec);
247 JLOG(
j_.
fatal()) <<
"Unable to create performance log "
249 << logDir <<
": " << ec.message();
260 <<
"Unable to open performance log " <<
setup_.
perfLog <<
".";
344 ++counter->second.sync.started;
369 startTime = e->second.second;
379 ++counter->second.sync.finished;
381 ++counter->second.sync.errored;
382 counter->second.sync.duration += std::chrono::duration_cast<microseconds>(
396 ++counter->second.sync.queued;
414 ++counter->second.sync.started;
415 counter->second.sync.queuedDuration += dur;
433 ++counter->second.sync.finished;
434 counter->second.sync.runningDuration += dur;
497 set(perfLog,
"perf_log", section);
500 setup.
perfLog = boost::filesystem::path(perfLog);
501 if (setup.
perfLog.is_relative())
504 boost::filesystem::absolute(setup.
perfLog, configDir);
521 return std::make_unique<PerfLogImp>(
522 setup, parent, journal, std::move(signalStop));