2 * AUTHOR: Francesco Chemolli
4 * SQUID Web Proxy Cache http://www.squid-cache.org/
5 * ----------------------------------------------------------
7 * Squid is the result of efforts by numerous individuals from
8 * the Internet community; see the CONTRIBUTORS file for full
9 * details. Many organizations have provided support for Squid's
10 * development; see the SPONSORS file for full details. Squid is
11 * Copyrighted (C) 2001 by the Regents of the University of
12 * California; see the COPYRIGHT file for full details. Squid
13 * incorporates software developed and/or copyrighted by other
14 * sources; see the CREDITS file for full details.
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 2 of the License, or
19 * (at your option) any later version.
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software
28 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
38 /// function signature for in/out StatHist adaptation
39 typedef double hbase_f(double);
41 /// function signature for StatHist dumping functions
42 typedef void StatHistBinDumper(StoreEntry
*, int idx
, double val
, double size
, int count
);
44 /** Generic histogram class
46 * see important comments on hbase_f restrictions in StatHist.cc
51 * \note the default constructor doesn't fully initialize.
52 * you have to call one of the *init functions to specialize the
54 * \todo merge functionality from the *init functions to the constructor and
56 * \todo specialize the class in a small hierarchy so that all
57 * relevant initializations are done at build-time
59 StatHist() : scale_(1.0) {};
60 StatHist(const StatHist
&);
61 StatHist
&operator=(const StatHist
&);
63 /** clear the contents of the histograms
65 * \todo remove: this function has been replaced in its purpose
70 /** Calculate the percentile for value pctile for the difference between
71 * this and the supplied histogram.
73 double deltaPctile(const StatHist
&B
, double pctile
) const;
74 /** obtain the output-transformed value from the specified bin
77 double val(int bin
) const;
78 /** increment the counter for the histogram entry
79 * associated to the supplied value
81 void count(double val
);
82 /** iterate the supplied bd function over the histogram values
84 void dump(StoreEntry
*sentry
, StatHistBinDumper
* bd
) const;
85 /** Initialize the Histogram using a logarithmic values distribution
88 void logInit(int capacity
, double min
, double max
);
89 /** initialize the histogram to count occurrences in an enum-represented set
92 void enumInit(int last_enum
);
94 /** low-level initialize function. called by *Init high-level functions
95 * \note Important restrictions on val_in and val_out functions:
97 * - val_in: ascending, defined on [0, oo), val_in(0) == 0;
98 * - val_out: x == val_out(val_in(x)) where val_in(x) is defined
100 * In practice, the requirements are less strict,
101 * but then it gets hard to define them without math notation.
102 * val_in is applied after offseting the value but before scaling
103 * See log and linear based histograms for examples
105 void init(int capacity
, hbase_f
* val_in
, hbase_f
* val_out
, double min
, double max
);
106 /// find what entry in the histogram corresponds to v, by applying
107 /// the preset input transformation function
108 int findBin(double v
);
109 /// the histogram counters
112 /// minimum value to be stored, corresponding to the first bin
114 /// value of the maximum counter in the histogram
116 /// scaling factor when looking for a bin
118 hbase_f
*val_in
; /* e.g., log() for log-based histogram */
119 hbase_f
*val_out
; /* e.g., exp() for log based histogram */
122 double statHistDeltaMedian(const StatHist
& A
, const StatHist
& B
);
123 double statHistDeltaPctile(const StatHist
& A
, const StatHist
& B
, double pctile
);
124 StatHistBinDumper statHistEnumDumper
;
125 StatHistBinDumper statHistIntDumper
;
127 #endif /* STATHIST_H_ */