StatHist.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2017 The Squid Software Foundation and contributors
3  *
4  * Squid software is distributed under GPLv2+ license and includes
5  * contributions from numerous individuals and organizations.
6  * Please see the COPYING and CONTRIBUTORS files for details.
7  */
8 
9 #ifndef STATHIST_H_
10 #define STATHIST_H_
11 
12 /* for StoreEntry */
13 #include "Store.h"
14 
16 typedef double hbase_f(double);
17 
19 typedef void StatHistBinDumper(StoreEntry *, int idx, double val, double size, int count);
20 
25 class StatHist
26 {
27 public:
37  StatHist();
38  StatHist(const StatHist&); //not needed
39  ~StatHist() { clear(); };
40 
41  typedef uint64_t bins_type;
42 
43  StatHist &operator=(const StatHist &);
44 
50  void clear();
51 
55  double deltaPctile(const StatHist &B, double pctile) const;
56 
60  double val(unsigned int bin) const;
61 
65  void count(double val);
66 
69  void dump(StoreEntry *sentry, StatHistBinDumper * bd) const;
70 
73  void logInit(unsigned int capacity, double min, double max);
74 
77  void enumInit(unsigned int last_enum);
78 
85 
86 protected:
98  void init(unsigned int capacity, hbase_f * val_in, hbase_f * val_out, double min, double max);
99 
102  unsigned int findBin(double v);
103 
106  unsigned int capacity_;
107 
109  double min_;
110 
112  double max_;
113 
115  double scale_;
116  hbase_f *val_in; /* e.g., log() for log-based histogram */
117  hbase_f *val_out; /* e.g., exp() for log based histogram */
118 };
119 
120 double statHistDeltaMedian(const StatHist & A, const StatHist & B);
121 double statHistDeltaPctile(const StatHist & A, const StatHist & B, double pctile);
124 
125 inline StatHist&
127 {
128  if (this==&src) //handle self-assignment
129  return *this;
130  if (capacity_ != src.capacity_) {
131  xfree(bins); // xfree can handle NULL pointers, no need to check
132  capacity_=src.capacity_;
133  bins = static_cast<bins_type *>(xcalloc(src.capacity_, sizeof(bins_type)));
134  }
135  min_=src.min_;
136  max_=src.max_;
137  scale_=src.scale_;
138  val_in=src.val_in;
139  val_out=src.val_out;
140  if (bins != NULL)
141  memcpy(bins,src.bins,capacity_*sizeof(*bins));
142  return *this;
143 }
144 
145 inline
147  bins(NULL), capacity_(0), min_(0), max_(0),
148  scale_(1.0), val_in(NULL), val_out(NULL)
149 {}
150 
151 inline void
153 {
154  xfree(bins); // can handle case of bins being NULL
155  bins=NULL;
156  capacity_=0; // mark as destructed, may be needed for troubleshooting
157 }
158 
159 #endif /* STATHIST_H_ */
160 
void count(double val)
Definition: StatHist.cc:57
StatHist & operator+=(const StatHist &B)
Definition: StatHist.cc:189
void StatHistBinDumper(StoreEntry *, int idx, double val, double size, int count)
function signature for StatHist dumping functions
Definition: StatHist.h:19
void init(unsigned int capacity, hbase_f *val_in, hbase_f *val_out, double min, double max)
Definition: StatHist.cc:28
static uint32 B
Definition: md4.c:43
unsigned int capacity_
Definition: StatHist.h:106
void clear()
Definition: StatHist.h:152
#define xcalloc
Definition: membanger.c:57
StatHistBinDumper statHistEnumDumper
Definition: StatHist.h:122
A const & max(A const &lhs, A const &rhs)
void logInit(unsigned int capacity, double min, double max)
Definition: StatHist.cc:223
hbase_f * val_in
Definition: StatHist.h:116
bins_type * bins
the histogram counters
Definition: StatHist.h:105
double statHistDeltaPctile(const StatHist &A, const StatHist &B, double pctile)
Definition: StatHist.cc:99
uint64_t bins_type
Definition: StatHist.h:39
~StatHist()
Definition: StatHist.h:39
double scale_
scaling factor when looking for a bin
Definition: StatHist.h:115
static uint32 A
Definition: md4.c:43
unsigned int findBin(double v)
Definition: StatHist.cc:66
double max_
value of the maximum counter in the histogram
Definition: StatHist.h:112
double val(unsigned int bin) const
Definition: StatHist.cc:87
double hbase_f(double)
function signature for in/out StatHist adaptation
Definition: StatHist.h:16
double statHistDeltaMedian(const StatHist &A, const StatHist &B)
Definition: StatHist.cc:93
StatHist & operator=(const StatHist &)
Definition: StatHist.h:126
StatHist()
Definition: StatHist.h:146
double deltaPctile(const StatHist &B, double pctile) const
Definition: StatHist.cc:105
void dump(StoreEntry *sentry, StatHistBinDumper *bd) const
Definition: StatHist.cc:173
hbase_f * val_out
Definition: StatHist.h:117
#define xfree
StatHistBinDumper statHistIntDumper
Definition: StatHist.h:123
double min_
minimum value to be stored, corresponding to the first bin
Definition: StatHist.h:109
#define NULL
Definition: types.h:166
int size
Definition: ModDevPoll.cc:77
A const & min(A const &lhs, A const &rhs)
void enumInit(unsigned int last_enum)
Definition: StatHist.cc:237

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors