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#include <boost/filesystem.hpp>
27#include <chrono>
28#include <cstdint>
29#include <functional>
30#include <memory>
31#include <string>
32
33namespace beast {
34class Journal;
35}
36
37namespace ripple {
38class Application;
39namespace perf {
40
49{
50public:
58
62 struct Setup
63 {
64 boost::filesystem::path perfLog;
65 // log_interval is in milliseconds to support faster testing.
67 };
68
69 virtual ~PerfLog() = default;
70
71 virtual void
73 {
74 }
75
76 virtual void
78 {
79 }
80
87 virtual void
88 rpcStart(std::string const& method, std::uint64_t requestId) = 0;
89
96 virtual void
97 rpcFinish(std::string const& method, std::uint64_t requestId) = 0;
98
105 virtual void
106 rpcError(std::string const& method, std::uint64_t requestId) = 0;
107
113 virtual void
114 jobQueue(JobType const type) = 0;
115
124 virtual void
126 JobType const type,
127 microseconds dur,
128 steady_time_point startTime,
129 int instance) = 0;
130
138 virtual void
139 jobFinish(JobType const type, microseconds dur, int instance) = 0;
140
146 virtual Json::Value
147 countersJson() const = 0;
148
154 virtual Json::Value
155 currentJson() const = 0;
156
162 virtual void
163 resizeJobs(int const resize) = 0;
164
168 virtual void
169 rotate() = 0;
170};
171
173setup_PerfLog(Section const& section, boost::filesystem::path const& configDir);
174
177 PerfLog::Setup const& setup,
178 Application& app,
179 beast::Journal journal,
180 std::function<void()>&& signalStop);
181
182template <typename Func, class Rep, class Period>
183auto
185 Func&& func,
186 const std::string& actionDescription,
188 const beast::Journal& journal)
189{
190 auto start_time = std::chrono::high_resolution_clock::now();
191
192 auto result = func();
193
195 auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(
196 end_time - start_time);
197 if (duration > maxDelay)
198 {
199 JLOG(journal.warn())
200 << actionDescription << " took " << duration.count() << " ms";
201 }
202
203 return result;
204}
205
206} // namespace perf
207} // namespace ripple
208
209#endif // RIPPLE_BASICS_PERFLOG_H
Represents a JSON value.
Definition: json_value.h:147
A generic endpoint for log messages.
Definition: Journal.h:59
Stream warn() const
Definition: Journal.h:329
Holds a collection of configuration values.
Definition: BasicConfig.h:46
Singleton class that maintains performance counters and optionally writes Json-formatted data to a di...
Definition: PerfLog.h:49
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:77
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:72
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:55
virtual ~PerfLog()=default
PerfLog::Setup setup_PerfLog(Section const &section, boost::filesystem::path const &configDir)
Definition: PerfLogImp.cpp:483
auto measureDurationAndLog(Func &&func, const std::string &actionDescription, std::chrono::duration< Rep, Period > maxDelay, const beast::Journal &journal)
Definition: PerfLog.h:184
std::unique_ptr< PerfLog > make_PerfLog(PerfLog::Setup const &setup, Application &app, beast::Journal journal, std::function< void()> &&signalStop)
Definition: PerfLogImp.cpp:505
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:26
JobType
Definition: Job.h:35
Configuration from [perf] section of rippled.cfg.
Definition: PerfLog.h:63
boost::filesystem::path perfLog
Definition: PerfLog.h:64
milliseconds logInterval
Definition: PerfLog.h:66