StatHist.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2018 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() = default;
38  StatHist(const StatHist &);
40  xfree(bins); // can handle case of bins being nullptr
41  capacity_ = 0; // mark as destructed, may be needed for troubleshooting
42  }
43 
44  typedef uint64_t bins_type;
45 
46  StatHist &operator=(const StatHist &);
47 
51  double deltaPctile(const StatHist &B, double pctile) const;
52 
56  double val(unsigned int bin) const;
57 
61  void count(double val);
62 
65  void dump(StoreEntry *sentry, StatHistBinDumper * bd) const;
66 
69  void logInit(unsigned int capacity, double min, double max);
70 
73  void enumInit(unsigned int last_enum);
74 
81 
82 protected:
94  void init(unsigned int capacity, hbase_f * val_in, hbase_f * val_out, double min, double max);
95 
98  unsigned int findBin(double v);
99 
101  bins_type *bins = nullptr;
102  unsigned int capacity_ = 0;
103 
105  double min_ = 0.0;
106 
108  double max_ = 0.0;
109 
111  double scale_ = 1.0;
112  hbase_f *val_in = nullptr; /* e.g., log() for log-based histogram */
113  hbase_f *val_out = nullptr; /* e.g., exp() for log based histogram */
114 };
115 
116 double statHistDeltaMedian(const StatHist & A, const StatHist & B);
117 double statHistDeltaPctile(const StatHist & A, const StatHist & B, double pctile);
120 
121 inline StatHist&
123 {
124  if (this==&src) //handle self-assignment
125  return *this;
126  if (capacity_ != src.capacity_) {
127  xfree(bins); // xfree can handle NULL pointers, no need to check
128  capacity_=src.capacity_;
129  bins = static_cast<bins_type *>(xcalloc(src.capacity_, sizeof(bins_type)));
130  }
131  min_=src.min_;
132  max_=src.max_;
133  scale_=src.scale_;
134  val_in=src.val_in;
135  val_out=src.val_out;
136  if (bins)
137  memcpy(bins,src.bins,capacity_*sizeof(*bins));
138  return *this;
139 }
140 
141 #endif /* STATHIST_H_ */
142 
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
double statHistDeltaMedian(const StatHist &A, const StatHist &B)
Definition: StatHist.cc:93
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:102
#define xcalloc
Definition: membanger.c:57
StatHistBinDumper statHistEnumDumper
Definition: StatHist.h:118
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:112
bins_type * bins
the histogram counters
Definition: StatHist.h:101
StatHist()=default
uint64_t bins_type
Definition: StatHist.h:44
~StatHist()
Definition: StatHist.h:39
double scale_
scaling factor when looking for a bin
Definition: StatHist.h:111
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:108
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
StatHist & operator=(const StatHist &)
Definition: StatHist.h:122
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:113
#define xfree
StatHistBinDumper statHistIntDumper
Definition: StatHist.h:119
double min_
minimum value to be stored, corresponding to the first bin
Definition: StatHist.h:105
int size
Definition: ModDevPoll.cc:77
A const & min(A const &lhs, A const &rhs)
double statHistDeltaPctile(const StatHist &A, const StatHist &B, double pctile)
Definition: StatHist.cc:99
void enumInit(unsigned int last_enum)
Definition: StatHist.cc:237

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors