Accumulator Class Reference

#include <Accumulator.h>

Collaboration diagram for Accumulator:

Collaboration graph
[legend]

List of all members.


Detailed Description

Simple class for accumulating basic statistics.

The accumulator is a new system to replace filters. Used for accumulating network statistics, byte counts, etc. It uses uint64_t to be useful in a wider variety of situations (without wrapping).

Common usage:

 // in main()
 Log::add(Accumulator::NETWORK_READ_SELECTOR);
 Accumulator::startLogging(); //causes periodic logs of the accumulator values

 // elsewhere
 Accumulator* a = Accumulator::Instance(Accumulator::NETWORK_READ);

 while (true) {
   int r = ::read(fd, buf, size);
   if (r > 0) {
     a->accumulate(r);
   }
 }

Each accumulator will log values with a selector of the format "Accumulator::SELECTORNAME". So there are two variables for the basic accumulators, one with the accumulator name, one with the selector name.

Definition at line 79 of file Accumulator.h.


Public Member Functions

void startTimer ()
 call to begin a timer for accumulators
void stopTimer ()
 disables the timer started with startTimer()
void accumulate (unsigned int amount)
 adds amount to the accumulator
void accumulateUnlocked (unsigned int amount)
 adds amount to the accumulator
uint64_t getAmount () const
 returns the current accumulator amount
uint64_t getDiff () const
 returns the amount since diff was last reset
uint64_t resetDiff ()
 returns the amount since diff was last reset and also resets diff.
uint64_t getStartTime ()
 returns the startTime for the timer
uint64_t getLastTime ()
 returns the lastTime for the timer

Static Public Member Functions

static AccumulatorInstance (const std::string &counter)
 returns an accumulator for the given counter string
static void dumpAll ()
 prints all values in text to selector "Accumulator::dumpAll"
static void logAll ()
 prints all values to their specific accumulator
static void startLogging (uint64_t interval=1 *1000 *1000)
 begins the logging thread
static void stopLogging ()
 ends the logging thread. Must br called after start for clean shutdown.

Static Public Attributes

static const std::string NETWORK_READ = "NETWORK_READ"
 accumulates bytes from all transports reading
static const std::string NETWORK_READ_SELECTOR = "Accumulator::NETWORK_READ"
 selector for Accumulator::NETWORK_READ
static const std::string NETWORK_WRITE = "NETWORK_WRITE"
 accumulates bytes from all transport writing
static const std::string NETWORK_WRITE_SELECTOR = "Accumulator::NETWORK_WRITE"
 selector for Accumulator::NETWORK_WRITE
static const std::string TCP_READ = "TCP_READ"
 accumulates bytes from all TCP transpot reads
static const std::string TCP_READ_SELECTOR = "Accumulator::TCP_READ"
 selector for Accumulator::TCP_READ
static const std::string TCP_WRITE = "TCP_WRITE"
 accumulates bytes from all TCP transport writes
static const std::string TCP_WRITE_SELECTOR = "Accumulator::TCP_WRITE"
 selector for Accumulator::TCP_WRITE
static const std::string UDP_READ = "UDP_READ"
 accumulates bytes from all UDP transpot reads
static const std::string UDP_READ_SELECTOR = "Accumulator::UDP_READ"
 selector for Accumulator::UDP_READ
static const std::string UDP_WRITE = "UDP_WRITE"
 accumulates bytes from all UDP transport writes
static const std::string UDP_WRITE_SELECTOR = "Accumulator::UDP_WRITE"
 selector for Accumulator::UDP_WRITE
static const std::string HTTP_CLIENT_READ = "HTTP_CLIENT_READ"
 accumulates bytes from HTTP reads
static const std::string HTTP_CLIENT_READ_SELECTOR
 selector for Accumulator::HTTP_CLIENT_READ
static const std::string HTTP_CLIENT_WRITE = "HTTP_CLIENT_WRITE"
 accumulates bytes from HTTP writing
static const std::string HTTP_CLIENT_WRITE_SELECTOR
 selector for Accumulator::HTTP_CLIENT_WRITE
static const std::string HTTP_SERVER_READ = "HTTP_SERVER_READ"
 accumulates bytes from HTTP server reading
