rippled
Loading...
Searching...
No Matches
PerfLog.h
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2018 Ripple Labs Inc.
5
6 Permission to use, copy, modify, and/or distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#ifndef RIPPLE_BASICS_PERFLOG_H
21#define RIPPLE_BASICS_PERFLOG_H
22
23#include <xrpld/core/Config.h>
24#include <xrpld/core/JobTypes.h>
25#include <xrpl/json/json_value.h>
26
27#include <boost/filesystem.hpp>
28
29#include <chrono>
30#include <cstdint>
31#include <functional>
32#include <memory>
33#include <string>
34
35namespace beast {
36class Journal;
37}
38
39namespace ripple {
40class Application;
41namespace perf {
42
51{
52public:
60
64 struct Setup
65 {
66 boost::filesystem::path perfLog;
67 // log_interval is in milliseconds to support faster testing.
69 };
70
71 virtual ~PerfLog() = default;
72
73 virtual void
75 {
76 }
77
78 virtual void
80 {
81 }
82
89 virtual void
90 rpcStart(std::string const& method, std::uint64_t requestId) = 0;
91
98 virtual void
99 rpcFinish(std::string const& method, std::uint64_t requestId) = 0;
100
107 virtual void
108 rpcError(std::string const& method, std::uint64_t requestId) = 0;
109
115 virtual void
116 jobQueue(JobType const type) = 0;
117
126 virtual void
128 JobType const type,
129 microseconds dur,
130 steady_time_point startTime,
131 int instance) = 0;
132
140 virtual void
141 jobFinish(JobType const type, microseconds dur, int instance) = 0;
142
148 virtual Json::Value
149 countersJson() const = 0;
150
156 virtual Json::Value
157 currentJson() const = 0;
158
164 virtual void
165 resizeJobs(int const resize) = 0;
166
170 virtual void
171 rotate() = 0;
172};
173
175setup_PerfLog(Section const& section, boost::filesystem::path const& configDir);
176
179 PerfLog::Setup const& setup,
180 Application& app,
181 beast::Journal journal,
182 std::function<void()>&& signalStop);
183
184template <typename Func, class Rep, class Period>
185auto
187 Func&& func,
188 const std::string& actionDescription,
190 const beast::Journal& journal)
191{
192 auto start_time = std::chrono::high_resolution_clock::now();
193
194 auto result = func();
195
197 auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(
198 end_time - start_time);
199 if (duration > maxDelay)
200 {
201 JLOG(journal.warn())
202 << actionDescription << " took " << duration.count() << " ms";
203 }
204
205 return result;
206}
207
208} // namespace perf
209} // namespace ripple
210
211#endif // RIPPLE_BASICS_PERFLOG_H
Represents a JSON value.
Definition: json_value.h:148
A generic endpoint for log messages.
Definition: Journal.h:60
Stream warn() const
Definition: Journal.h:340
Holds a collection of configuration values.
Definition: BasicConfig.h:45
Singleton class that maintains performance counters and optionally writes Json-formatted data to a di...
Definition: PerfLog.h:51
virtual void jobFinish(JobType const type, microseconds dur, int instance)=0
Log job finishing.
virtual void jobStart(JobType const type, microseconds dur, steady_time_point startTime, int instance)=0
Log job executing.
virtual void stop()
Definition: PerfLog.h:79
virtual void rpcFinish(std::string const &method, std::uint64_t requestId)=0
Log successful finish of RPC call.
virtual void rpcStart(std::string const &method, std::uint64_t requestId)=0
Log start 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 Json::Value currentJson() const =0
Render currently executing jobs and RPC calls and durations in Json.
virtual void start()
Definition: PerfLog.h:74
virtual void rotate()=0
Rotate perf log file.
virtual Json::Value countersJson() const =0
Render performance counters in Json.
virtual void rpcError(std::string const &method, std::uint64_t requestId)=0
Log errored RPC call.
std::chrono::seconds seconds
Definition: PerfLog.h:57
virtual ~PerfLog()=default
PerfLog::Setup setup_PerfLog(Section const &section, boost::filesystem::path const &configDir)
Definition: PerfLogImp.cpp:481
auto measureDurationAndLog(Func &&func, const std::string &actionDescription, std::chrono::duration< Rep, Period > maxDelay, const beast::Journal &journal)
Definition: PerfLog.h:186
std::unique_ptr< PerfLog > make_PerfLog(PerfLog::Setup const &setup, Application &app, beast::Journal journal, std::function< void()> &&signalStop)
Definition: PerfLogImp.cpp:503
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:26
JobType
Definition: Job.h:34
Configuration from [perf] section of rippled.cfg.
Definition: PerfLog.h:65
boost::filesystem::path perfLog
Definition: PerfLog.h:66
milliseconds logInterval
Definition: PerfLog.h:68