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
26#include <xrpl/json/json_value.h>
27
28#include <boost/filesystem.hpp>
29
30#include <chrono>
31#include <cstdint>
32#include <functional>
33#include <memory>
34#include <string>
35
36namespace beast {
37class Journal;
38}
39
40namespace ripple {
41class Application;
42namespace perf {
43
52{
53public:
61
65 struct Setup
66 {
67 boost::filesystem::path perfLog;
68 // log_interval is in milliseconds to support faster testing.
70 };
71
72 virtual ~PerfLog() = default;
73
74 virtual void
76 {
77 }
78
79 virtual void
81 {
82 }
83
90 virtual void
91 rpcStart(std::string const& method, std::uint64_t requestId) = 0;
92
99 virtual void
100 rpcFinish(std::string const& method, std::uint64_t requestId) = 0;
101
108 virtual void
109 rpcError(std::string const& method, std::uint64_t requestId) = 0;
110
116 virtual void
117 jobQueue(JobType const type) = 0;
118
127 virtual void
129 JobType const type,
130 microseconds dur,
131 steady_time_point startTime,
132 int instance) = 0;
133
141 virtual void
142 jobFinish(JobType const type, microseconds dur, int instance) = 0;
143
149 virtual Json::Value
150 countersJson() const = 0;
151
157 virtual Json::Value
158 currentJson() const = 0;
159
165 virtual void
166 resizeJobs(int const resize) = 0;
167
171 virtual void
172 rotate() = 0;
173};
174
176setup_PerfLog(Section const& section, boost::filesystem::path const& configDir);
177
180 PerfLog::Setup const& setup,
181 Application& app,
182 beast::Journal journal,
183 std::function<void()>&& signalStop);
184
185template <typename Func, class Rep, class Period>
186auto
188 Func&& func,
189 std::string const& actionDescription,
191 beast::Journal const& journal)
192{
193 auto start_time = std::chrono::high_resolution_clock::now();
194
195 auto result = func();
196
198 auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(
199 end_time - start_time);
200 if (duration > maxDelay)
201 {
202 JLOG(journal.warn())
203 << actionDescription << " took " << duration.count() << " ms";
204 }
205
206 return result;
207}
208
209} // namespace perf
210} // namespace ripple
211
212#endif // RIPPLE_BASICS_PERFLOG_H
Represents a JSON value.
Definition: json_value.h:149
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:52
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:80
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:75
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:58
virtual ~PerfLog()=default
PerfLog::Setup setup_PerfLog(Section const &section, boost::filesystem::path const &configDir)
Definition: PerfLogImp.cpp:482
auto measureDurationAndLog(Func &&func, std::string const &actionDescription, std::chrono::duration< Rep, Period > maxDelay, beast::Journal const &journal)
Definition: PerfLog.h:187
std::unique_ptr< PerfLog > make_PerfLog(PerfLog::Setup const &setup, Application &app, beast::Journal journal, std::function< void()> &&signalStop)
Definition: PerfLogImp.cpp:504
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:25
JobType
Definition: Job.h:35
Configuration from [perf] section of rippled.cfg.
Definition: PerfLog.h:66
boost::filesystem::path perfLog
Definition: PerfLog.h:67
milliseconds logInterval
Definition: PerfLog.h:69