namespace Stats {
-StatData *
-DataAccess::find() const
+Info *
+InfoAccess::find() const
{
return Database::find(const_cast<void *>((const void *)this));
}
-const StatData *
-getStatData(const void *stat)
+const Info *
+getInfo(const void *stat)
{
return Database::find(const_cast<void *>(stat));
}
void
-DataAccess::map(StatData *data)
+InfoAccess::setInfo(Info *info)
{
- Database::regStat(this, data);
+ Database::regStat(this, info);
}
-StatData *
-DataAccess::statData()
-{
- StatData *ptr = find();
- assert(ptr);
- return ptr;
-}
-
-const StatData *
-DataAccess::statData() const
+void
+InfoAccess::setInit()
{
- const StatData *ptr = find();
- assert(ptr);
- return ptr;
+ info()->flags |= init;
}
-void
-DataAccess::setInit()
+Info *
+InfoAccess::info()
{
- statData()->flags |= init;
+ Info *info = find();
+ assert(info);
+ return info;
}
-void
-DataAccess::setPrint()
+const Info *
+InfoAccess::info() const
{
- Database::regPrint(this);
+ const Info *info = find();
+ assert(info);
+ return info;
}
-StatData::StatData()
+Info::Info()
: flags(none), precision(-1), prereq(0)
{
static int count = 0;
id = count++;
}
-StatData::~StatData()
+Info::~Info()
{
}
bool
-StatData::less(StatData *stat1, StatData *stat2)
+Info::less(Info *stat1, Info *stat2)
{
const string &name1 = stat1->name;
const string &name2 = stat2->name;
}
bool
-StatData::baseCheck() const
+Info::baseCheck() const
{
if (!(flags & init)) {
#ifdef DEBUG
}
void
-FormulaBase::update(StatData *)
+FormulaBase::update(Info *)
{
}
iter_t i, end = Database::stats().end();
for (i = Database::stats().begin(); i != end; ++i) {
- StatData *data = *i;
- assert(data);
- if (!data->check() || !data->baseCheck())
- panic("stat check failed for %s\n", data->name);
+ Info *info = *i;
+ assert(info);
+ if (!info->check() || !info->baseCheck())
+ panic("stat check failed for %s\n", info->name);
}
off_t j = 0;
for (i = Database::stats().begin(); i != end; ++i) {
- StatData *data = *i;
- if (!(data->flags & print))
- data->name = "__Stat" + to_string(j++);
+ Info *info = *i;
+ if (!(info->flags & print))
+ info->name = "__Stat" + to_string(j++);
}
- Database::stats().sort(StatData::less);
+ Database::stats().sort(Info::less);
if (i == end)
return;
Database::stat_list_t::iterator i = Database::stats().begin();
Database::stat_list_t::iterator end = Database::stats().end();
while (i != end) {
- StatData *data = *i;
- data->reset();
+ Info *info = *i;
+ info->reset();
++i;
}
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Authors: Nathan Binkert
- * Erik Hallnor
*/
/** @file
#include <string>
#include <vector>
+#include "base/cast.hh"
#include "base/cprintf.hh"
#include "base/intmath.hh"
#include "base/refcnt.hh"
// Statistics Framework Base classes
//
//////////////////////////////////////////////////////////////////////
-struct StatData
+class Info
{
+ public:
/** The name of the stat. */
std::string name;
/** The description of the stat. */
/** The display precision. */
int precision;
/** A pointer to a prerequisite Stat. */
- const StatData *prereq;
+ const Info *prereq;
/**
* A unique stat ID for each stat in the simulator.
* Can be used externally for lookups as well as for debugging.
*/
int id;
- StatData();
- virtual ~StatData();
+ public:
+ Info();
+ virtual ~Info();
/**
* Reset the corresponding stat to the default state.
* @param stat2 The second stat.
* @return stat1's name is alphabetically before stat2's
*/
- static bool less(StatData *stat1, StatData *stat2);
+ static bool less(Info *stat1, Info *stat2);
};
-class ScalarData : public StatData
+class ScalarInfoBase : public Info
{
public:
virtual Counter value() const = 0;
};
template <class Stat>
-class ScalarStatData : public ScalarData
+class ScalarInfo : public ScalarInfoBase
{
protected:
Stat &s;
public:
- ScalarStatData(Stat &stat) : s(stat) {}
+ ScalarInfo(Stat &stat) : s(stat) {}
virtual bool check() const { return s.check(); }
virtual Counter value() const { return s.value(); }
virtual bool zero() const { return s.zero(); }
};
-struct VectorData : public StatData
+class VectorInfoBase : public Info
{
+ public:
/** Names and descriptions of subfields. */
mutable std::vector<std::string> subnames;
mutable std::vector<std::string> subdescs;
+ public:
virtual size_type size() const = 0;
virtual const VCounter &value() const = 0;
virtual const VResult &result() const = 0;
};
template <class Stat>
-class VectorStatData : public VectorData
+class VectorInfo : public VectorInfoBase
{
protected:
Stat &s;
mutable VResult rvec;
public:
- VectorStatData(Stat &stat) : s(stat) {}
+ VectorInfo(Stat &stat) : s(stat) {}
virtual bool check() const { return s.check(); }
virtual bool zero() const { return s.zero(); }
}
};
-struct DistDataData
+struct DistData
{
Counter min_val;
Counter max_val;
bool fancy;
};
-struct DistData : public StatData
+class DistInfoBase : public Info
{
+ public:
/** Local storage for the entry values, used for printing. */
- DistDataData data;
+ DistData data;
};
template <class Stat>
-class DistStatData : public DistData
+class DistInfo : public DistInfoBase
{
protected:
Stat &s;
public:
- DistStatData(Stat &stat) : s(stat) {}
+ DistInfo(Stat &stat) : s(stat) {}
virtual bool check() const { return s.check(); }
virtual void reset() { s.reset(); }
}
};
-struct VectorDistData : public StatData
+class VectorDistInfoBase : public Info
{
- std::vector<DistDataData> data;
+ public:
+ std::vector<DistData> data;
/** Names and descriptions of subfields. */
mutable std::vector<std::string> subnames;
mutable std::vector<std::string> subdescs;
+ protected:
/** Local storage for the entry values, used for printing. */
mutable VResult rvec;
+ public:
virtual size_type size() const = 0;
void
};
template <class Stat>
-class VectorDistStatData : public VectorDistData
+class VectorDistInfo : public VectorDistInfoBase
{
protected:
Stat &s;
public:
- VectorDistStatData(Stat &stat) : s(stat) {}
+ VectorDistInfo(Stat &stat) : s(stat) {}
virtual bool check() const { return s.check(); }
virtual void reset() { s.reset(); }
}
};
-struct Vector2dData : public StatData
+class Vector2dInfoBase : public Info
{
+ public:
/** Names and descriptions of subfields. */
std::vector<std::string> subnames;
std::vector<std::string> subdescs;
mutable size_type x;
mutable size_type y;
+ public:
void
update()
{
};
template <class Stat>
-class Vector2dStatData : public Vector2dData
+class Vector2dInfo : public Vector2dInfoBase
{
protected:
Stat &s;
public:
- Vector2dStatData(Stat &stat) : s(stat) {}
+ Vector2dInfo(Stat &stat) : s(stat) {}
virtual bool check() const { return s.check(); }
virtual void reset() { s.reset(); }
}
};
-class DataAccess
+class InfoAccess
{
protected:
- StatData *find() const;
- void map(StatData *data);
-
- StatData *statData();
- const StatData *statData() const;
-
+ Info *find() const;
+ /** Set up an info class for this statistic */
+ void setInfo(Info *info);
+ /** Save Storage class parameters if any */
void setInit();
- void setPrint();
+
+ Info *info();
+ const Info *info() const;
};
-template <class Parent, class Child, template <class> class Data>
+template <class Parent, class Child, template <class> class Info>
class Wrap : public Child
{
+ public:
+ typedef Parent ParentType;
+ typedef Child ChildType;
+ typedef Info<Child> InfoType;
+
protected:
Parent &self() { return *reinterpret_cast<Parent *>(this); }
protected:
- Data<Child> *
- statData()
+ InfoType *
+ info()
{
- StatData *__data = DataAccess::statData();
- Data<Child> *ptr = dynamic_cast<Data<Child> *>(__data);
- assert(ptr);
- return ptr;
+ return safe_cast<InfoType *>(InfoAccess::info());
}
public:
- const Data<Child> *
- statData() const
+ const InfoType *
+ info() const
{
- const StatData *__data = DataAccess::statData();
- const Data<Child> *ptr = dynamic_cast<const Data<Child> *>(__data);
- assert(ptr);
- return ptr;
+ return safe_cast<const InfoType *>(InfoAccess::info());
}
protected:
public:
Wrap()
{
- this->map(new Data<Child>(*this));
+ this->setInfo(new InfoType(*this));
}
/**
Parent &
name(const std::string &_name)
{
- Data<Child> *data = this->statData();
- data->name = _name;
- this->setPrint();
+ InfoType *info = this->info();
+ info->name = _name;
+ info->flags |= print;
return this->self();
}
Parent &
desc(const std::string &_desc)
{
- this->statData()->desc = _desc;
+ this->info()->desc = _desc;
return this->self();
}
Parent &
precision(int _precision)
{
- this->statData()->precision = _precision;
+ this->info()->precision = _precision;
return this->self();
}
Parent &
flags(StatFlags _flags)
{
- this->statData()->flags |= _flags;
+ this->info()->flags |= _flags;
return this->self();
}
Parent &
prereq(const Stat &prereq)
{
- this->statData()->prereq = prereq.statData();
+ this->info()->prereq = prereq.info();
return this->self();
}
};
-template <class Parent, class Child, template <class Child> class Data>
-class WrapVec : public Wrap<Parent, Child, Data>
+template <class Parent, class Child, template <class Child> class Info>
+class WrapVec : public Wrap<Parent, Child, Info>
{
+ public:
+ typedef Parent ParentType;
+ typedef Child ChildType;
+ typedef Info<Child> InfoType;
+
public:
// The following functions are specific to vectors. If you use them
// in a non vector context, you will get a nice compiler error!
Parent &
subname(off_type index, const std::string &name)
{
- std::vector<std::string> &subn = this->statData()->subnames;
+ std::vector<std::string> &subn = this->info()->subnames;
if (subn.size() <= index)
subn.resize(index + 1);
subn[index] = name;
Parent &
subdesc(off_type index, const std::string &desc)
{
- std::vector<std::string> &subd = this->statData()->subdescs;
+ std::vector<std::string> &subd = this->info()->subdescs;
if (subd.size() <= index)
subd.resize(index + 1);
subd[index] = desc;
};
-template <class Parent, class Child, template <class Child> class Data>
-class WrapVec2d : public WrapVec<Parent, Child, Data>
+template <class Parent, class Child, template <class Child> class Info>
+class WrapVec2d : public WrapVec<Parent, Child, Info>
{
+ public:
+ typedef Parent ParentType;
+ typedef Child ChildType;
+ typedef Info<Child> InfoType;
+
public:
/**
* @warning This makes the assumption that if you're gonna subnames a 2d
Parent &
ysubnames(const char **names)
{
- Data<Child> *data = this->statData();
- data->y_subnames.resize(this->y);
+ InfoType *info = this->info();
+ info->y_subnames.resize(this->y);
for (off_type i = 0; i < this->y; ++i)
- data->y_subnames[i] = names[i];
+ info->y_subnames[i] = names[i];
return this->self();
}
Parent &
ysubname(off_type index, const std::string subname)
{
- Data<Child> *data = this->statData();
+ InfoType *info = this->info();
assert(index < this->y);
- data->y_subnames.resize(this->y);
- data->y_subnames[index] = subname.c_str();
+ info->y_subnames.resize(this->y);
+ info->y_subnames[index] = subname.c_str();
return this->self();
}
};
/**
* Templatized storage and interface for a simple scalar stat.
*/
-struct StatStor
+class StatStor
{
public:
/** The paramaters for this storage type, none for a scalar. */
* being watched. This is good for keeping track of residencies in structures
* among other things.
*/
-struct AvgStor
+class AvgStor
{
public:
/** The paramaters for this storage type */
* @param p The parameters for this storage.
*/
void
- set(Counter val, Params &p) {
+ set(Counter val, Params &p)
+ {
total += current * (curTick - last);
last = curTick;
current = val;
* Storage template.
*/
template <class Stor>
-class ScalarBase : public DataAccess
+class ScalarBase : public InfoAccess
{
public:
typedef Stor Storage;
};
-class ProxyData : public ScalarData
+class ProxyInfo : public ScalarInfoBase
{
public:
virtual void visit(Visit &visitor) { visitor.visit(*this); }
};
template <class T>
-class ValueProxy : public ProxyData
+class ValueProxy : public ProxyInfo
{
private:
T *scalar;
};
template <class T>
-class FunctorProxy : public ProxyData
+class FunctorProxy : public ProxyInfo
{
private:
T *functor;
virtual Result total() const { return (*functor)(); }
};
-class ValueBase : public DataAccess
+class ValueBase : public InfoAccess
{
private:
- ProxyData *proxy;
+ ProxyInfo *proxy;
public:
ValueBase() : proxy(NULL) { }
* @return A reference to this proxy.
*/
const ScalarProxy &
- operator=(const ScalarProxy &sp) {
+ operator=(const ScalarProxy &sp)
+ {
stat = sp.stat;
index = sp.index;
return *this;
std::string
str() const
{
- return csprintf("%s[%d]", stat->statData()->name, index);
+ return csprintf("%s[%d]", stat->info()->name, index);
}
};
* Storage class. @sa ScalarBase
*/
template <class Stor>
-class VectorBase : public DataAccess
+class VectorBase : public InfoAccess
{
public:
typedef Stor Storage;
return Proxy(this, index);
}
- void update(StatData *data) {}
+ void update(Info *data) {}
};
template <class Stat>
};
template <class Stor>
-class Vector2dBase : public DataAccess
+class Vector2dBase : public InfoAccess
{
public:
typedef Stor Storage;
assert(_x > 0 && _y > 0 && "sizes must be positive!");
assert(!storage && "already initialized");
- Vector2dData *statdata = dynamic_cast<Vector2dData *>(find());
+ Vector2dInfoBase *info = dynamic_cast<Vector2dInfoBase *>(find());
x = _x;
y = _y;
- statdata->x = _x;
- statdata->y = _y;
+ info->x = _x;
+ info->y = _y;
_size = x * y;
char *ptr = new char[_size * sizeof(Storage)];
}
void
- update(Vector2dData *newdata)
+ update(Vector2dInfoBase *newinfo)
{
size_type size = this->size();
- newdata->cvec.resize(size);
+ newinfo->cvec.resize(size);
for (off_type i = 0; i < size; ++i)
- newdata->cvec[i] = data(i)->value(params);
+ newinfo->cvec[i] = data(i)->value();
}
std::string ysubname(off_type i) const { return (*this->y_subnames)[i]; }
/**
* Templatized storage and interface for a distrbution stat.
*/
-struct DistStor
+class DistStor
{
public:
/** The parameters for a distribution stat. */
}
void
- update(DistDataData *data, const Params ¶ms)
+ update(DistData *data, const Params ¶ms)
{
data->min = params.min;
data->max = params.max;
* Templatized storage and interface for a distribution that calculates mean
* and variance.
*/
-struct FancyStor
+class FancyStor
{
public:
/**
}
void
- update(DistDataData *data, const Params ¶ms)
+ update(DistData *data, const Params ¶ms)
{
data->sum = sum;
data->squares = squares;
* Templatized storage for distribution that calculates per tick mean and
* variance.
*/
-struct AvgFancy
+class AvgFancy
{
public:
/** No parameters for this storage. */
}
void
- update(DistDataData *data, const Params ¶ms)
+ update(DistData *data, const Params ¶ms)
{
data->sum = sum;
data->squares = squares;
* determined by the Storage template. @sa ScalarBase
*/
template <class Stor>
-class DistBase : public DataAccess
+class DistBase : public InfoAccess
{
public:
typedef Stor Storage;
bool zero() const { return data()->zero(params); }
void
- update(DistData *base)
+ update(DistInfoBase *base)
{
base->data.fancy = Storage::fancy;
data()->update(&(base->data), params);
class DistProxy;
template <class Stor>
-class VectorDistBase : public DataAccess
+class VectorDistBase : public InfoAccess
{
public:
typedef Stor Storage;
}
void
- update(VectorDistData *base)
+ update(VectorDistInfoBase *base)
{
size_type size = this->size();
base->data.resize(size);
class ScalarStatNode : public Node
{
private:
- const ScalarData *data;
+ const ScalarInfoBase *data;
mutable VResult vresult;
public:
- ScalarStatNode(const ScalarData *d) : data(d), vresult(1) {}
+ ScalarStatNode(const ScalarInfoBase *d) : data(d), vresult(1) {}
virtual const VResult &
result() const
class VectorStatNode : public Node
{
private:
- const VectorData *data;
+ const VectorInfoBase *data;
public:
- VectorStatNode(const VectorData *d) : data(d) { }
+ VectorStatNode(const VectorInfoBase *d) : data(d) { }
virtual const VResult &result() const { return data->result(); }
virtual Result total() const { return data->total(); };
* @sa Stat, ScalarBase, StatStor
*/
template<int N = 0>
-class Scalar : public Wrap<Scalar<N>, ScalarBase<StatStor>, ScalarStatData>
+class Scalar : public Wrap<Scalar<N>, ScalarBase<StatStor>, ScalarInfo>
{
public:
/** The base implementation. */
void operator=(const U &v) { Base::operator=(v); }
};
-class Value : public Wrap<Value, ValueBase, ScalarStatData>
+class Value : public Wrap<Value, ValueBase, ScalarInfo>
{
public:
/** The base implementation. */
* @sa Stat, ScalarBase, AvgStor
*/
template<int N = 0>
-class Average : public Wrap<Average<N>, ScalarBase<AvgStor>, ScalarStatData>
+class Average : public Wrap<Average<N>, ScalarBase<AvgStor>, ScalarInfo>
{
public:
/** The base implementation. */
* @sa Stat, VectorBase, StatStor
*/
template<int N = 0>
-class Vector : public WrapVec<Vector<N>, VectorBase<StatStor>, VectorStatData>
+class Vector : public WrapVec<Vector<N>, VectorBase<StatStor>, VectorInfo>
{
public:
/** The base implementation. */
*/
template<int N = 0>
class AverageVector
- : public WrapVec<AverageVector<N>, VectorBase<AvgStor>, VectorStatData>
+ : public WrapVec<AverageVector<N>, VectorBase<AvgStor>, VectorInfo>
{
public:
/**
*/
template<int N = 0>
class Vector2d
- : public WrapVec2d<Vector2d<N>, Vector2dBase<StatStor>, Vector2dStatData>
+ : public WrapVec2d<Vector2d<N>, Vector2dBase<StatStor>, Vector2dInfo>
{
public:
Vector2d &
*/
template<int N = 0>
class Distribution
- : public Wrap<Distribution<N>, DistBase<DistStor>, DistStatData>
+ : public Wrap<Distribution<N>, DistBase<DistStor>, DistInfo>
{
public:
/** Base implementation. */
*/
template<int N = 0>
class StandardDeviation
- : public Wrap<StandardDeviation<N>, DistBase<FancyStor>, DistStatData>
+ : public Wrap<StandardDeviation<N>, DistBase<FancyStor>, DistInfo>
{
public:
/** The base implementation */
*/
template<int N = 0>
class AverageDeviation
- : public Wrap<AverageDeviation<N>, DistBase<AvgFancy>, DistStatData>
+ : public Wrap<AverageDeviation<N>, DistBase<AvgFancy>, DistInfo>
{
public:
/** The base implementation */
class VectorDistribution
: public WrapVec<VectorDistribution<N>,
VectorDistBase<DistStor>,
- VectorDistStatData>
+ VectorDistInfo>
{
public:
/** The base implementation */
class VectorStandardDeviation
: public WrapVec<VectorStandardDeviation<N>,
VectorDistBase<FancyStor>,
- VectorDistStatData>
+ VectorDistInfo>
{
public:
/** The base implementation */
class VectorAverageDeviation
: public WrapVec<VectorAverageDeviation<N>,
VectorDistBase<AvgFancy>,
- VectorDistStatData>
+ VectorDistInfo>
{
public:
/** The base implementation */
* stored as a tree of Nodes that represent the equation to calculate.
* @sa Stat, ScalarStat, VectorStat, Node, Temp
*/
-class FormulaBase : public DataAccess
+class FormulaBase : public InfoAccess
{
protected:
/** The root of the tree which represents the Formula */
/**
*
*/
- void update(StatData *);
+ void update(Info *);
std::string str() const;
};
-class FormulaData : public VectorData
+class FormulaInfoBase : public VectorInfoBase
{
public:
virtual std::string str() const = 0;
};
template <class Stat>
-class FormulaStatData : public FormulaData
+class FormulaInfo : public FormulaInfoBase
{
protected:
Stat &s;
mutable VCounter cvec;
public:
- FormulaStatData(Stat &stat) : s(stat) {}
+ FormulaInfo(Stat &stat) : s(stat) {}
virtual bool zero() const { return s.zero(); }
virtual void reset() { s.reset(); }
class Formula
: public WrapVec<Formula,
FormulaBase,
- FormulaStatData>
+ FormulaInfo>
{
public:
/**
*/
template <int N>
Temp(const Scalar<N> &s)
- : node(new ScalarStatNode(s.statData()))
+ : node(new ScalarStatNode(s.info()))
{ }
/**
* @param s The ScalarStat to place in a node.
*/
Temp(const Value &s)
- : node(new ScalarStatNode(s.statData()))
+ : node(new ScalarStatNode(s.info()))
{ }
/**
*/
template <int N>
Temp(const Average<N> &s)
- : node(new ScalarStatNode(s.statData()))
+ : node(new ScalarStatNode(s.info()))
{ }
/**
*/
template <int N>
Temp(const Vector<N> &s)
- : node(new VectorStatNode(s.statData()))
+ : node(new VectorStatNode(s.info()))
{ }
/**
}
for (i = stats().begin(); i != end; ++i) {
- StatData *data = *i;
- if (data->prereq) {
+ Info *info = *i;
+ if (info->prereq) {
// update the prerequisite
- uint16_t stat_id = find(data->id);
- uint16_t prereq_id = find(data->prereq->id);
+ uint16_t stat_id = find(info->id);
+ uint16_t prereq_id = find(info->prereq->id);
assert(stat_id && prereq_id);
stringstream update;
configured = true;
}
-
bool
-MySql::configure(const StatData &data, string type)
+MySql::configure(const Info &info, string type)
{
stat.init();
- stat.name = data.name;
- stat.descr = data.desc;
+ stat.name = info.name;
+ stat.descr = info.desc;
stat.type = type;
- stat.print = data.flags & print;
- stat.prec = data.precision;
- stat.nozero = data.flags & nozero;
- stat.nonan = data.flags & nonan;
- stat.total = data.flags & total;
- stat.pdf = data.flags & pdf;
- stat.cdf = data.flags & cdf;
+ stat.print = info.flags & print;
+ stat.prec = info.precision;
+ stat.nozero = info.flags & nozero;
+ stat.nonan = info.flags & nonan;
+ stat.total = info.flags & total;
+ stat.pdf = info.flags & pdf;
+ stat.cdf = info.flags & cdf;
return stat.print;
}
void
-MySql::configure(const ScalarData &data)
+MySql::configure(const ScalarInfoBase &info)
{
- if (!configure(data, "SCALAR"))
+ if (!configure(info, "SCALAR"))
return;
- insert(data.id, stat.setup(run));
+ insert(info.id, stat.setup(run));
}
void
-MySql::configure(const VectorData &data)
+MySql::configure(const VectorInfoBase &info)
{
- if (!configure(data, "VECTOR"))
+ if (!configure(info, "VECTOR"))
return;
uint16_t statid = stat.setup(run);
- if (!data.subnames.empty()) {
+ if (!info.subnames.empty()) {
InsertSubData subdata;
subdata.stat = statid;
subdata.y = 0;
- for (off_type i = 0; i < data.subnames.size(); ++i) {
+ for (off_type i = 0; i < info.subnames.size(); ++i) {
subdata.x = i;
- subdata.name = data.subnames[i];
- subdata.descr = data.subdescs.empty() ? "" : data.subdescs[i];
+ subdata.name = info.subnames[i];
+ subdata.descr = info.subdescs.empty() ? "" : info.subdescs[i];
if (!subdata.name.empty() || !subdata.descr.empty())
subdata.setup(run);
}
}
- insert(data.id, statid);
+ insert(info.id, statid);
}
void
-MySql::configure(const DistData &data)
+MySql::configure(const DistInfoBase &info)
{
- if (!configure(data, "DIST"))
+ if (!configure(info, "DIST"))
return;
- if (!data.data.fancy) {
- stat.size = data.data.size;
- stat.min = data.data.min;
- stat.max = data.data.max;
- stat.bktsize = data.data.bucket_size;
+ if (!info.data.fancy) {
+ stat.size = info.data.size;
+ stat.min = info.data.min;
+ stat.max = info.data.max;
+ stat.bktsize = info.data.bucket_size;
}
- insert(data.id, stat.setup(run));
+ insert(info.id, stat.setup(run));
}
void
-MySql::configure(const VectorDistData &data)
+MySql::configure(const VectorDistInfoBase &info)
{
- if (!configure(data, "VECTORDIST"))
+ if (!configure(info, "VECTORDIST"))
return;
- if (!data.data[0].fancy) {
- stat.size = data.data[0].size;
- stat.min = data.data[0].min;
- stat.max = data.data[0].max;
- stat.bktsize = data.data[0].bucket_size;
+ if (!info.data[0].fancy) {
+ stat.size = info.data[0].size;
+ stat.min = info.data[0].min;
+ stat.max = info.data[0].max;
+ stat.bktsize = info.data[0].bucket_size;
}
uint16_t statid = stat.setup(run);
- if (!data.subnames.empty()) {
+ if (!info.subnames.empty()) {
InsertSubData subdata;
subdata.stat = statid;
subdata.y = 0;
- for (off_type i = 0; i < data.subnames.size(); ++i) {
+ for (off_type i = 0; i < info.subnames.size(); ++i) {
subdata.x = i;
- subdata.name = data.subnames[i];
- subdata.descr = data.subdescs.empty() ? "" : data.subdescs[i];
+ subdata.name = info.subnames[i];
+ subdata.descr = info.subdescs.empty() ? "" : info.subdescs[i];
if (!subdata.name.empty() || !subdata.descr.empty())
subdata.setup(run);
}
}
- insert(data.id, statid);
+ insert(info.id, statid);
}
void
-MySql::configure(const Vector2dData &data)
+MySql::configure(const Vector2dInfoBase &info)
{
- if (!configure(data, "VECTOR2D"))
+ if (!configure(info, "VECTOR2D"))
return;
uint16_t statid = stat.setup(run);
- if (!data.subnames.empty()) {
+ if (!info.subnames.empty()) {
InsertSubData subdata;
subdata.stat = statid;
subdata.y = -1;
- for (off_type i = 0; i < data.subnames.size(); ++i) {
+ for (off_type i = 0; i < info.subnames.size(); ++i) {
subdata.x = i;
- subdata.name = data.subnames[i];
- subdata.descr = data.subdescs.empty() ? "" : data.subdescs[i];
+ subdata.name = info.subnames[i];
+ subdata.descr = info.subdescs.empty() ? "" : info.subdescs[i];
if (!subdata.name.empty() || !subdata.descr.empty())
subdata.setup(run);
}
}
- if (!data.y_subnames.empty()) {
+ if (!info.y_subnames.empty()) {
InsertSubData subdata;
subdata.stat = statid;
subdata.x = -1;
subdata.descr = "";
- for (off_type i = 0; i < data.y_subnames.size(); ++i) {
+ for (off_type i = 0; i < info.y_subnames.size(); ++i) {
subdata.y = i;
- subdata.name = data.y_subnames[i];
+ subdata.name = info.y_subnames[i];
if (!subdata.name.empty())
subdata.setup(run);
}
}
- insert(data.id, statid);
+ insert(info.id, statid);
}
void
-MySql::configure(const FormulaData &data)
+MySql::configure(const FormulaInfoBase &info)
{
MySQL::Connection &mysql = run->conn();
assert(mysql.connected());
- configure(data, "FORMULA");
- insert(data.id, stat.setup(run));
+ configure(info, "FORMULA");
+ insert(info.id, stat.setup(run));
- uint16_t stat = find(data.id);
- string formula = data.str();
+ uint16_t stat = find(info.id);
+ string formula = info.str();
stringstream insert_formula;
ccprintf(insert_formula,
Database::stat_list_t::const_iterator i, end = Database::stats().end();
for (i = Database::stats().begin(); i != end; ++i) {
- StatData *stat = *i;
+ Info *stat = *i;
stat->visit(*this);
if (mysql.commit())
panic("could not commit transaction\n%s\n", mysql.error);
newevent.insert(event);
}
-
void
-MySql::output(const ScalarData &data)
+MySql::output(const ScalarInfoBase &info)
{
- if (!(data.flags & print))
+ if (!(info.flags & print))
return;
- newdata.stat = find(data.id);
+ newdata.stat = find(info.id);
newdata.x = 0;
newdata.y = 0;
- newdata.data = data.value();
+ newdata.data = info.value();
newdata.insert();
}
void
-MySql::output(const VectorData &data)
+MySql::output(const VectorInfoBase &info)
{
- if (!(data.flags & print))
+ if (!(info.flags & print))
return;
- newdata.stat = find(data.id);
+ newdata.stat = find(info.id);
newdata.y = 0;
- const VCounter &cvec = data.value();
- size_type size = data.size();
+ const VCounter &cvec = info.value();
+ size_type size = info.size();
for (off_type x = 0; x < size; x++) {
newdata.x = x;
newdata.data = cvec[x];
}
void
-MySql::output(const DistDataData &data)
+MySql::output(const DistData &data)
{
const int db_sum = -1;
const int db_squares = -2;
}
}
-
void
-MySql::output(const DistData &data)
+MySql::output(const DistInfoBase &info)
{
- if (!(data.flags & print))
+ if (!(info.flags & print))
return;
- newdata.stat = find(data.id);
+ newdata.stat = find(info.id);
newdata.y = 0;
- output(data.data);
+ output(info.data);
}
void
-MySql::output(const VectorDistData &data)
+MySql::output(const VectorDistInfoBase &info)
{
- if (!(data.flags & print))
+ if (!(info.flags & print))
return;
- newdata.stat = find(data.id);
+ newdata.stat = find(info.id);
- size_type size = data.data.size();
+ size_type size = info.data.size();
for (off_type y = 0; y < size; ++y) {
newdata.y = y;
- output(data.data[y]);
+ output(info.data[y]);
}
}
void
-MySql::output(const Vector2dData &data)
+MySql::output(const Vector2dInfoBase &info)
{
- if (!(data.flags & print))
+ if (!(info.flags & print))
return;
- newdata.stat = find(data.id);
+ newdata.stat = find(info.id);
off_type index = 0;
- for (off_type x = 0; x < data.x; x++) {
+ for (off_type x = 0; x < info.x; x++) {
newdata.x = x;
- for (off_type y = 0; y < data.y; y++) {
+ for (off_type y = 0; y < info.y; y++) {
newdata.y = y;
- newdata.data = data.cvec[index++];
+ newdata.data = info.cvec[index++];
newdata.insert();
}
}
}
void
-MySql::output(const FormulaData &data)
+MySql::output(const FormulaInfoBase &info)
{
}
* Implement the visitor
*/
void
-MySql::visit(const ScalarData &data)
+MySql::visit(const ScalarInfoBase &info)
{
if (!configured)
- configure(data);
+ configure(info);
else
- output(data);
+ output(info);
}
void
-MySql::visit(const VectorData &data)
+MySql::visit(const VectorInfoBase &info)
{
if (!configured)
- configure(data);
+ configure(info);
else
- output(data);
+ output(info);
}
void
-MySql::visit(const DistData &data)
+MySql::visit(const DistInfoBase &info)
{
return;
if (!configured)
- configure(data);
+ configure(info);
else
- output(data);
+ output(info);
}
void
-MySql::visit(const VectorDistData &data)
+MySql::visit(const VectorDistInfoBase &info)
{
return;
if (!configured)
- configure(data);
+ configure(info);
else
- output(data);
+ output(info);
}
void
-MySql::visit(const Vector2dData &data)
+MySql::visit(const Vector2dInfoBase &info)
{
return;
if (!configured)
- configure(data);
+ configure(info);
else
- output(data);
+ output(info);
}
void
-MySql::visit(const FormulaData &data)
+MySql::visit(const FormulaInfoBase &info)
{
if (!configured)
- configure(data);
+ configure(info);
else
- output(data);
+ output(info);
}
bool
namespace MySQL { class Connection; }
namespace Stats {
-class DistDataData;
+class DistInfoBase;
class MySqlRun;
struct SetupStat
SetupStat stat;
InsertData newdata;
InsertEvent newevent;
- std::list<FormulaData *> formulas;
+ std::list<FormulaInfoBase *> formulas;
bool configured;
protected:
public:
// Implement Visit
- virtual void visit(const ScalarData &data);
- virtual void visit(const VectorData &data);
- virtual void visit(const DistData &data);
- virtual void visit(const VectorDistData &data);
- virtual void visit(const Vector2dData &data);
- virtual void visit(const FormulaData &data);
+ virtual void visit(const ScalarInfoBase &info);
+ virtual void visit(const VectorInfoBase &info);
+ virtual void visit(const DistInfoBase &info);
+ virtual void visit(const VectorDistInfoBase &info);
+ virtual void visit(const Vector2dInfoBase &info);
+ virtual void visit(const FormulaInfoBase &info);
// Implement Output
virtual bool valid() const;
protected:
// Output helper
- void output(const DistDataData &data);
- void output(const ScalarData &data);
- void output(const VectorData &data);
+ void output(const ScalarInfoBase &info);
+ void output(const VectorInfoBase &info);
+ void output(const DistInfoBase &info);
+ void output(const VectorDistInfoBase &info);
+ void output(const Vector2dInfoBase &info);
+ void output(const FormulaInfoBase &info);
void output(const DistData &data);
- void output(const VectorDistData &data);
- void output(const Vector2dData &data);
- void output(const FormulaData &data);
void configure();
- bool configure(const StatData &data, std::string type);
- void configure(const ScalarData &data);
- void configure(const VectorData &data);
- void configure(const DistData &data);
- void configure(const VectorDistData &data);
- void configure(const Vector2dData &data);
- void configure(const FormulaData &data);
+ bool configure(const Info &info, std::string type);
+ void configure(const ScalarInfoBase &info);
+ void configure(const VectorInfoBase &info);
+ void configure(const DistInfoBase &info);
+ void configure(const VectorDistInfoBase &info);
+ void configure(const Vector2dInfoBase &info);
+ void configure(const FormulaInfoBase &info);
};
bool initMySQL(std::string host, std::string database, std::string user,
namespace Stats {
namespace Database {
-StatData *
+Info *
find(void *stat)
{
stat_map_t::const_iterator i = map().find(stat);
}
void
-regStat(void *stat, StatData *data)
+regStat(void *stat, Info *data)
{
if (map().find(stat) != map().end())
panic("shouldn't register stat twice!");
void
regPrint(void *stat)
{
- StatData *data = find(stat);
+ Info *data = find(stat);
assert(data);
data->flags |= print;
}
namespace Stats {
-class StatData;
+class Info;
namespace Database {
-typedef std::map<void *, StatData *> stat_map_t;
-typedef std::list<StatData *> stat_list_t;
+typedef std::map<void *, Info *> stat_map_t;
+typedef std::list<Info *> stat_list_t;
// We wrap the database in a struct to make sure it is built in time.
struct TheDatabase
inline stat_map_t &map() { return db().map; }
inline stat_list_t &stats() { return db().stats; }
-StatData *find(void *stat);
-void regStat(void *stat, StatData *data);
+Info *find(void *stat);
+void regStat(void *stat, Info *data);
void regPrint(void *stat);
inline std::string name() { return "Statistics Database"; }
}
bool
-Text::noOutput(const StatData &data)
+Text::noOutput(const Info &info)
{
- if (!(data.flags & print))
+ if (!(info.flags & print))
return true;
- if (data.prereq && data.prereq->zero())
+ if (info.prereq && info.prereq->zero())
return true;
return false;
}
void
-Text::visit(const ScalarData &data)
+Text::visit(const ScalarInfoBase &info)
{
- if (noOutput(data))
+ if (noOutput(info))
return;
ScalarPrint print;
- print.value = data.result();
- print.name = data.name;
- print.desc = data.desc;
- print.flags = data.flags;
+ print.value = info.result();
+ print.name = info.name;
+ print.desc = info.desc;
+ print.flags = info.flags;
print.compat = compat;
print.descriptions = descriptions;
- print.precision = data.precision;
+ print.precision = info.precision;
print.pdf = NAN;
print.cdf = NAN;
}
void
-Text::visit(const VectorData &data)
+Text::visit(const VectorInfoBase &info)
{
- if (noOutput(data))
+ if (noOutput(info))
return;
- size_type size = data.size();
+ size_type size = info.size();
VectorPrint print;
- print.name = data.name;
- print.desc = data.desc;
- print.flags = data.flags;
+ print.name = info.name;
+ print.desc = info.desc;
+ print.flags = info.flags;
print.compat = compat;
print.descriptions = descriptions;
- print.precision = data.precision;
- print.vec = data.result();
- print.total = data.total();
+ print.precision = info.precision;
+ print.vec = info.result();
+ print.total = info.total();
- if (!data.subnames.empty()) {
+ if (!info.subnames.empty()) {
for (off_type i = 0; i < size; ++i) {
- if (!data.subnames[i].empty()) {
- print.subnames = data.subnames;
+ if (!info.subnames[i].empty()) {
+ print.subnames = info.subnames;
print.subnames.resize(size);
for (off_type i = 0; i < size; ++i) {
- if (!data.subnames[i].empty() &&
- !data.subdescs[i].empty()) {
- print.subdescs = data.subdescs;
+ if (!info.subnames[i].empty() &&
+ !info.subdescs[i].empty()) {
+ print.subdescs = info.subdescs;
print.subdescs.resize(size);
break;
}
}
void
-Text::visit(const Vector2dData &data)
+Text::visit(const Vector2dInfoBase &info)
{
- if (noOutput(data))
+ if (noOutput(info))
return;
bool havesub = false;
VectorPrint print;
- print.subnames = data.y_subnames;
- print.flags = data.flags;
+ print.subnames = info.y_subnames;
+ print.flags = info.flags;
print.compat = compat;
print.descriptions = descriptions;
- print.precision = data.precision;
+ print.precision = info.precision;
- if (!data.subnames.empty()) {
- for (off_type i = 0; i < data.x; ++i)
- if (!data.subnames[i].empty())
+ if (!info.subnames.empty()) {
+ for (off_type i = 0; i < info.x; ++i)
+ if (!info.subnames[i].empty())
havesub = true;
}
- VResult tot_vec(data.y);
+ VResult tot_vec(info.y);
Result super_total = 0.0;
- for (off_type i = 0; i < data.x; ++i) {
- if (havesub && (i >= data.subnames.size() || data.subnames[i].empty()))
+ for (off_type i = 0; i < info.x; ++i) {
+ if (havesub && (i >= info.subnames.size() || info.subnames[i].empty()))
continue;
- off_type iy = i * data.y;
- VResult yvec(data.y);
+ off_type iy = i * info.y;
+ VResult yvec(info.y);
Result total = 0.0;
- for (off_type j = 0; j < data.y; ++j) {
- yvec[j] = data.cvec[iy + j];
+ for (off_type j = 0; j < info.y; ++j) {
+ yvec[j] = info.cvec[iy + j];
tot_vec[j] += yvec[j];
total += yvec[j];
super_total += yvec[j];
}
- print.name = data.name + "_" +
- (havesub ? data.subnames[i] : to_string(i));
- print.desc = data.desc;
+ print.name = info.name + "_" +
+ (havesub ? info.subnames[i] : to_string(i));
+ print.desc = info.desc;
print.vec = yvec;
print.total = total;
print(*stream);
}
- if ((data.flags & ::Stats::total) && (data.x > 1)) {
- print.name = data.name;
- print.desc = data.desc;
+ if ((info.flags & ::Stats::total) && (info.x > 1)) {
+ print.name = info.name;
+ print.desc = info.desc;
print.vec = tot_vec;
print.total = super_total;
print(*stream);
}
void
-Text::visit(const DistData &data)
+Text::visit(const DistInfoBase &info)
{
- if (noOutput(data))
+ if (noOutput(info))
return;
DistPrint print;
- print.name = data.name;
- print.desc = data.desc;
- print.flags = data.flags;
+ print.name = info.name;
+ print.desc = info.desc;
+ print.flags = info.flags;
print.compat = compat;
print.descriptions = descriptions;
- print.precision = data.precision;
+ print.precision = info.precision;
- print.min_val = data.data.min_val;
- print.max_val = data.data.max_val;
- print.underflow = data.data.underflow;
- print.overflow = data.data.overflow;
- print.vec.resize(data.data.cvec.size());
+ const DistData &data = info.data;
+
+ print.min_val = data.min_val;
+ print.max_val = data.max_val;
+ print.underflow = data.underflow;
+ print.overflow = data.overflow;
+ print.vec.resize(data.cvec.size());
for (off_type i = 0; i < print.vec.size(); ++i)
- print.vec[i] = (Result)data.data.cvec[i];
- print.sum = data.data.sum;
- print.squares = data.data.squares;
- print.samples = data.data.samples;
+ print.vec[i] = (Result)data.cvec[i];
+ print.sum = data.sum;
+ print.squares = data.squares;
+ print.samples = data.samples;
- print.min = data.data.min;
- print.max = data.data.max;
- print.bucket_size = data.data.bucket_size;
- print.size = data.data.size;
- print.fancy = data.data.fancy;
+ print.min = data.min;
+ print.max = data.max;
+ print.bucket_size = data.bucket_size;
+ print.size = data.size;
+ print.fancy = data.fancy;
print(*stream);
}
void
-Text::visit(const VectorDistData &data)
+Text::visit(const VectorDistInfoBase &info)
{
- if (noOutput(data))
+ if (noOutput(info))
return;
- for (off_type i = 0; i < data.size(); ++i) {
+ for (off_type i = 0; i < info.size(); ++i) {
DistPrint print;
- print.name = data.name + "_" +
- (data.subnames[i].empty() ? (to_string(i)) : data.subnames[i]);
- print.desc = data.subdescs[i].empty() ? data.desc : data.subdescs[i];
- print.flags = data.flags;
+ print.name = info.name + "_" +
+ (info.subnames[i].empty() ? (to_string(i)) : info.subnames[i]);
+ print.desc = info.subdescs[i].empty() ? info.desc : info.subdescs[i];
+ print.flags = info.flags;
print.compat = compat;
print.descriptions = descriptions;
- print.precision = data.precision;
+ print.precision = info.precision;
- print.min_val = data.data[i].min_val;
- print.max_val = data.data[i].max_val;
- print.underflow = data.data[i].underflow;
- print.overflow = data.data[i].overflow;
- print.vec.resize(data.data[i].cvec.size());
+ print.min_val = info.data[i].min_val;
+ print.max_val = info.data[i].max_val;
+ print.underflow = info.data[i].underflow;
+ print.overflow = info.data[i].overflow;
+ print.vec.resize(info.data[i].cvec.size());
for (off_type j = 0; j < print.vec.size(); ++j)
- print.vec[j] = (Result)data.data[i].cvec[j];
- print.sum = data.data[i].sum;
- print.squares = data.data[i].squares;
- print.samples = data.data[i].samples;
+ print.vec[j] = (Result)info.data[i].cvec[j];
+ print.sum = info.data[i].sum;
+ print.squares = info.data[i].squares;
+ print.samples = info.data[i].samples;
- print.min = data.data[i].min;
- print.max = data.data[i].max;
- print.bucket_size = data.data[i].bucket_size;
- print.size = data.data[i].size;
- print.fancy = data.data[i].fancy;
+ print.min = info.data[i].min;
+ print.max = info.data[i].max;
+ print.bucket_size = info.data[i].bucket_size;
+ print.size = info.data[i].size;
+ print.fancy = info.data[i].fancy;
print(*stream);
}
}
void
-Text::visit(const FormulaData &data)
+Text::visit(const FormulaInfoBase &info)
{
- visit((const VectorData &)data);
+ visit((const VectorInfoBase &)info);
}
bool
std::ostream *stream;
protected:
- bool noOutput(const StatData &data);
+ bool noOutput(const Info &info);
public:
bool compat;
void open(const std::string &file);
// Implement Visit
- virtual void visit(const ScalarData &data);
- virtual void visit(const VectorData &data);
- virtual void visit(const DistData &data);
- virtual void visit(const VectorDistData &data);
- virtual void visit(const Vector2dData &data);
- virtual void visit(const FormulaData &data);
+ virtual void visit(const ScalarInfoBase &info);
+ virtual void visit(const VectorInfoBase &info);
+ virtual void visit(const DistInfoBase &info);
+ virtual void visit(const VectorDistInfoBase &info);
+ virtual void visit(const Vector2dInfoBase &info);
+ virtual void visit(const FormulaInfoBase &info);
// Implement Output
virtual bool valid() const;
namespace Stats {
-class StatData;
-class ScalarData;
-class VectorData;
-class DistDataData;
-class DistData;
-class VectorDistData;
-class Vector2dData;
-class FormulaData;
+class Info;
+class ScalarInfoBase;
+class VectorInfoBase;
+class DistInfoBase;
+class DistInfoBase;
+class VectorDistInfoBase;
+class Vector2dInfoBase;
+class FormulaInfoBase;
struct Visit
{
Visit();
virtual ~Visit();
- virtual void visit(const ScalarData &data) = 0;
- virtual void visit(const VectorData &data) = 0;
- virtual void visit(const DistData &data) = 0;
- virtual void visit(const VectorDistData &data) = 0;
- virtual void visit(const Vector2dData &data) = 0;
- virtual void visit(const FormulaData &data) = 0;
+ virtual void visit(const ScalarInfoBase &info) = 0;
+ virtual void visit(const VectorInfoBase &info) = 0;
+ virtual void visit(const DistInfoBase &info) = 0;
+ virtual void visit(const VectorDistInfoBase &info) = 0;
+ virtual void visit(const Vector2dInfoBase &info) = 0;
+ virtual void visit(const FormulaInfoBase &info) = 0;
};
/* namespace Stats */ }