StatHist.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2023 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 SQUID_SRC_STATHIST_H
10 #define SQUID_SRC_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 /* SQUID_SRC_STATHIST_H */
142 
void * xcalloc(size_t n, size_t sz)
Definition: xalloc.cc:71
void StatHistBinDumper(StoreEntry *, int idx, double val, double size, int count)
function signature for StatHist dumping functions
Definition: StatHist.h:19
double scale_
scaling factor when looking for a bin
Definition: StatHist.h:111
double max_
value of the maximum counter in the histogram
Definition: StatHist.h:108
hbase_f * val_out
Definition: StatHist.h:113
~StatHist()
Definition: StatHist.h:39
double val(unsigned int bin) const
Definition: StatHist.cc:85
const A & max(A const &lhs, A const &rhs)
StatHist & operator=(const StatHist &)
Definition: StatHist.h:122
unsigned int findBin(double v)
Definition: StatHist.cc:64
StatHistBinDumper statHistEnumDumper
Definition: StatHist.h:118
StatHist & operator+=(const StatHist &B)
Definition: StatHist.cc:187
double min_
minimum value to be stored, corresponding to the first bin
Definition: StatHist.h:105
int size
Definition: ModDevPoll.cc:69
double deltaPctile(const StatHist &B, double pctile) const
Definition: StatHist.cc:103
void dump(StoreEntry *sentry, StatHistBinDumper *bd) const
Definition: StatHist.cc:171
static uint32 A
Definition: md4.c:43
void enumInit(unsigned int last_enum)
Definition: StatHist.cc:235
void count(double val)
Definition: StatHist.cc:55
double statHistDeltaPctile(const StatHist &A, const StatHist &B, double pctile)
Definition: StatHist.cc:97
#define xfree
void init(unsigned int capacity, hbase_f *val_in, hbase_f *val_out, double min, double max)
Definition: StatHist.cc:26
unsigned int capacity_
Definition: StatHist.h:102
double hbase_f(double)
function signature for in/out StatHist adaptation
Definition: StatHist.h:16
StatHistBinDumper statHistIntDumper
Definition: StatHist.h:119
double statHistDeltaMedian(const StatHist &A, const StatHist &B)
Definition: StatHist.cc:91
void logInit(unsigned int capacity, double min, double max)
Definition: StatHist.cc:221
hbase_f * val_in
Definition: StatHist.h:112
bins_type * bins
the histogram counters
Definition: StatHist.h:101
static uint32 B
Definition: md4.c:43
StatHist()=default
const A & min(A const &lhs, A const &rhs)
uint64_t bins_type
Definition: StatHist.h:44

 

Introduction

Documentation

Support

Miscellaneous