gem5  v21.0.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Classes | Public Member Functions | Private Member Functions | Private Attributes | List of all members
Stats::HistStor Class Reference

Templatized storage and interface for a histogram stat. More...

#include <storage.hh>

Classes

struct  Params
 The parameters for a distribution stat. More...
 

Public Member Functions

 HistStor (Info *info)
 
void add (HistStor *other)
 Adds the contents of the given storage to this storage. More...
 
void sample (Counter val, int number)
 Add a value to the distribution for the given number of times. More...
 
size_type size () const
 Return the number of buckets in this distribution. More...
 
bool zero () const
 Returns true if any calls to sample have been made. More...
 
void prepare (Info *info, DistData &data)
 
void reset (Info *info)
 Reset stat value to default. More...
 

Private Member Functions

void growUp ()
 Given a bucket size B, and a range of values [0, N], this function doubles the bucket size to double the range of values towards the positive infinite; that is, double the upper range of this storage so that the range becomes [0, 2*N]. More...
 
void growOut ()
 Given a bucket size B, and a range of values [M, N], where M < 0, this function doubles the bucket size to double the range of values towards both positive and negative infinites; that is, it doubles both the lower and the upper range of this storage so that the range becomes [2*M, 2*N]. More...
 
void growDown ()
 Given a bucket size B, and a range of values [0, N], this function doubles the bucket size to double the range of values towards the negative infinite; that is, it doubles the lower range of this storage so that the middle buckes contaihs zero as a lower bound. More...
 

Private Attributes

Counter min_bucket
 Lower bound of the first bucket's range. More...
 
Counter max_bucket
 Lower bound of the last bucket's range. More...
 
Counter bucket_size
 The number of entries in each bucket. More...
 
Counter sum
 The current sum. More...
 
Counter logs
 The sum of logarithm of each sample, used to compute geometric mean. More...
 
Counter squares
 The sum of squares. More...
 
Counter samples
 The number of samples. More...
 
VCounter cvec
 Counter for each bucket. More...
 

Detailed Description

Templatized storage and interface for a histogram stat.

The number of buckets is fixed on initialization; however, the bucket size isn't. That means that when samples that are outside the current range are seen, the bucket size will be increased so that each bucket can hold a bigger range of values. When that happens, the bucket's contents are re- located.

The min and max bucket values can only be, respectively, decreased and increased when sampling. If this wasn't true, samples that were previously within the buclet range could not be anymore within the valid range, making the storage's state incoherent. These values are set back to their initial states on reset().

The bucket range always is zero-centric. While the storage does not contain negative values the bucket range will keep its lower bound at zero, doubling the upper bound when needed; However, as soon a negative value is sampled, zero becomes the lower bound of the middle (rounded up) bucket. Although this means that the histogram will not be symmetric if negative values are sampled, it makes it possible to grow the buckets without keeping track of the individual values.

