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

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors