19 #ifndef PAGESPEED_KERNEL_BASE_STATISTICS_H_
20 #define PAGESPEED_KERNEL_BASE_STATISTICS_H_
24 #include "base/logging.h"
30 #include "pagespeed/kernel/base/thread_annotations.h"
32 namespace net_instaweb {
36 class StatisticsLogger;
47 virtual int64 Get()
const = 0;
50 virtual StringPiece
GetName()
const = 0;
53 int64
Add(int64 non_negative_delta) {
54 DCHECK_LE(0, non_negative_delta);
58 virtual void Clear() = 0;
77 virtual int64 Get()
const = 0;
80 virtual StringPiece
GetName()
const = 0;
92 virtual void Set(int64 value) = 0;
93 void Clear() { Set(0); }
94 int64 Add(int64 delta) {
return AddHelper(delta); }
119 void Set(int64 value);
120 int64 SetReturningPreviousValue(int64 value);
121 int64 AddHelper(int64 delta);
130 virtual int64 SetReturningPreviousValueLockHeld(int64 value) = 0;
135 int64 AddLockHeld(int64 delta);
142 virtual void Add(
double value) = 0;
144 virtual void Clear() = 0;
148 return CountInternal() == 0;
188 return PercentileInternal(perc);
190 double StandardDeviation() {
192 return StandardDeviationInternal();
196 return CountInternal();
200 return MaximumInternal();
204 return MinimumInternal();
234 virtual double PercentileInternal(
const double perc) = 0;
235 virtual double StandardDeviationInternal() = 0;
236 virtual double CountInternal() = 0;
237 virtual double MaximumInternal() = 0;
238 virtual double MinimumInternal() = 0;
240 virtual AbstractMutex* lock() = 0;
260 virtual void Add(
double value) {
276 virtual AbstractMutex* lock() LOCK_RETURNED(mutex_) {
return mutex_.get(); }
278 virtual double PercentileInternal(
const double perc) {
return 0.0; }
279 virtual double StandardDeviationInternal() {
return 0.0; }
280 virtual double CountInternal() EXCLUSIVE_LOCKS_REQUIRED(lock()) {
283 virtual double MaximumInternal() {
return 0.0; }
284 virtual double MinimumInternal() {
return 0.0; }
290 int count_ GUARDED_BY(mutex_);
301 enum Levels { TENSEC, MINUTE, HOUR, START };
304 virtual void IncBy(int64 delta) = 0;
307 virtual int64
Get(
int level) = 0;
309 virtual void Clear() = 0;
323 virtual int64
Get(
int level) {
327 if (level == START) {
334 return var_->Clear();
366 CHECK(var != NULL) <<
"UpDownCounter not found: " << name;
381 CHECK(var != NULL) <<
"Variable not found: " << name;
395 CHECK(hist != NULL) <<
"Histogram not found: " << name;
404 const StringPiece& name,
const StringPiece& group) = 0;
407 const StringPiece& name)
const = 0;
410 const StringPiece& name)
const {
412 CHECK(stat != NULL) <<
"TimedVariable not found: " << name;
423 virtual void RenderTimedVariables(
Writer* writer,
429 virtual void Clear() = 0;
int64 LookupValue(StringPiece stat_name)
virtual StringPiece GetName() const =0
virtual void SetMinValue(double value)
Set the minimum value allowed in histogram.
Definition: statistics.h:270
virtual int64 AddHelper(int64 delta)=0
This is virtual so that subclasses can add platform-specific atomicity.
virtual void IncBy(int64 delta)
Update the stat value. delta is in milliseconds.
Definition: statistics.h:318
Variable * GetVariable(const StringPiece &name) const
Find a variable from a name, aborting if not found.
Definition: statistics.h:379
double Average()
Returns average of the values added.
Definition: statistics.h:179
virtual Histogram * FindHistogram(const StringPiece &name) const =0
Find a histogram from a name, returning NULL if not found.
virtual void Dump(Writer *writer, MessageHandler *handler)=0
Dump the variable-values to a writer.
virtual UpDownCounter * AddUpDownCounter(const StringPiece &name)=0
virtual void Clear()=0
Throw away all data.
virtual double BucketStart(int index)=0
virtual Variable * FindVariable(const StringPiece &name) const =0
Find a variable from a name, returning NULL if not found.
virtual UpDownCounter * FindUpDownCounter(const StringPiece &name) const =0
Find a variable from a name, returning NULL if not found.
Definition: statistics.h:43
static const char kDefaultGroup[]
Default group for use with AddTimedVariable.
Definition: statistics.h:345
virtual TimedVariable * FindTimedVariable(const StringPiece &name) const =0
Find a TimedVariable from a name, returning NULL if not found.
CountHistogram(AbstractMutex *mutex)
Takes ownership of mutex.
virtual void Clear()
Throw away all data.
Definition: statistics.h:264
virtual double AverageInternal()
Note that these *Internal interfaces require the mutex to be held.
Definition: statistics.h:277
virtual void SetSuggestedNumBuckets(int i)=0
virtual int64 Get(int level)
Definition: statistics.h:323
virtual int64 SetReturningPreviousValue(int64 value)
Histogram * GetHistogram(const StringPiece &name) const
Find a histogram from a name, aborting if not found.
Definition: statistics.h:393
Base class for implementations of monitoring statistics.
Definition: statistics.h:342
GoogleString HtmlTableRow(const GoogleString &title, int index)
void WriteRawHistogramData(Writer *writer, MessageHandler *handler)
Abstract interface for implementing a mutex.
Definition: abstract_mutex.h:28
virtual void IncBy(int64 delta)=0
Update the stat value. delta is in milliseconds.
virtual double BucketCount(int index)
Value of a bucket.
Definition: statistics.h:286
virtual void DumpJson(Writer *writer, MessageHandler *message_handler)=0
Dump the variable-values in JSON format to a writer.
virtual UpDownCounter * AddGlobalUpDownCounter(const StringPiece &name)
TimedVariable implementation that only updates a basic UpDownCounter.
Definition: statistics.h:313
bool Empty()
True if the histogram is empty.
Definition: statistics.h:146
virtual void Clear()=0
Throw away all data.
virtual void Render(int index, Writer *writer, MessageHandler *handler)
virtual Variable * AddVariable(const StringPiece &name)=0
double Percentile(const double perc)
Definition: statistics.h:186
Definition: scoped_ptr.h:30
UpDownCounter * GetUpDownCounter(const StringPiece &name) const
Find a variable from a name, aborting if not found.
Definition: statistics.h:364
std::string GoogleString
PAGESPEED_KERNEL_BASE_STRING_H_.
Definition: string.h:24
#define ScopedMutex(x)
Definition: abstract_mutex.h:69
Levels
The intervals for which we keep stats.
Definition: statistics.h:301
virtual double BucketLimit(int index)
Upper bound of a bucket.
Definition: statistics.h:223
virtual const StringVector & HistogramNames()=0
Return the names of all the histograms for render.
virtual void Add(double value)
Record a value in its bucket.
Definition: statistics.h:260
Helper class for lexically scoped mutexing.
Definition: abstract_mutex.h:46
void SetLockHeld(int64 value)
Trivial implementation. But Count() returns a meaningful value.
Definition: statistics.h:255
virtual StatisticsLogger * console_logger()
Definition: statistics.h:435
virtual void Add(double value)=0
Record a value in its bucket.
Interface for writing bytes to an output stream.
Definition: writer.h:29
virtual void EnableNegativeBuckets()
Allow histogram have negative values.
Definition: statistics.h:269
virtual int NumBuckets()=0
Returns number of buckets the histogram actually has.
virtual void SetMaxValue(double value)=0
virtual void Clear()
Throw away all data.
Definition: statistics.h:333
TimedVariable * GetTimedVariable(const StringPiece &name) const
Find a TimedVariable from a name, aborting if not found.
Definition: statistics.h:409
virtual double BucketCount(int index)=0
Value of a bucket.
virtual void SetMaxValue(double value)
Definition: statistics.h:271
Definition: statistics.h:138
Definition: statistics.h:112
virtual void EnableNegativeBuckets()=0
Allow histogram have negative values.
Definition: statistics.h:73
virtual void RenderHistograms(Writer *writer, MessageHandler *handler)
Write all the histograms in this Statistic object to a writer.
Definition: message_handler.h:39
virtual StringPiece GetName() const =0
virtual int NumBuckets()
Returns number of buckets the histogram actually has.
Definition: statistics.h:268
virtual double BucketStart(int index)
Definition: statistics.h:285
Definition: statistics.h:298
virtual Histogram * AddHistogram(const StringPiece &name)=0
virtual int64 Get(int level)=0
virtual void SetSuggestedNumBuckets(int i)
Definition: statistics.h:272
virtual double AverageInternal()=0
Note that these *Internal interfaces require the mutex to be held.
virtual void SetMinValue(double value)=0
Set the minimum value allowed in histogram.
int64 Add(int64 non_negative_delta)
Adds 'delta' to the variable's value, returning the result.
Definition: statistics.h:53
virtual const std::map< GoogleString, StringVector > & TimedVariableMap()=0
Return the map of groupnames and names of all timedvariables for render.
virtual int64 GetLockHeld() const =0
Get/Setters that may only be called if you already hold the mutex.
virtual TimedVariable * AddTimedVariable(const StringPiece &name, const StringPiece &group)=0
virtual int64 AddHelper(int64 delta)=0
This is virtual so that subclasses can add platform-specific atomicity.
Definition: statistics_logger.h:42