This happens because if zero was not a lower or upper bound, when its value was doubled, the lower and upper bound of the bucket containing zero would intersect with middle values of the previous and next buckets. For example, if the bucket containing zero has range [-2,2[, therefore its neighbor buckets would have ranges at [-6,-2[ and [2,6[. When the buckets are grown, the zero bucket would grow its range to [-4,4[, which cannot be easily extracted from the neighor buckets.

Definition at line 395 of file storage.hh.

Constructor & Destructor Documentation

◆ HistStor()

Stats::HistStor::HistStor ( Info info)
inline

Definition at line 470 of file storage.hh.

References reset().

Member Function Documentation

◆ add()

void Stats::HistStor::add ( HistStor other)

Adds the contents of the given storage to this storage.

Parameters
otherThe other storage to be added.

Definition at line 205 of file storage.cc.

References bucket_size, cvec, growUp(), ArmISA::i, logs, min_bucket, samples, size(), squares, and sum.

Referenced by TEST().

◆ growDown()

void Stats::HistStor::growDown ( )
private

Given a bucket size B, and a range of values [0, N], this function doubles the bucket size to double the range of values towards the negative infinite; that is, it doubles the lower range of this storage so that the middle buckes contaihs zero as a lower bound.

As such, the storage range becomes [-N, N+B] if there is an odd number of buckets, and [-N-B, N+B] if there is an even number of buckets.

Because the bucket size is doubled, the buckets contents are rearranged, and the original range of values are redistributed to free buckets for the newly appended ranges.

Definition at line 111 of file storage.cc.

References bucket_size, cvec, ArmISA::i, max_bucket, min_bucket, size(), and zero().

Referenced by sample().

◆ growOut()

void Stats::HistStor::growOut ( )
private

Given a bucket size B, and a range of values [M, N], where M < 0, this function doubles the bucket size to double the range of values towards both positive and negative infinites; that is, it doubles both the lower and the upper range of this storage so that the range becomes [2*M, 2*N].

Because the bucket size is doubled, the buckets contents are rearranged, and the original range of values are redistributed to free buckets for the newly appended ranges.

Definition at line 72 of file storage.cc.

References bucket_size, cvec, ArmISA::i, max_bucket, min_bucket, size(), and zero().

Referenced by sample().

◆ growUp()

void Stats::HistStor::growUp ( )
private

Given a bucket size B, and a range of values [0, N], this function doubles the bucket size to double the range of values towards the positive infinite; that is, double the upper range of this storage so that the range becomes [0, 2*N].

Because the bucket size is doubled, the buckets contents are rearranged, since the original range of values is mapped to the lower half buckets.

Definition at line 150 of file storage.cc.

References bucket_size, cvec, ArmISA::i, max_bucket, and size().

Referenced by add(), and sample().

◆ prepare()

void Stats::HistStor::prepare ( Info info,
DistData data 
)
inline

◆ reset()

void Stats::HistStor::reset ( Info info)
inline

Reset stat value to default.

Definition at line 534 of file storage.hh.

References bucket_size, Stats::HistStor::Params::buckets, cvec, ArmISA::i, logs, max_bucket, min_bucket, samples, size(), squares, Stats::Info::storageParams, and sum.

Referenced by HistStor(), and TEST().

◆ sample()

void Stats::HistStor::sample ( Counter  val,
int  number 
)

Add a value to the distribution for the given number of times.

Parameters
valThe value to add.
numberThe number of times to add the value.

Definition at line 172 of file storage.cc.

References bucket_size, cvec, growDown(), growOut(), growUp(), MipsISA::index, logs, max_bucket, min_bucket, samples, size(), squares, sum, and X86ISA::val.

Referenced by prepareCheckHistStor(), and TEST().

◆ size()

size_type Stats::HistStor::size ( ) const
inline

Return the number of buckets in this distribution.

Returns
the number of buckets.

Definition at line 493 of file storage.hh.

References cvec.

Referenced by add(), growDown(), growOut(), growUp(), reset(), sample(), and TEST().

◆ zero()

bool Stats::HistStor::zero ( ) const
inline

Returns true if any calls to sample have been made.

Returns
True if any values have been sampled.

Definition at line 500 of file storage.hh.

References samples.

Referenced by growDown(), growOut(), and TEST().

Member Data Documentation

◆ bucket_size

Counter Stats::HistStor::bucket_size
private

The number of entries in each bucket.

Definition at line 403 of file storage.hh.

Referenced by add(), growDown(), growOut(), growUp(), prepare(), reset(), and sample().

◆ cvec

VCounter Stats::HistStor::cvec
private

Counter for each bucket.

Definition at line 414 of file storage.hh.

Referenced by add(), growDown(), growOut(), growUp(), prepare(), reset(), sample(), and size().

◆ logs

Counter Stats::HistStor::logs
private

The sum of logarithm of each sample, used to compute geometric mean.

Definition at line 408 of file storage.hh.

Referenced by add(), prepare(), reset(), and sample().

◆ max_bucket

Counter Stats::HistStor::max_bucket
private

Lower bound of the last bucket's range.

Definition at line 401 of file storage.hh.

Referenced by growDown(), growOut(), growUp(), prepare(), reset(), and sample().

◆ min_bucket

Counter Stats::HistStor::min_bucket
private

Lower bound of the first bucket's range.

Definition at line 399 of file storage.hh.

Referenced by add(), growDown(), growOut(), prepare(), reset(), and sample().

◆ samples

Counter Stats::HistStor::samples
private

The number of samples.

Definition at line 412 of file storage.hh.

Referenced by add(), prepare(), reset(), sample(), and zero().

◆ squares

Counter Stats::HistStor::squares
private

The sum of squares.

Definition at line 410 of file storage.hh.

Referenced by add(), prepare(), reset(), and sample().

◆ sum

Counter Stats::HistStor::sum
private

The current sum.

Definition at line 406 of file storage.hh.

Referenced by add(), prepare(), reset(), and sample().


The documentation for this class was generated from the following files:

Generated on Tue Mar 23 2021 19:42:06 for gem5 by doxygen 1.8.17