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/JobTypes.h>
24 #include <ripple/json/json_value.h>
25 #include <boost/filesystem.hpp>
26 #include <chrono>
27 #include <cstdint>
28 #include <functional>
29 #include <memory>
30 #include <string>
31 
32 namespace beast {
33 class Journal;
34 }
35 
36 namespace ripple {
37 namespace perf {
38 
46 class PerfLog
47 {
48 public:
56 
60  struct Setup
61  {
62  boost::filesystem::path perfLog;
63  // log_interval is in milliseconds to support faster testing.
65  };
66 
67  virtual ~PerfLog() = default;
68 
75  virtual void
76  rpcStart(std::string const& method, std::uint64_t requestId) = 0;
77 
84  virtual void
85  rpcFinish(std::string const& method, std::uint64_t requestId) = 0;
86 
93  virtual void
94  rpcError(std::string const& method, std::uint64_t requestId) = 0;
95 
101  virtual void
102  jobQueue(JobType const type) = 0;
103 
112  virtual void
113  jobStart(
114  JobType const type,
115  microseconds dur,
116  steady_time_point startTime,
117  int instance) = 0;
118 
126  virtual void
127  jobFinish(JobType const type, microseconds dur, int instance) = 0;
128 
134  virtual Json::Value
135  countersJson() const = 0;
136 
142  virtual Json::Value
143  currentJson() const = 0;
144 
150  virtual void
151  resizeJobs(int const resize) = 0;
152 
156  virtual void
157  rotate() = 0;
158 };
159 
160 } // namespace perf
161 
162 class Section;
163 class Stoppable;
164 
165 namespace perf {
166 
167 PerfLog::Setup
168 setup_PerfLog(Section const& section, boost::filesystem::path const& configDir);
169 
172  PerfLog::Setup const& setup,
173  Stoppable& parent,
174  beast::Journal journal,
175  std::function<void()>&& signalStop);
176 
177 } // namespace perf
178 } // namespace ripple
179 
180 #endif // RIPPLE_BASICS_PERFLOG_H
ripple::perf::PerfLog::microseconds
std::chrono::microseconds microseconds
Definition: PerfLog.h:55
std::chrono::system_clock
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:62
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:46
std::function
ripple::perf::make_PerfLog
std::unique_ptr< PerfLog > make_PerfLog(PerfLog::Setup const &setup, Stoppable &parent, beast::Journal journal, std::function< void()> &&signalStop)
Definition: PerfLogImp.cpp:515
ripple::perf::PerfLog::Setup
Configuration from [perf] section of rippled.cfg.
Definition: PerfLog.h:60
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.
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:493
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:51
ripple::perf::PerfLog::rotate
virtual void rotate()=0
Rotate perf log file.
ripple::JobType
JobType
Definition: Job.h:33
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:53
std::unique_ptr
STL class.
ripple::perf::PerfLog::Setup::logInterval
milliseconds logInterval
Definition: PerfLog.h:64
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:585
string