49 #ifndef __BASE_STATISTICS_HH__
50 #define __BASE_STATISTICS_HH__
83 template <
class Stat,
class Base>
92 bool check()
const {
return s.check(); }
98 visitor.
visit(*static_cast<Base *>(
this));
100 bool zero()
const {
return s.zero(); }
103 template <
class Stat>
114 template <
class Stat>
136 this->
s.result(
rvec);
143 template <
class Stat>
150 template <
class Stat>
159 template <
class Stat>
198 bool zero()
const {
return true; }
208 template <
class Derived,
template <
class>
class InfoProxyType>
212 typedef InfoProxyType<Derived>
Info;
215 Derived &
self() {
return *
static_cast<Derived *
>(
this); }
261 const std::string &
name()
const {
return this->
info()->name; }
272 this->
info()->setSeparator(_sep);
277 return this->
info()->separatorString;
289 this->
info()->desc = _desc;
301 this->
info()->precision = _precision;
313 this->
info()->flags.set(_flags);
323 template <
class Stat>
327 this->
info()->prereq = prereq.info();
332 template <
class Derived,
template <
class>
class InfoProxyType>
336 typedef InfoProxyType<Derived>
Info;
360 Derived &
self = this->
self();
364 if (subn.size() <=
index)
365 subn.resize(index + 1);
387 if (subd.size() <=
index)
388 subd.resize(index + 1);
397 Derived &
self = this->
self();
400 size_t size =
self.size();
402 self.
data(
i)->prepare(info);
408 Derived &
self = this->
self();
411 size_t size =
self.size();
413 self.
data(
i)->reset(info);
417 template <
class Derived,
template <
class>
class InfoProxyType>
421 typedef InfoProxyType<Derived>
Info;
430 Derived &
self = this->
self();
442 Derived &
self = this->
self();
445 assert(index <
self.y);
454 return this->
info()->y_subnames[
i];
630 template <
class Derived,
class Stor>
650 return reinterpret_cast<Storage *
>(storage);
662 return reinterpret_cast<const Storage *
>(storage);
708 template <
typename U>
716 template <
typename U>
724 template <
typename U>
748 std::string
str()
const {
return std::to_string(
value()); }
788 template <
class T,
class V>
803 template <
class Derived>
838 template <
class T,
class V>
869 template <
class Stat>
946 template <
typename U>
958 template <
typename U>
970 template <
typename U>
995 template <
class Derived,
class Stor>
1030 assert(s > 0 &&
"size must be positive!");
1031 assert(!
storage &&
"already initialized");
1049 vec[
i] =
data(
i)->value();
1061 vec[
i] =
data(
i)->result();
1073 total +=
data(
i)->result();
1086 if (
data(
i)->zero())
1108 data(
i)->~Storage();
1109 delete []
reinterpret_cast<char *
>(
storage);
1120 Derived &
self = this->
self();
1133 assert (index >= 0 && index <
size());
1134 return Proxy(this->
self(), index);
1138 template <
class Stat>
1149 typename Stat::Storage *
1152 assert(index <
len);
1156 const typename Stat::Storage *
1159 assert(index <
len);
1180 total +=
data(
i)->result();
1207 assert (index >= 0 && index <
size());
1214 template <
class Derived,
class Stor>
1248 data(
i)->~Storage();
1249 delete []
reinterpret_cast<char *
>(
storage);
1255 assert(_x > 0 && _y > 0 &&
"sizes must be positive!");
1256 assert(!
storage &&
"already initialized");
1258 Derived &
self = this->
self();
1282 assert (index >= 0 && offset + y <=
size());
1283 return Proxy(this->
self(), offset, y);
1296 return data(0)->zero();
1299 if (!
data(
i)->zero())
1314 total +=
data(
i)->result();
1325 data(
i)->prepare(info);
1327 info->
cvec.resize(size);
1341 data(
i)->reset(info);
1432 assert(index <
size());
1442 sum += val * number;
1443 squares += val * val * number;
1499 min_val = CounterLimits::max();
1500 max_val = CounterLimits::min();
1588 assert(index <
size());
1591 sum += val * number;
1592 squares += val * val * number;
1593 logs += log(val) * number;
1627 int buckets = params->
buckets;
1628 data.
cvec.resize(buckets);
1819 template <
class Derived,
class Stor>
1839 return reinterpret_cast<Storage *
>(storage);
1849 return reinterpret_cast<const Storage *
>(storage);
1868 template <
typename U>
1905 template <
class Stat>
1908 template <
class Derived,
class Stor>
1939 assert(s > 0 &&
"size must be positive!");
1940 assert(!
storage &&
"already initialized");
1964 data(
i)->~Storage();
1965 delete []
reinterpret_cast<char *
>(
storage);
1970 assert(index >= 0 && index <
size());
1971 return Proxy(this->
self(), index);
1984 if (!
data(
i)->zero())
1994 info->
data.resize(size);
2006 template <
class Stat>
2035 template <
typename U>
2039 data()->sample(v,
n);
2051 return data()->zero();
2092 virtual std::string
str()
const = 0;
2124 template <
class Stat>
2146 return proxy.result();
2219 std::string tmp =
"(";
2233 static std::string
str() {
return "+"; }
2239 static std::string
str() {
return "-"; }
2245 static std::string
str() {
return "*"; }
2251 static std::string
str() {
return "/"; }
2257 static std::string
str() {
return "%"; }
2263 static std::string
str() {
return "-"; }
2329 assert(lvec.size() > 0 && rvec.size() > 0);
2331 if (lvec.size() == 1 && rvec.size() == 1) {
2334 }
else if (lvec.size() == 1) {
2339 }
else if (rvec.size() == 1) {
2344 }
else if (rvec.size() == lvec.size()) {
2365 assert(lvec.size() > 0 && rvec.size() > 0);
2366 assert(lvec.size() == rvec.size() ||
2367 lvec.size() == 1 || rvec.size() == 1);
2370 if (lvec.size() == rvec.size() && lvec.size() > 1) {
2375 return op(lsum, rsum);
2393 }
else if (rs == 1) {
2396 assert(ls == rs &&
"Node vector sizes are not equal");
2445 result =
op(result, lvec[
i]);
2543 return this->
self();
2566 return this->
self();
2631 return this->
self();
2654 return this->
self();
2677 return this->
self();
2681 template <
class Stat>
2696 this->
s.result(
vec);
2702 std::string
str()
const {
return this->
s.str(); }
2705 template <
class Stat>
2716 template <
class Derived,
class Stor>
2765 template <
typename U>
2851 MCounter::iterator it;
2853 for (it =
cmap.begin(); it !=
cmap.end(); it++) {
2854 data.
cmap[(*it).first] = (*it).second;
2885 return this->
self();
2974 std::string
str()
const;
3072 template <
class Stat>
3182 return Temp(std::make_shared<
BinaryNode<std::plus<Result> > >(l, r));
3188 return Temp(std::make_shared<
BinaryNode<std::minus<Result> > >(l, r));
3194 return Temp(std::make_shared<
BinaryNode<std::multiplies<Result> > >(l, r));
3200 return Temp(std::make_shared<
BinaryNode<std::divides<Result> > >(l, r));
3206 return Temp(std::make_shared<
UnaryNode<std::negate<Result> > >(l));
3209 template <
typename T>
3216 template <
typename T>
3226 return Temp(std::make_shared<
SumNode<std::plus<Result> > >(val));
3280 #endif // __BASE_STATISTICS_HH__
const Storage * data() const
Retrieve a const pointer to the storage.
Counter value() const
Return the current value of this stat as its base type.
double Result
All results are doubles.
Storage * data(off_type index)
Retrieve the storage.
std::map< Counter, int > MCounter
map of counters
DistProxy(const DistProxy &sp)
DistProxy< Derived > Proxy
Storage * storage
The storage of this stat.
Templatized storage and interface for a sparse histogram stat.
size_type size() const
Return the number of nodes in the subtree starting at this node.
Counter samples
The number of samples.
std::string name
The name of the stat.
Temp(unsigned long long value)
Create a ConstNode.
void sample(const U &v, int n=1)
StandardDeviation()
Construct and initialize this distribution.
Derived & method(T *obj, V(T::*method)() const)
Extended functor that calls the specified method of the provided object.
Counter value() const
Return the value of this stat as its base type.
Derived & init(size_type _x, size_type _y)
void processDumpQueue()
Process all the callbacks in the dump callbacks queue.
Result total() const
Return a total of all entries in this vector.
Derived & subname(off_type index, const std::string &name)
Set the subfield name for the given index, and marks this stat to print at the end of simulation...
const VectorProxy & operator=(const VectorProxy &sp)
Counter sum
The current sum.
virtual Result total() const =0
Return the total of the result vector.
std::vector< std::string > subdescs
bool zero() const
Return true if no samples have been added.
void setParams(const StorageParams *params)
Save Storage class parameters if any.
const std::string & name() const
The parameters for a distribution stat.
const std::string & name()
const Storage * data(off_type index) const
Retrieve a const pointer to the storage.
void operator++()
Increment the stat by 1.
Base class for formula statistic node.
Counter bucket_size
The number of entries in each bucket.
void reset(Info *info)
Reset stat value to default.
AverageDeviation()
Construct and initialize this distribution.
A stat that calculates the per tick average of a value.
MethodProxy(T *obj, MethodPointer meth)
SampleStor(Info *info)
Create and initialize this storage.
const VResult & result() const
Counter min
The minimum value to track.
Counter min_val
The smallest value sampled.
VectorProxy(const VectorProxy &sp)
Temp(signed int value)
Create a ConstNode.
Counter current
The current count.
void operator--(int)
Decrement the stat by 1.
Temp(const AverageVector &s)
char storage[sizeof(Storage)] __attribute__((aligned(8)))
The storage of this stat.
Storage * data(off_type index)
const VResult & result() const
Return the result vector of this subtree.
Counter max_bucket
The maximum value to track.
Temp(unsigned char value)
Create a ConstNode.
virtual size_type size() const =0
Result result() const
Return the value of this stat as a result type.
Counter overflow
The number of values sampled more than max.
void operator+=(const U &v)
Increment the stat by the given value.
VCounter cvec
Counter for each bucket.
const VResult & result() const
Return the result vector of this subtree.
InfoProxyType< Derived > Info
size_type buckets
The number of buckets.
Proxy operator[](off_type index)
void inc(Counter val)
Increment the current count by the provided value, calls set.
Implementation of a distribution stat.
virtual size_type size() const =0
Return the number of nodes in the subtree starting at this node.
VectorInfoProxy(Stat &stat)
void operator--()
Decrement the stat by 1.
VectorAverageDeviation & init(size_type size)
Initialize storage for this distribution.
virtual Result total() const =0
void prepare(Info *info, DistData &data)
Temp operator/(Temp l, Temp r)
ScalarProxy< Derived > Proxy
Proxy type.
virtual std::string str() const =0
const Info * info() const
size_type size() const
Return the number of nodes in the subtree starting at this node.
void result(VResult &vec) const
Copy the values to a local vector and return a reference to it.
Counter samples
Counter for number of samples.
void(* Handler)()
Register reset and dump handlers.
const VResult & result() const
Return the result vector of this subtree.
Result total
The total count for all tick.
Counter min_track
The minimum value to track.
Templatized storage and interface for a simple scalar stat.
Derived & subdesc(off_type index, const std::string &desc)
Set the subfield description for the given index and marks this stat to print at the end of simulatio...
char storage[sizeof(Storage)] __attribute__((aligned(8)))
The storage for this stat.
A vector of scalar stats.
Histogram & init(size_type size)
Set the parameters of this histogram.
V(T::* MethodPointer)() const
size_type buckets
The number of buckets.
VectorDistribution & init(size_type size, Counter min, Counter max, Counter bkt)
Initialize storage and parameters for this distribution.
list< Info * > & statsList()
A vector of distributions.
Counter squares
Current sum of squares.
MCounter cmap
Counter for each bucket.
std::vector< std::string > y_subnames
virtual Result result() const =0
Counter logs
The sum of logarithm of each sample, used to compute geometric mean.
Storage * data()
Retrieve the storage.
Temp(signed char value)
Create a ConstNode.
size_type size() const
Return the number of nodes in the subtree starting at this node.
const Storage * data(off_type index) const
bool zero() const
Returns true if any calls to sample have been made.
void operator--(int)
Decrement the stat by 1.
ScalarProxy(Stat &s, off_type i)
Create and initialize this proxy, do not register it with the database.
The parameters for a distribution stat.
Counter squares
The sum of squares.
Derived & scalar(T &value)
void operator++()
Increment the stat by 1.
Derived & flags(Flags _flags)
Set the flags and marks this stat to print at the end of simulation.
Counter min_bucket
The minimum value to track.
Proxy operator[](off_type index)
Return a reference (ScalarProxy) to the stat at the given index.
Result total() const
Return the total of the result vector.
VectorDistInfoProxy< Derived > Info
virtual void visit(const ScalarInfo &info)=0
This is a simple scalar statistic, like a counter.
This is a vector of AverageDeviation stats.
bool zero() const
Returns true if any calls to sample have been made.
Derived & init(size_type size)
Set this vector to have the given size.
VectorStatNode(const VectorInfo *d)
Calculates the mean and variance of all the samples.
size_type size() const
Return the number of entries in this stat.
size_type size() const
Return the number of entries in this stat.
double Counter
All counters are of 64-bit values.
void sample(Counter val, int number)
Add a value to the distribution for the given number of times.
virtual const VResult & result() const =0
Return the result vector of this subtree.
const Storage * data() const
Retrieve a const pointer to the storage.
size_type size() const
Return the number of nodes in the subtree starting at this node.
ScalarProxy(const ScalarProxy &sp)
Create a copy of the provided ScalarProxy.
SparseHistInfoProxy(Stat &stat)
Temp(signed long long value)
Create a ConstNode.
Data structure of sparse histogram.
void value(VCounter &vec) const
void visit(Output &visitor)
Visitor entry for outputing statistics data.
Result total() const
Return the total of the result vector.
void operator++(int)
Increment the stat by 1.
void prepare(Info *info, DistData &data)
bool zero() const
Returns true if any calls to sample have been made.
Counter samples
The number of samples.
const VResult & result() const
Return the result vector of this subtree.
Tick curTick()
The current simulated tick.
Counter max
The maximum value to track.
Temp(const ScalarProxy< Stat > &p)
Create a new ScalarProxyNode.
void prepare(Info *info, DistData &data)
Counter squares
The sum of squares.
VCounter cvec
Counter for each bucket.
virtual const VResult & result() const =0
std::string csprintf(const char *format, const Args &...args)
void operator=(const U &v)
Set the data value to the given value.
VCounter cvec
Local storage for the entry values, used for printing.
const DistProxy & operator=(const DistProxy &sp)
Derived & setSeparator(const std::string &_sep)
Set the character(s) used between the name and vector number on vectors, dist, etc.
Temp operator-(Temp l, Temp r)
void reset()
Proxy has no state.
Temp(const Average &s)
Create a new ScalarStatNode.
Result result() const
Return the current average.
Tick last
The tick that current last changed.
BinaryNode(NodePtr &a, NodePtr &b)
Result result() const
Return the current value of this statas a result type.
Templatized storage and interface for a histogram stat.
size_type size() const
Return the number of nodes in the subtree starting at this node.
Counter sum
The current sum.
Proxy operator[](off_type index)
uint64_t Tick
Tick count type.
Counter squares
The sum of squares.
const Stat::Storage * data() const
A simple distribution stat.
std::shared_ptr< Node > NodePtr
Shared pointer to a function Node.
Implementation of a scalar stat.
virtual Result total() const =0
void reset()
Reset the stat to the default state.
The parameters for a distribution stat.
Flags flags
The formatting flags.
void dec(Counter val)
Decrement the stat by the given value.
Derived & prereq(const Stat &prereq)
Set the prerequisite stat and marks this stat to print at the end of simulation.
void set(Counter val)
Set the current count to the one provided, update the total and last set values.
void reset(Info *info)
Reset stat value to default.
ScalarStatNode(const ScalarInfo *d)
ScalarProxy< Stat > operator[](off_type index)
void registerResetCallback(Callback *cb)
Register a callback that should be called whenever statistics are reset.
Counter value() const
Return the current count.
VectorDistInfoProxy(Stat &stat)
ScalarInfoProxy(Stat &stat)
void reset()
Reset the stat to the default state.
InfoProxyType< Derived > Info
void reset(Info *info)
Reset stat value to default.
size_type size() const
Return the number of buckets in this distribution.
Counter bucket_size
The number of entries in each bucket.
StatStor(Info *info)
Builds this storage element and calls the base constructor of the datatype.
const VResult & result() const
Return the result vector of this subtree.
void setName(const std::string &name)
Set the name of this statistic.
Temp(const NodePtr &n)
Copy the given pointer to this class.
virtual Counter value() const =0
Temp(signed short value)
Create a ConstNode.
size_type size() const
Return the number of buckets in this distribution.
ScalarProxyNode(const ScalarProxy< Stat > &p)
Storage * data()
Retrieve the storage.
void prepare(Info *info)
Prepare stat data for dumping or serialization.
AvgStor(Info *info)
Build and initializes this stat storage.
Counter sum
Current total.
void operator-=(const U &v)
Decrement the stat by the given value.
Distribution & init(Counter min, Counter max, Counter bkt)
Set the parameters of this distribution.
Implementation of a sparse histogram stat.
DataWrap(const DataWrap &stat)
Copy constructor, copies are not allowed.
std::vector< DistData > data
const FlagsType display
Print this stat.
void operator=(const DataWrapVec &)
Calculates the per tick mean and variance of the samples.
const std::string & setSeparator() const
void sample(Counter val, int number)
Add a value to the distribution for the given number of times.
Temp(const Value &s)
Create a new ScalarStatNode.
Temp(float value)
Create a ConstNode.
Defines global host-dependent types: Counter, Tick, and (indirectly) {int,uint}{8,16,32,64}_t.
std::string ysubname(off_type i) const
Temp(unsigned int value)
Create a ConstNode.
const Storage * data(off_type index) const
std::map< const void *, Info * > MapType
bool zero() const
Return true if no samples have been added.
Derived & precision(int _precision)
Set the precision and marks this stat to print at the end of simulation.
void dec(Counter val)
Deccrement the current count by the provided value, calls set.
Counter bucket_size
The number of entries in each bucket.
Result total() const
Return a total of all entries in this vector.
Temp operator+(Temp l, Temp r)
Templatized storage and interface to a per-tick average stat.
Helper class to construct formula node trees.
void operator=(const DataWrap &)
Can't copy stats.
void reset()
Reset stat value to default.
Temp(signed long value)
Create a ConstNode.
const VResult & result() const
Return the result vector of this subtree.
SparseHistInfoProxy< Derived > Info
bool check() const
Check that this stat has been set up properly and is ready for use.
Counter max_track
The maximum value to track.
void registerDumpCallback(Callback *cb)
Register a callback that should be called whenever statistics are about to be dumped.
Templatized storage and interface for a distribution stat.
Counter max_val
The largest value sampled.
Result total() const
Return the total of the result vector.
Tick lastReset
The tick of the last reset.
void sample(Counter val, int number)
Add a value to the distribution for the given number of times.
Derived & name(const std::string &name)
Set the name and marks this stat to print at the end of simulation.
Templatized storage for distribution that calculates per tick mean and variance.
bool zero() const
Return true if no samples have been added.
void reset(Info *info)
Reset stat value to default.
void sample(Counter val, int number)
Add a value the given number of times to this running average.
void setInit()
Save Storage class parameters if any.
void prepare()
Prepare the stat for dumping.
const VResult & result() const
Return the result vector of this subtree.
Temp constantVector(T val)
size_type size() const
Return the number of buckets in this distribution.
Result total() const
Return the total of the result vector.
bool zero() const
Return true if no samples have been added.
The parameters for a sparse histogram stat.
const VResult & result() const
Return the result vector of this subtree.
const VResult & result() const
size_type size() const
Return the number of nodes in the subtree starting at this node.
Counter underflow
The number of values sampled less than min.
void processResetQueue()
Process all the callbacks in the reset callbacks queue.
Storage * data()
Retrieve the storage.
Result total() const
Return the total of the result vector.
void setInfo(Info *info)
Set up an info class for this statistic.
NodePtr getNodePtr() const
Makde gcc < 4.6.3 happy and explicitly get the underlying node.
const StorageParams * storageParams
const ScalarProxy & operator=(const ScalarProxy &sp)
Set this proxy equal to the provided one.
Result total() const
Return the total of the result vector.
void operator-=(const U &v)
Decrement the stat by the given value.
void add(DistBase &d)
Add the argument distribution to the this distribution.
SparseHistData data
Local storage for the entry values, used for printing.
void prepare(Info *info, SparseHistData &data)
Derived & ysubname(off_type index, const std::string &subname)
Temp(const Scalar &s)
Create a new ScalarStatNode.
Vector2dInfoProxy< Derived > Info
bool validateStatName(const string &name)
Counter data
The statistic value.
void sample(Counter val, int number)
Add a value to the distribution for the given number of times.
Counter value() const
Return the current value of this stat as its base type.
DistInfoProxy(Stat &stat)
SparseHistogram & init(size_type size)
Set the parameters of this histogram.
Result total() const
Return the total of the result vector.
const Storage * data() const
Retrieve a const pointer to the storage.
SparseHistStor(Info *info)
Temp operator*(Temp l, Temp r)
off_type index
The index to access in the parent VectorBase.
VectorProxy< Derived > Proxy
DataWrapVec(const DataWrapVec &ref)
A vector of Average stats.
VectorProxy(Stat &s, off_type o, size_type l)
void reset()
Reset stat value to default.
ConstVectorNode(const T &s)
size_type size() const
Return the number of elements, always 1 for a scalar.
Stat::Storage * data(off_type index)
void inc(Counter val)
Increment the stat by the given value.
void reset(Info *info)
Reset stat value to default.
Temp(unsigned short value)
Create a ConstNode.
void sample(const U &v, int n=1)
Add a value to the distribtion n times.
Derived & desc(const std::string &_desc)
Set the description and marks this stat to print at the end of simulation.
void prepare(Info *info, DistData &data)
void operator--()
Decrement the stat by 1.
const ScalarProxy< Stat > proxy
void operator=(const U &v)
Set the data value to the given value.
void dump()
Dump all statistics data to the registered outputs.
Vector2dInfoProxy(Stat &stat)
size_type size() const
Return the number of entries, in this case 1.
A 2-Dimensional vecto of scalar stats.
std::map< std::string, Info * > NameMapType
size_type size() const
Return the number of entries in this stat, 1.
bool check() const
Check that this stat has been set up properly and is ready for use.
Storage * data(off_type index)
DistInfoProxy< Derived > Info
VectorStandardDeviation & init(size_type size)
Initialize storage for this distribution.
void reset(Info *info)
Reset stat value to default.
InfoProxyType< Derived > Info
size_type size() const
Return the number of elements, always 1 for a scalar.
This is a vector of StandardDeviation stats.
Derived & ysubnames(const char **names)
Temp(double value)
Create a ConstNode.
void registerHandlers(Handler reset_handler, Handler dump_handler)
Temp(unsigned long value)
Create a ConstNode.
size_type size() const
Return the number of nodes in the subtree starting at this node.
NodePtr node
Pointer to a Node object.
void prepare(Info *info)
Prepare stat data for dumping or serialization.
Derived & functor(T &func)
void visit(Output &visitor)
Info * info()
Grab the information class for this statistic.
void operator++(int)
Increment the stat by 1.
A proxy similar to the FunctorProxy, but allows calling a method of a bound object, instead of a global free-standing function.
Counter samples
The number of samples.
char storage[sizeof(Storage)]
The storage for this stat.
Temp(const Vector &s)
Create a new VectorStatNode.
Counter sum
The current sum.
Implementation of a vector of stats.
void operator+=(const U &v)
Increment the stat by the given value.
DistData data
Local storage for the entry values, used for printing.
void set(Counter val)
The the stat to the given value.
void sample(const U &v, int n=1)
Add a value to the distribtion n times.
size_type size() const
Return the number of nodes in the subtree starting at this node.
std::vector< std::string > subnames
Names and descriptions of subfields.
Result total() const
Return the total of the result vector.
void reset()
Reset stat value to default.
Templatized storage and interface for a distribution that calculates mean and variance.
const Stat::Storage * data(off_type index) const
DistProxy(Stat &s, off_type i)
Stat & stat
Pointer to the parent Vector.
A proxy class to access the stat at a given index in a VectorBase stat.
AvgSampleStor(Info *info)
Create and initialize this storage.
void reset(Info *info)
Reset stat value to default.