rippled
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 <ripple/core/Config.h>
24 #include <ripple/core/JobTypes.h>
25 #include <ripple/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 
33 namespace beast {
34 class Journal;
35 }
36 
37 namespace ripple {
38 namespace perf {
39 
47 class PerfLog
48 {
49 public:
57 
61  struct Setup
62  {
63  boost::filesystem::path perfLog;
64  // log_interval is in milliseconds to support faster testing.
66  };
67 
68  virtual ~PerfLog() = default;
69 
70  virtual void
72  {
73  }
74 
75  virtual void
76  stop()
77  {
78  }
79 
86  virtual void
87  rpcStart(std::string const& method, std::uint64_t requestId) = 0;
88 
95  virtual void
96  rpcFinish(std::string const& method, std::uint64_t requestId) = 0;
97 
104  virtual void
105  rpcError(std::string const& method, std::uint64_t requestId) = 0;
106 
112  virtual void
113  jobQueue(JobType const type) = 0;
114 
123  virtual void
124  jobStart(
125  JobType const type,
126  microseconds dur,
127  steady_time_point startTime,
128  int instance) = 0;
129 
137  virtual void
138  jobFinish(JobType const type, microseconds dur, int instance) = 0;
139 
145  virtual Json::Value
146  countersJson() const = 0;
147 
153  virtual Json::Value
154  currentJson() const = 0;
155 
161  virtual void
162  resizeJobs(int const resize) = 0;
163 
167  virtual void
168  rotate() = 0;
169 };
170 
171 PerfLog::Setup
172 setup_PerfLog(Section const& section, boost::filesystem::path const& configDir);
173 
176  PerfLog::Setup const& setup,
177  beast::Journal journal,
178  std::function<void()>&& signalStop);
179 
180 } // namespace perf
181 } // namespace ripple
182 
183 #endif // RIPPLE_BASICS_PERFLOG_H
ripple::perf::PerfLog::microseconds
std::chrono::microseconds microseconds
Definition: PerfLog.h:56
std::chrono::system_clock
ripple::Section
Holds a collection of configuration values.
Definition: BasicConfig.h:42
std::chrono::steady_clock
ripple::perf::PerfLog::rpcError
virtual void rpcError(std::string const &method, std::uint64_t requestId)=0
Log errored RPC call.
std::string
STL class.
ripple::perf::PerfLog::Setup::perfLog
boost::filesystem::path perfLog
Definition: PerfLog.h:63
functional
std::chrono::seconds
ripple::perf::PerfLog
Singleton class that maintains performance counters and optionally writes Json-formatted data to a di...
Definition: PerfLog.h:47
std::function
ripple::perf::PerfLog::Setup
Configuration from [perf] section of rippled.cfg.
Definition: PerfLog.h:61
ripple::perf::make_PerfLog
std::unique_ptr< PerfLog > make_PerfLog(PerfLog::Setup const &setup, beast::Journal journal, std::function< void()> &&signalStop)
Definition: PerfLogImp.cpp:492
ripple::perf::PerfLog::stop
virtual void stop()
Definition: PerfLog.h:76
chrono
ripple::perf::PerfLog::resizeJobs
virtual void resizeJobs(int const resize)=0
Ensure enough room to store each currently executing job.
std::chrono::time_point
cstdint
beast::Journal
A generic endpoint for log messages.
Definition: Journal.h:58
std::uint64_t
ripple::perf::PerfLog::jobQueue
virtual void jobQueue(JobType const type)=0
Log queued job.
ripple::perf::PerfLog::jobStart
virtual void jobStart(JobType const type, microseconds dur, steady_time_point startTime, int instance)=0
Log job executing.
ripple::perf::PerfLog::start
virtual void start()
Definition: PerfLog.h:71
memory
ripple::perf::PerfLog::rpcStart
virtual void rpcStart(std::string const &method, std::uint64_t requestId)=0
Log start of RPC call.
ripple::perf::PerfLog::~PerfLog
virtual ~PerfLog()=default
ripple::perf::setup_PerfLog
PerfLog::Setup setup_PerfLog(Section const &section, boost::filesystem::path const &configDir)
Definition: PerfLogImp.cpp:470
ripple::perf::PerfLog::countersJson
virtual Json::Value countersJson() const =0
Render performance counters in Json.
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::perf::PerfLog::steady_time_point
std::chrono::time_point< steady_clock > steady_time_point
Definition: PerfLog.h:52
ripple::perf::PerfLog::rotate
virtual void rotate()=0
Rotate perf log file.
ripple::JobType
JobType
Definition: Job.h:34
ripple::perf::PerfLog::currentJson
virtual Json::Value currentJson() const =0
Render currently executing jobs and RPC calls and durations in Json.
ripple::perf::PerfLog::seconds
std::chrono::seconds seconds
Definition: PerfLog.h:54
std::unique_ptr
STL class.
ripple::perf::PerfLog::Setup::logInterval
milliseconds logInterval
Definition: PerfLog.h:65
ripple::perf::PerfLog::rpcFinish
virtual void rpcFinish(std::string const &method, std::uint64_t requestId)=0
Log successful finish of RPC call.
ripple::perf::PerfLog::jobFinish
virtual void jobFinish(JobType const type, microseconds dur, int instance)=0
Log job finishing.
Json::Value
Represents a JSON value.
Definition: json_value.h:145
beast
Definition: base_uint.h:657
string