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 <boost/filesystem.hpp>
25 #include <ripple/json/json_value.h>
26 #include <chrono>
27 #include <cstdint>
28 #include <functional>
29 #include <memory>
30 #include <string>
31 
32 namespace beast { class Journal; }
33 
34 namespace ripple {
35 namespace perf {
36 
44 class PerfLog
45 {
46 public:
54 
58  struct Setup
59  {
60  boost::filesystem::path perfLog;
61  // log_interval is in milliseconds to support faster testing.
63  };
64 
65  virtual ~PerfLog() = default;
66 
73  virtual void rpcStart(std::string const& method,
74  std::uint64_t requestId) = 0;
75 
82  virtual void rpcFinish(std::string const& method,
83  std::uint64_t requestId) = 0;
84 
91  virtual void rpcError(std::string const& method,
92  std::uint64_t requestId) = 0;
93 
99  virtual void jobQueue(JobType const type) = 0;
100 
109  virtual void jobStart(JobType const type,
110  microseconds dur,
111  steady_time_point startTime,
112  int instance) = 0;
113 
121  virtual void jobFinish(JobType const type,
122  microseconds dur, int instance) = 0;
123 
129  virtual Json::Value countersJson() const = 0;
130 
136  virtual Json::Value currentJson() const = 0;
137 
143  virtual void resizeJobs(int const resize) = 0;
144 
148  virtual void rotate() = 0;
149 };
150 
151 } //perf
152 
153 class Section;
154 class Stoppable;
155 
156 namespace perf {
157 
158 PerfLog::Setup setup_PerfLog(Section const& section,
159  boost::filesystem::path const& configDir);
160 
162  PerfLog::Setup const& setup,
163  Stoppable& parent,
164  beast::Journal journal,
165  std::function<void()>&& signalStop);
166 
167 } // perf
168 } // ripple
169 
170 #endif //RIPPLE_BASICS_PERFLOG_H
ripple::perf::PerfLog::microseconds
std::chrono::microseconds microseconds
Definition: PerfLog.h:53
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:60
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:44
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:517
ripple::perf::PerfLog::Setup
Configuration from [perf] section of rippled.cfg.
Definition: PerfLog.h:58
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:60
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:495
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:49
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:51
std::unique_ptr
STL class.
ripple::perf::PerfLog::Setup::logInterval
milliseconds logInterval
Definition: PerfLog.h:62
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:141
beast
Definition: base_uint.h:582
string