static const std::string HTTP_SERVER_READ_SELECTOR
 selector for Accumulator::HTTP_SERVER_READ
static const std::string HTTP_SERVER_WRITE = "HTTP_SERVER_WRITE"
 accumulates bytes from HTTP server writing
static const std::string HTTP_SERVER_WRITE_SELECTOR
 selector for Accumulator::HTTP_SERVER_WRITE
static const std::string TRANSPORT_SEND = "TRANSPORT_SEND"
 accumulates bytes enqueued in the transports
static const std::string TRANSPORT_SEND_SELECTOR = "Accumulator::TRANSPORT_SEND"
 selector for Accumulator::TRANSPORT_SEND
static const std::string TRANSPORT_RECV = "TRANSPORT_RECV"
 accumulates bytes delivered from the transports
static const std::string TRANSPORT_RECV_SELECTOR = "Accumulator::TRANSPORT_RECV"
 selector for Accumulator::TRANSPORT_RECV
static const std::string TRANSPORT_RECV_CANCELED = "TRANSPORT_RECV_CANCELED"
 accumulates bytes received for cancelled messages
static const std::string TRANSPORT_RECV_CANCELED_SELECTOR = "Accumulator::TRANSPORT_RECV_CANCELED"
 selector for Accumulator::TRANSPORT_RECV_CANCELED
static const std::string FILE_WRITE = "FILE_WRITE"
 accumulates bytes written from the file util
static const std::string FILE_WRITE_SELECTOR = "Accumulator::FILE_WRITE"
 selector for Accumulator::FILE_WRITE
static const std::string APPLICATION_RECV = "APPLICATION_RECV"
 intended for use by applications to measure goodput received
static const std::string APPLICATION_RECV_SELECTOR = "Accumulator::APPLICATION_RECV"
 selector for Accumulator::APPLICATION_RECV
static const std::string APPLICATION_SEND = "APPLICATION_SEND"
 intended for use by applications to measure goodput sent
static const std::string APPLICATION_SEND_SELECTOR = "Accumulator::APPLICATION_SEND"
 selector for Accumulator::APPLICATION_SEND
static const std::string DB_WRITE_BYTES = "DB_WRITE_BYTES"
 accumulates bytes written from a db
static const std::string DB_WRITE_BYTES_SELECTOR = "Accumulator::DB_WRITE_BYTES"
 selector for Accumulator::DB_WRITE_BYTES
static const std::string DB_WRITE_COUNT = "DB_WRITE_COUNT"
 accumulates writes to a db
static const std::string DB_WRITE_COUNT_SELECTOR = "Accumulator::DB_WRITE_COUNT"
 selector for Accumulator::DB_WRITE_COUNT
static const std::string DB_ERASE_COUNT = "DB_ERASE_COUNT"
 accumulates erases to a db
static const std::string DB_ERASE_COUNT_SELECTOR = "Accumulator::DB_ERASE_COUNT"
 selector for Accumulator::DB_ERASE_COUNT

Member Function Documentation

void Accumulator::startTimer (  )  [inline]

call to begin a timer for accumulators

the first call to accumulateUnlocked() after startTimer() sets startTime (and each call sets lastTime). This is so you can see the amount accumulated between startTime and endtime, without bias for time passing without accumulation.

Clear the timer using stopTimer();

Definition at line 147 of file Accumulator.h.

void Accumulator::accumulate ( unsigned int  amount  )  [inline]

adds amount to the accumulator

Calls accumulateUnlocked() after acquring a lock. This is because it is unsafe to call accumulate multithreaded without synchronization.

Parameters:
amount amount to add to the accumulator

Definition at line 163 of file Accumulator.h.

References accumulateUnlocked().

void Accumulator::accumulateUnlocked ( unsigned int  amount  )  [inline]

adds amount to the accumulator

Caller promises to not call accumulateUnlocked from two threads at the same time. If that may occur, caller should use accumulate() instead.

Parameters:
amount amount to add to the accumulator

Definition at line 176 of file Accumulator.h.

References TimeUtil::timeu().

Referenced by accumulate().


The documentation for this class was generated from the following files:

Generated on Sat Oct 4 21:30:25 2008 for Mace Library by  doxygen 1.5.5