#include <ace/Stats.h>
class ACE_Stats {
public:
ACE_Stats (void);
int sample (const ACE_INT32 value);
ACE_UINT32 samples (void) const;
ACE_INT32 min_value (void) const;
ACE_INT32 max_value (void) const;
void mean ( ACE_Stats_Value &mean, const ACE_UINT32 scale_factor = 1 );
int std_dev ( ACE_Stats_Value &std_dev, const ACE_UINT32 scale_factor = 1 );
int print_summary ( const u_int precision, const ACE_UINT32 scale_factor = 1, FILE * = stdout ) const;
void reset ();
void dump (void) const;
static void quotient ( const ACE_UINT64 dividend, const ACE_UINT32 divisor, ACE_Stats_Value "ient );
static void quotient ( const ACE_Stats_Value ÷nd, const ACE_UINT32 divisor, ACE_Stats_Value "ient );
static void square_root ( const ACE_UINT64 n, ACE_Stats_Value &square_root );
private:
u_int overflow_;
ACE_UINT32 number_of_samples_;
ACE_INT32 min_;
ACE_INT32 max_;
ACE_Stats_Value cached_mean_;
ACE_Unbounded_Queue <ACE_INT32> samples_;
};
Example usage:
ACE_Stats stats;
for (u_int i = 0; i
n; ++i)
{
const ACE_UINT32 sample = /* ... */;
stats.sample (sample);
}
stats.print_summary (3);
PUBLIC MEMBERS
ACE_Stats (void);
Default constructor.
int sample (const ACE_INT32 value);
Provide a new sample. Returns 0 on success, -1 if it fails due
to running out of memory.
ACE_UINT32 samples (void) const;
Access the number of samples provided so far.
ACE_INT32 min_value (void) const;
Value of the minimum sample provided so far.
ACE_INT32 max_value (void) const;
Value of the maximum sample provided so far.
void mean (ACE_Stats_Value &mean, const ACE_UINT32 scale_factor = 1);
Access the mean of all samples provided so far. The fractional
part is to the specified number of digits. E.g., 3 fractional
digits specifies that the fractional part is in thousandths.
int std_dev (
ACE_Stats_Value &std_dev,
const ACE_UINT32 scale_factor = 1
);
Access the standard deviation, whole and fractional parts. See
description of
mean
method for argument descriptions.
int print_summary (
const u_int precision,
const ACE_UINT32 scale_factor = 1,
FILE * = stdout
) const;
Print summary statistics. If scale_factor is not 1, then the
results are divided by it, i.e., each of the samples is scaled
down by it. Returns -1 if internal overflow had been reached.
If that happens, you might retry with a smaller precision.
void reset ();
Initialize internal state.
void dump (void) const;
Print summary statictics to stdout.
static void quotient (
const ACE_UINT64 dividend,
const ACE_UINT32 divisor,
ACE_Stats_Value "ient
);
Utility division function, for ACE_UINT64 dividend.
static void quotient (
const ACE_Stats_Value ÷nd,
const ACE_UINT32 divisor,
ACE_Stats_Value "ient
);
Utility division function, for ACE_Stats_Value dividend.
static void square_root (
const ACE_UINT64 n,
ACE_Stats_Value &square_root
);
Sqrt function, which uses an oversimplified version of Newton's
method. It's not fast, but it doesn't require floating point
support.
PRIVATE MEMBERS
u_int overflow_;
Internal indication of whether there has been overflow.
ACE_UINT32 number_of_samples_;
Number of samples.
ACE_INT32 min_;
Minimum sample value.
ACE_INT32 max_;
Maximum sample value.
ACE_Stats_Value cached_mean_;
Cached mean value, because std_dev () needs to know the mean.
ACE_Unbounded_Queue <ACE_INT32> samples_;
The samples.
AUTHORS
David L. Levine
LIBRARY
ace