rippled
Loading...
Searching...
No Matches
PerfLog.h
1#ifndef XRPL_CORE_PERFLOG_H
2#define XRPL_CORE_PERFLOG_H
3
4#include <xrpl/basics/BasicConfig.h>
5#include <xrpl/core/JobTypes.h>
6#include <xrpl/json/json_value.h>
7
8#include <boost/filesystem.hpp>
9
10#include <chrono>
11#include <cstdint>
12#include <functional>
13#include <memory>
14#include <string>
15
16namespace beast {
17class Journal;
18}
19
20namespace xrpl {
21class Application;
22namespace perf {
23
32{
33public:
41
45 struct Setup
46 {
47 boost::filesystem::path perfLog;
48 // log_interval is in milliseconds to support faster testing.
50 };
51
52 virtual ~PerfLog() = default;
53
54 virtual void
56 {
57 }
58
59 virtual void
61 {
62 }
63
70 virtual void
71 rpcStart(std::string const& method, std::uint64_t requestId) = 0;
72
79 virtual void
80 rpcFinish(std::string const& method, std::uint64_t requestId) = 0;
81
88 virtual void
89 rpcError(std::string const& method, std::uint64_t requestId) = 0;
90
96 virtual void
97 jobQueue(JobType const type) = 0;
98
107 virtual void
109 JobType const type,
110 microseconds dur,
111 steady_time_point startTime,
112 int instance) = 0;
113
121 virtual void
122 jobFinish(JobType const type, microseconds dur, int instance) = 0;
123
129 virtual Json::Value
130 countersJson() const = 0;
131
137 virtual Json::Value
138 currentJson() const = 0;
139
145 virtual void
146 resizeJobs(int const resize) = 0;
147
151 virtual void
152 rotate() = 0;
153};
154
156setup_PerfLog(Section const& section, boost::filesystem::path const& configDir);
157
160 PerfLog::Setup const& setup,
161 Application& app,
162 beast::Journal journal,
163 std::function<void()>&& signalStop);
164
165template <typename Func, class Rep, class Period>
166auto
168 Func&& func,
169 std::string const& actionDescription,
171 beast::Journal const& journal)
172{
173 auto start_time = std::chrono::high_resolution_clock::now();
174
175 auto result = func();
176
178 auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(
179 end_time - start_time);
180 if (duration > maxDelay)
181 {
182 JLOG(journal.warn())
183 << actionDescription << " took " << duration.count() << " ms";
184 }
185
186 return result;
187}
188
189} // namespace perf
190} // namespace xrpl
191
192#endif // XRPL_CORE_PERFLOG_H
Represents a JSON value.
Definition json_value.h:131
A generic endpoint for log messages.
Definition Journal.h:41
Stream warn() const
Definition Journal.h:321
Holds a collection of configuration values.
Definition BasicConfig.h:26
Singleton class that maintains performance counters and optionally writes Json-formatted data to a di...
Definition PerfLog.h:32
virtual void start()
Definition PerfLog.h:55
virtual void jobFinish(JobType const type, microseconds dur, int instance)=0
Log job finishing.
virtual ~PerfLog()=default
std::chrono::seconds seconds
Definition PerfLog.h:38
virtual Json::Value currentJson() const =0
Render currently executing jobs and RPC calls and durations in Json.
virtual void rpcFinish(std::string const &method, std::uint64_t requestId)=0
Log successful finish of RPC call.
virtual void jobQueue(JobType const type)=0
Log queued job.
virtual void resizeJobs(int const resize)=0
Ensure enough room to store each currently executing job.
virtual void stop()
Definition PerfLog.h:60
virtual void jobStart(JobType const type, microseconds dur, steady_time_point startTime, int instance)=0
Log job executing.
virtual void rpcStart(std::string const &method, std::uint64_t requestId)=0
Log start of RPC call.
virtual Json::Value countersJson() const =0
Render performance counters in Json.
virtual void rotate()=0
Rotate perf log file.
virtual void rpcError(std::string const &method, std::uint64_t requestId)=0
Log errored RPC call.
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 &section, boost::filesystem::path const &configDir)
auto measureDurationAndLog(Func &&func, std::string const &actionDescription, std::chrono::duration< Rep, Period > maxDelay, beast::Journal const &journal)
Definition PerfLog.h:167
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:6
JobType
Definition Job.h:15
Configuration from [perf] section of xrpld.cfg.
Definition PerfLog.h:46
boost::filesystem::path perfLog
Definition PerfLog.h:47
milliseconds logInterval
Definition PerfLog.h:49