#include "base/cprintf.hh"
#include "base/intmath.hh"
#include "base/refcnt.hh"
-#include "base/str.hh"
-#include "base/stats/flags.hh"
-#include "base/stats/visit.hh"
+#include "base/stats/info.hh"
#include "base/stats/types.hh"
-#include "sim/host.hh"
+#include "base/stats/visit.hh"
+#include "base/str.hh"
+#include "base/types.hh"
class Callback;
/* A namespace for all of the Statistics */
namespace Stats {
-struct StorageParams
-{
- virtual ~StorageParams();
-};
-
-//////////////////////////////////////////////////////////////////////
-//
-// Statistics Framework Base classes
-//
-//////////////////////////////////////////////////////////////////////
-class Info
-{
- public:
- /** The name of the stat. */
- std::string name;
- /** The description of the stat. */
- std::string desc;
- /** The formatting flags. */
- StatFlags flags;
- /** The display precision. */
- int precision;
- /** A pointer to a prerequisite Stat. */
- const Info *prereq;
- /**
- * A unique stat ID for each stat in the simulator.
- * Can be used externally for lookups as well as for debugging.
- */
- static int id_count;
- int id;
-
- public:
- const StorageParams *storageParams;
-
- public:
- Info();
- virtual ~Info();
-
- /**
- * Check that this stat has been set up properly and is ready for
- * use
- * @return true for success
- */
- virtual bool check() const = 0;
- bool baseCheck() const;
-
- /**
- * Enable the stat for use
- */
- virtual void enable();
-
- /**
- * Prepare the stat for dumping.
- */
- virtual void prepare() = 0;
-
- /**
- * Reset the stat to the default state.
- */
- virtual void reset() = 0;
-
- /**
- * @return true if this stat has a value and satisfies its
- * requirement as a prereq
- */
- virtual bool zero() const = 0;
-
- /**
- * Visitor entry for outputing statistics data
- */
- virtual void visit(Visit &visitor) = 0;
-
- /**
- * Checks if the first stat's name is alphabetically less than the second.
- * This function breaks names up at periods and considers each subname
- * separately.
- * @param stat1 The first stat.
- * @param stat2 The second stat.
- * @return stat1's name is alphabetically before stat2's
- */
- static bool less(Info *stat1, Info *stat2);
-};
-
template <class Stat, class Base>
-class InfoWrap : public Base
+class InfoProxy : public Base
{
protected:
Stat &s;
public:
- InfoWrap(Stat &stat) : s(stat) {}
+ InfoProxy(Stat &stat) : s(stat) {}
bool check() const { return s.check(); }
void prepare() { s.prepare(); }
bool zero() const { return s.zero(); }
};
-class ScalarInfoBase : public Info
-{
- public:
- virtual Counter value() const = 0;
- virtual Result result() const = 0;
- virtual Result total() const = 0;
-};
-
template <class Stat>
-class ScalarInfo : public InfoWrap<Stat, ScalarInfoBase>
+class ScalarInfoProxy : public InfoProxy<Stat, ScalarInfo>
{
public:
- ScalarInfo(Stat &stat) : InfoWrap<Stat, ScalarInfoBase>(stat) {}
+ ScalarInfoProxy(Stat &stat) : InfoProxy<Stat, ScalarInfo>(stat) {}
Counter value() const { return this->s.value(); }
Result result() const { return this->s.result(); }
Result total() const { return this->s.total(); }
};
-class VectorInfoBase : public Info
-{
- public:
- /** Names and descriptions of subfields. */
- std::vector<std::string> subnames;
- std::vector<std::string> subdescs;
-
- public:
- void enable();
-
- public:
- virtual size_type size() const = 0;
- virtual const VCounter &value() const = 0;
- virtual const VResult &result() const = 0;
- virtual Result total() const = 0;
-};
-
template <class Stat>
-class VectorInfo : public InfoWrap<Stat, VectorInfoBase>
+class VectorInfoProxy : public InfoProxy<Stat, VectorInfo>
{
protected:
mutable VCounter cvec;
mutable VResult rvec;
public:
- VectorInfo(Stat &stat) : InfoWrap<Stat, VectorInfoBase>(stat) {}
+ VectorInfoProxy(Stat &stat) : InfoProxy<Stat, VectorInfo>(stat) {}
size_type size() const { return this->s.size(); }
Result total() const { return this->s.total(); }
};
-struct DistData
-{
- Counter min_val;
- Counter max_val;
- Counter underflow;
- Counter overflow;
- VCounter cvec;
- Counter sum;
- Counter squares;
- Counter samples;
-};
-
-class DistInfoBase : public Info
-{
- public:
- /** Local storage for the entry values, used for printing. */
- DistData data;
-};
-
template <class Stat>
-class DistInfo : public InfoWrap<Stat, DistInfoBase>
+class DistInfoProxy : public InfoProxy<Stat, DistInfo>
{
public:
- DistInfo(Stat &stat) : InfoWrap<Stat, DistInfoBase>(stat) {}
-};
-
-class VectorDistInfoBase : public Info
-{
- public:
- std::vector<DistData> data;
-
- /** Names and descriptions of subfields. */
- std::vector<std::string> subnames;
- std::vector<std::string> subdescs;
- void enable();
-
- protected:
- /** Local storage for the entry values, used for printing. */
- mutable VResult rvec;
-
- public:
- virtual size_type size() const = 0;
+ DistInfoProxy(Stat &stat) : InfoProxy<Stat, DistInfo>(stat) {}
};
template <class Stat>
-class VectorDistInfo : public InfoWrap<Stat, VectorDistInfoBase>
+class VectorDistInfoProxy : public InfoProxy<Stat, VectorDistInfo>
{
public:
- VectorDistInfo(Stat &stat) : InfoWrap<Stat, VectorDistInfoBase>(stat) {}
+ VectorDistInfoProxy(Stat &stat) : InfoProxy<Stat, VectorDistInfo>(stat) {}
size_type size() const { return this->s.size(); }
};
-class Vector2dInfoBase : public Info
-{
- public:
- /** Names and descriptions of subfields. */
- std::vector<std::string> subnames;
- std::vector<std::string> subdescs;
- std::vector<std::string> y_subnames;
-
- size_type x;
- size_type y;
-
- /** Local storage for the entry values, used for printing. */
- mutable VCounter cvec;
-
- void enable();
-};
-
template <class Stat>
-class Vector2dInfo : public InfoWrap<Stat, Vector2dInfoBase>
+class Vector2dInfoProxy : public InfoProxy<Stat, Vector2dInfo>
{
public:
- Vector2dInfo(Stat &stat) : InfoWrap<Stat, Vector2dInfoBase>(stat) {}
+ Vector2dInfoProxy(Stat &stat) : InfoProxy<Stat, Vector2dInfo>(stat) {}
};
class InfoAccess
bool check() const { return true; }
};
-template <class Derived, template <class> class InfoType>
+template <class Derived, template <class> class InfoProxyType>
class DataWrap : public InfoAccess
{
public:
- typedef InfoType<Derived> Info;
+ typedef InfoProxyType<Derived> Info;
protected:
Derived &self() { return *static_cast<Derived *>(this); }
* @return A reference to this stat.
*/
Derived &
- name(const std::string &_name)
+ name(const std::string &name)
{
Info *info = this->info();
- info->name = _name;
- info->flags |= print;
+ info->setName(name);
+ info->flags.set(print);
return this->self();
}
const std::string &name() const { return this->info()->name; }
* @return A reference to this stat.
*/
Derived &
- flags(StatFlags _flags)
+ flags(Flags _flags)
{
- this->info()->flags |= _flags;
+ this->info()->flags.set(_flags);
return this->self();
}
}
};
-template <class Derived, template <class> class InfoType>
-class DataWrapVec : public DataWrap<Derived, InfoType>
+template <class Derived, template <class> class InfoProxyType>
+class DataWrapVec : public DataWrap<Derived, InfoProxyType>
{
public:
- typedef InfoType<Derived> Info;
+ typedef InfoProxyType<Derived> Info;
// The following functions are specific to vectors. If you use them
// in a non vector context, you will get a nice compiler error!
}
};
-template <class Derived, template <class> class InfoType>
-class DataWrapVec2d : public DataWrapVec<Derived, InfoType>
+template <class Derived, template <class> class InfoProxyType>
+class DataWrapVec2d : public DataWrapVec<Derived, InfoProxyType>
{
public:
- typedef InfoType<Derived> Info;
+ typedef InfoProxyType<Derived> Info;
/**
* @warning This makes the assumption that if you're gonna subnames a 2d
* Storage template.
*/
template <class Derived, class Stor>
-class ScalarBase : public DataWrap<Derived, ScalarInfo>
+class ScalarBase : public DataWrap<Derived, ScalarInfoProxy>
{
public:
typedef Stor Storage;
void prepare() { data()->prepare(this->info()); }
};
-class ProxyInfo : public ScalarInfoBase
+class ProxyInfo : public ScalarInfo
{
public:
std::string str() const { return to_string(value()); }
};
template <class Derived>
-class ValueBase : public DataWrap<Derived, ScalarInfo>
+class ValueBase : public DataWrap<Derived, ScalarInfoProxy>
{
private:
ProxyInfo *proxy;
* Return the current value of this stat as its base type.
* @return The current value.
*/
- Counter value() const { return stat->data(index)->value(); }
+ Counter value() const { return stat.data(index)->value(); }
/**
* Return the current value of this statas a result type.
* @return The current value.
*/
- Result result() const { return stat->data(index)->result(); }
+ Result result() const { return stat.data(index)->result(); }
public:
/**
* Storage class. @sa ScalarBase
*/
template <class Derived, class Stor>
-class VectorBase : public DataWrapVec<Derived, VectorInfo>
+class VectorBase : public DataWrapVec<Derived, VectorInfoProxy>
{
public:
typedef Stor Storage;
/** Proxy type */
typedef ScalarProxy<Derived> Proxy;
friend class ScalarProxy<Derived>;
- friend class DataWrapVec<Derived, VectorInfo>;
+ friend class DataWrapVec<Derived, VectorInfoProxy>;
protected:
/** The storage of this stat. */
};
template <class Derived, class Stor>
-class Vector2dBase : public DataWrapVec2d<Derived, Vector2dInfo>
+class Vector2dBase : public DataWrapVec2d<Derived, Vector2dInfoProxy>
{
public:
- typedef Vector2dInfo<Derived> Info;
+ typedef Vector2dInfoProxy<Derived> Info;
typedef Stor Storage;
typedef typename Stor::Params Params;
typedef VectorProxy<Derived> Proxy;
friend class ScalarProxy<Derived>;
friend class VectorProxy<Derived>;
- friend class DataWrapVec<Derived, Vector2dInfo>;
- friend class DataWrapVec2d<Derived, Vector2dInfo>;
+ friend class DataWrapVec<Derived, Vector2dInfoProxy>;
+ friend class DataWrapVec2d<Derived, Vector2dInfoProxy>;
protected:
size_type x;
{
public:
/** The parameters for a distribution stat. */
- struct Params : public StorageParams
- {
- /** The minimum value to track. */
- Counter min;
- /** The maximum value to track. */
- Counter max;
- /** The number of entries in each bucket. */
- Counter bucket_size;
- /** The number of buckets. Equal to (max-min)/bucket_size. */
- size_type buckets;
-
- enum { fancy = false };
+ struct Params : public DistParams
+ {
+ Params() : DistParams(Dist) {}
};
private:
data.underflow = underflow;
data.overflow = overflow;
- int buckets = params->buckets;
+ size_type buckets = params->buckets;
data.cvec.resize(buckets);
for (off_type i = 0; i < buckets; ++i)
data.cvec[i] = cvec[i];
min_val = CounterLimits::max();
max_val = CounterLimits::min();
- underflow = 0;
- overflow = 0;
+ underflow = Counter();
+ overflow = Counter();
size_type size = cvec.size();
for (off_type i = 0; i < size; ++i)
* Templatized storage and interface for a distribution that calculates mean
* and variance.
*/
-class FancyStor
+class SampleStor
{
public:
- struct Params : public StorageParams
+ struct Params : public DistParams
{
- enum { fancy = true };
+ Params() : DistParams(Deviation) {}
};
private:
/**
* Create and initialize this storage.
*/
- FancyStor(Info *info)
+ SampleStor(Info *info)
: sum(Counter()), squares(Counter()), samples(Counter())
{ }
* Templatized storage for distribution that calculates per tick mean and
* variance.
*/
-class AvgFancy
+class AvgSampleStor
{
public:
- struct Params : public StorageParams
+ struct Params : public DistParams
{
- enum { fancy = true };
+ Params() : DistParams(Deviation) {}
};
private:
/**
* Create and initialize this storage.
*/
- AvgFancy(Info *info)
+ AvgSampleStor(Info *info)
: sum(Counter()), squares(Counter())
{}
* determined by the Storage template. @sa ScalarBase
*/
template <class Derived, class Stor>
-class DistBase : public DataWrap<Derived, DistInfo>
+class DistBase : public DataWrap<Derived, DistInfoProxy>
{
public:
- typedef DistInfo<Derived> Info;
+ typedef DistInfoProxy<Derived> Info;
typedef Stor Storage;
typedef typename Stor::Params Params;
class DistProxy;
template <class Derived, class Stor>
-class VectorDistBase : public DataWrapVec<Derived, VectorDistInfo>
+class VectorDistBase : public DataWrapVec<Derived, VectorDistInfoProxy>
{
public:
- typedef VectorDistInfo<Derived> Info;
+ typedef VectorDistInfoProxy<Derived> Info;
typedef Stor Storage;
typedef typename Stor::Params Params;
typedef DistProxy<Derived> Proxy;
friend class DistProxy<Derived>;
- friend class DataWrapVec<Derived, VectorDistInfo>;
+ friend class DataWrapVec<Derived, VectorDistInfoProxy>;
protected:
Storage *storage;
class ScalarStatNode : public Node
{
private:
- const ScalarInfoBase *data;
+ const ScalarInfo *data;
mutable VResult vresult;
public:
- ScalarStatNode(const ScalarInfoBase *d) : data(d), vresult(1) {}
+ ScalarStatNode(const ScalarInfo *d) : data(d), vresult(1) {}
const VResult &
result() const
class VectorStatNode : public Node
{
private:
- const VectorInfoBase *data;
+ const VectorInfo *data;
public:
- VectorStatNode(const VectorInfoBase *d) : data(d) { }
+ VectorStatNode(const VectorInfo *d) : data(d) { }
const VResult &result() const { return data->result(); }
Result total() const { return data->total(); };
/**
* Calculates the mean and variance of all the samples.
- * @sa Stat, DistBase, FancyStor
+ * @sa DistBase, SampleStor
*/
-class StandardDeviation : public DistBase<StandardDeviation, FancyStor>
+class StandardDeviation : public DistBase<StandardDeviation, SampleStor>
{
public:
/**
/**
* Calculates the per tick mean and variance of the samples.
- * @sa Stat, DistBase, AvgFancy
+ * @sa DistBase, AvgSampleStor
*/
-class AverageDeviation : public DistBase<AverageDeviation, AvgFancy>
+class AverageDeviation : public DistBase<AverageDeviation, AvgSampleStor>
{
public:
/**
/**
* A vector of distributions.
- * @sa Stat, VectorDistBase, DistStor
+ * @sa VectorDistBase, DistStor
*/
class VectorDistribution : public VectorDistBase<VectorDistribution, DistStor>
{
params->min = min;
params->max = max;
params->bucket_size = bkt;
- params->buckets = rint((max - min) / bkt + 1.0);
+ params->buckets = (size_type)rint((max - min) / bkt + 1.0);
this->setParams(params);
this->doInit(size);
return this->self();
/**
* This is a vector of StandardDeviation stats.
- * @sa Stat, VectorDistBase, FancyStor
+ * @sa VectorDistBase, SampleStor
*/
class VectorStandardDeviation
- : public VectorDistBase<VectorStandardDeviation, FancyStor>
+ : public VectorDistBase<VectorStandardDeviation, SampleStor>
{
public:
/**
/**
* This is a vector of AverageDeviation stats.
- * @sa Stat, VectorDistBase, AvgFancy
+ * @sa VectorDistBase, AvgSampleStor
*/
class VectorAverageDeviation
- : public VectorDistBase<VectorAverageDeviation, AvgFancy>
+ : public VectorDistBase<VectorAverageDeviation, AvgSampleStor>
{
public:
/**
}
};
-class FormulaInfoBase : public VectorInfoBase
-{
- public:
- virtual std::string str() const = 0;
-};
-
template <class Stat>
-class FormulaInfo : public InfoWrap<Stat, FormulaInfoBase>
+class FormulaInfoProxy : public InfoProxy<Stat, FormulaInfo>
{
protected:
mutable VResult vec;
mutable VCounter cvec;
public:
- FormulaInfo(Stat &stat) : InfoWrap<Stat, FormulaInfoBase>(stat) {}
+ FormulaInfoProxy(Stat &stat) : InfoProxy<Stat, FormulaInfo>(stat) {}
size_type size() const { return this->s.size(); }
* stored as a tree of Nodes that represent the equation to calculate.
* @sa Stat, ScalarStat, VectorStat, Node, Temp
*/
-class Formula : public DataWrapVec<Formula, FormulaInfo>
+class Formula : public DataWrapVec<Formula, FormulaInfoProxy>
{
protected:
/** The root of the tree which represents the Formula */