LogCabin
|
Manages creation of server statistics, which are used for diagnostics. More...
#include <ServerStats.h>
Classes | |
struct | Deferred |
Members that are constructed later, during enable(). More... | |
class | Lock |
Provides read/write access to stats, protected against concurrent access. More... | |
class | SignalHandler |
Asks statsDumper thread to dumps stats to the debug log (NOTICE level) on SIGUSR1 signal. More... | |
Public Member Functions | |
ServerStats (Globals &globals) | |
Constructor. | |
~ServerStats () | |
Destructor. | |
void | enable () |
Called after Globals are initialized to finish setting up this class. | |
void | exit () |
Prepare for shutdown. | |
void | dumpToDebugLog () const |
Write the current stats to the debug log (NOTICE level). | |
Protocol::ServerStats | getCurrent () const |
Calculate and return the current server stats. | |
Private Types | |
typedef Core::Time::SteadyClock | SteadyClock |
Used to dump stats periodically. | |
typedef Core::Time::SystemClock | SystemClock |
Used to include wall time in stats. | |
Private Member Functions | |
void | dumpToDebugLog (std::unique_lock< Core::Mutex > &lockGuard) const |
See public dumpToDebugLog() above. | |
Protocol::ServerStats | getCurrent (std::unique_lock< Core::Mutex > &lockGuard) const |
See public getCurrent() above. | |
void | statsDumperMain () |
Private Attributes | |
Globals & | globals |
Server-wide objects. | |
Core::Mutex | mutex |
Protects all of the following members of this class. | |
Core::ConditionVariable | statsDumpRequested |
Notified when isStatsDumpRequested is set and when exiting is set. | |
bool | exiting |
Set to true when statsDumper should exit. | |
bool | isStatsDumpRequested |
Set to true when statsDumper should write the entire stats to the debug log. | |
Core::Time::SteadyClock::time_point | lastDumped |
The last time when the stats were written to the debug log. | |
Protocol::ServerStats | stats |
Partially filled-in structure that is copied as the basis of all calls to getCurrent(). | |
std::unique_ptr< Deferred > | deferred |
See Deferred. |
Manages creation of server statistics, which are used for diagnostics.
Server statistics are gathered in two ways. First, this object maintains a stats structure that modules can fill in by acquiring a Lock and modifying directly. This stats structure is copied every time stats are requested. Second, when stats are requested, getCurrent() will ask certain modules (such as RaftConsensus) to fill in the current information into a copy of the stats structure.
Definition at line 45 of file ServerStats.h.
typedef Core::Time::SteadyClock LogCabin::Server::ServerStats::SteadyClock [private] |
Used to dump stats periodically.
Definition at line 104 of file ServerStats.h.
typedef Core::Time::SystemClock LogCabin::Server::ServerStats::SystemClock [private] |
Used to include wall time in stats.
Definition at line 109 of file ServerStats.h.
LogCabin::Server::ServerStats::ServerStats | ( | Globals & | globals | ) | [explicit] |
Constructor.
Definition at line 86 of file ServerStats.cc.
Destructor.
Definition at line 98 of file ServerStats.cc.
Called after Globals are initialized to finish setting up this class.
Attaches signal handler and starts stats dumper thread. Starts calling other modules for their state in getCurrent().
Definition at line 103 of file ServerStats.cc.
void LogCabin::Server::ServerStats::exit | ( | ) |
Prepare for shutdown.
Waits for the statsDumper thread to exit, and destroys the deferred object (the opposite of enable()).
Definition at line 114 of file ServerStats.cc.
void LogCabin::Server::ServerStats::dumpToDebugLog | ( | ) | const |
Write the current stats to the debug log (NOTICE level).
This is preferred over calling getCurrent() followed by NOTICE(), since it will arrange for the next periodic stats dump to be delayed (there's not much sense in a periodic stats dump immediately following a manual stats dump).
Definition at line 127 of file ServerStats.cc.
Protocol::ServerStats LogCabin::Server::ServerStats::getCurrent | ( | ) | const |
Calculate and return the current server stats.
Definition at line 134 of file ServerStats.cc.
void LogCabin::Server::ServerStats::dumpToDebugLog | ( | std::unique_lock< Core::Mutex > & | lockGuard | ) | const [private] |
See public dumpToDebugLog() above.
Internally releases and reacquires the lock for concurrency and to avoid deadlock.
Definition at line 143 of file ServerStats.cc.
Protocol::ServerStats LogCabin::Server::ServerStats::getCurrent | ( | std::unique_lock< Core::Mutex > & | lockGuard | ) | const [private] |
See public getCurrent() above.
Internally releases and reacquires the lock for concurrency and to avoid deadlock.
Definition at line 155 of file ServerStats.cc.
void LogCabin::Server::ServerStats::statsDumperMain | ( | ) | [private] |
Definition at line 173 of file ServerStats.cc.
Globals& LogCabin::Server::ServerStats::globals [private] |
Server-wide objects.
Definition at line 186 of file ServerStats.h.
Core::Mutex LogCabin::Server::ServerStats::mutex [mutable, private] |
Protects all of the following members of this class.
Definition at line 191 of file ServerStats.h.
Notified when isStatsDumpRequested is set and when exiting is set.
statsDumper waits on this.
Definition at line 197 of file ServerStats.h.
bool LogCabin::Server::ServerStats::exiting [private] |
Set to true when statsDumper should exit.
Definition at line 202 of file ServerStats.h.
bool LogCabin::Server::ServerStats::isStatsDumpRequested [mutable, private] |
Set to true when statsDumper should write the entire stats to the debug log.
Mutable so that it can be reset to false in const methods such as dumpToDebugLog().
Definition at line 209 of file ServerStats.h.
Core::Time::SteadyClock::time_point LogCabin::Server::ServerStats::lastDumped [mutable, private] |
The last time when the stats were written to the debug log.
Monotonically increases.
Definition at line 215 of file ServerStats.h.
Protocol::ServerStats LogCabin::Server::ServerStats::stats [private] |
Partially filled-in structure that is copied as the basis of all calls to getCurrent().
Definition at line 221 of file ServerStats.h.
std::unique_ptr<Deferred> LogCabin::Server::ServerStats::deferred [private] |
See Deferred.
If non-NULL, enabled() has already been called, and other modules should be queried for stats during getCurrent().
Definition at line 227 of file ServerStats.h.