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.
*/
InfoWrap(Stat &stat) : s(stat) {}
bool check() const { return s.check(); }
+ void prepare() { s.prepare(); }
void reset() { s.reset(); }
+ void
+ visit(Visit &visitor)
+ {
+ visitor.visit(*static_cast<Base *>(this));
+ }
bool zero() const { return s.zero(); }
};
virtual Counter value() const = 0;
virtual Result result() const = 0;
virtual Result total() const = 0;
- void visit(Visit &visitor) { visitor.visit(*this); }
};
template <class Stat>
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;
-
- void
- update()
- {
- if (!subnames.empty()) {
- size_type s = size();
- if (subnames.size() < s)
- subnames.resize(s);
-
- if (subdescs.size() < s)
- subdescs.resize(s);
- }
- }
};
template <class Stat>
}
Result total() const { return this->s.total(); }
-
- void
- visit(Visit &visitor)
- {
- this->update();
- this->s.update();
- visitor.visit(*this);
- }
};
struct DistData
{
public:
DistInfo(Stat &stat) : InfoWrap<Stat, DistInfoBase>(stat) {}
-
- void
- visit(Visit &visitor)
- {
- this->s.update();
- visitor.visit(*this);
- }
};
class VectorDistInfoBase : public Info
/** 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. */
public:
virtual size_type size() const = 0;
-
- void
- update()
- {
- size_type s = size();
- if (subnames.size() < s)
- subnames.resize(s);
-
- if (subdescs.size() < s)
- subdescs.resize(s);
- }
};
template <class Stat>
VectorDistInfo(Stat &stat) : InfoWrap<Stat, VectorDistInfoBase>(stat) {}
size_type size() const { return this->s.size(); }
-
- void
- visit(Visit &visitor)
- {
- this->update();
- this->s.update();
- visitor.visit(*this);
- }
};
class Vector2dInfoBase : public Info
/** Local storage for the entry values, used for printing. */
mutable VCounter cvec;
- public:
- void
- update()
- {
- if (subnames.size() < x)
- subnames.resize(x);
- }
+ void enable();
};
template <class Stat>
{
public:
Vector2dInfo(Stat &stat) : InfoWrap<Stat, Vector2dInfoBase>(stat) {}
-
- void
- visit(Visit &visitor)
- {
- this->update();
- this->s.update();
- visitor.visit(*this);
- }
};
class InfoAccess
/**
* Reset the stat to the default state.
*/
- void reset() {}
+ void reset() { }
/**
* @return true if this stat has a value and satisfies its
subname(off_type index, const std::string &name)
{
Derived &self = this->self();
- Info *info = this->info();
+ Info *info = self.info();
std::vector<std::string> &subn = info->subnames;
if (subn.size() <= index)
return this->self();
}
+ void
+ prepare()
+ {
+ Derived &self = this->self();
+ Info *info = this->info();
+
+ size_t size = self.size();
+ for (off_type i = 0; i < size; ++i)
+ self.data(i)->prepare(info);
+ }
+
void
reset()
{
* @return The value of this stat.
*/
Result result() const { return (Result)data; }
+ /**
+ * Prepare stat data for dumping or serialization
+ */
+ void prepare(Info *info) { }
/**
* Reset stat value to default
*/
Result
result() const
{
- total += current * (curTick - last);
- last = curTick;
+ assert(last == curTick);
return (Result)(total + current) / (Result)(curTick + 1);
}
*/
bool zero() const { return total == 0.0; }
+ /**
+ * Prepare stat data for dumping or serialization
+ */
+ void
+ prepare(Info *info)
+ {
+ total += current * (curTick - last);
+ last = curTick;
+ }
+
/**
* Reset stat value to default
*/
*/
size_type size() const { return 1; }
- /**
- * Reset stat value to default
- */
- void reset() { data()->reset(this->info()); }
-
Counter value() { return data()->value(); }
Result result() { return data()->result(); }
Result total() { return result(); }
bool zero() { return result() == 0.0; }
+
+ void reset() { data()->reset(this->info()); }
+ void prepare() { data()->prepare(this->info()); }
};
class ProxyInfo : public ScalarInfoBase
{
public:
- void visit(Visit &visitor) { visitor.visit(*this); }
std::string str() const { return to_string(value()); }
size_type size() const { return 1; }
bool check() const { return true; }
- void reset() {}
+ void prepare() { }
+ void reset() { }
bool zero() const { return value() == 0; }
+
+ void visit(Visit &visitor) { visitor.visit(*this); }
};
template <class T>
std::string str() const { return proxy->str(); }
bool zero() const { return proxy->zero(); }
bool check() const { return proxy != NULL; }
+ void prepare() { }
void reset() { }
};
assert (index >= 0 && index < size());
return Proxy(this->self(), index);
}
-
- void update() {}
};
template <class Stat>
delete [] reinterpret_cast<char *>(storage);
}
- void
- update()
- {
- Info *info = this->info();
- size_type size = this->size();
- info->cvec.resize(size);
- for (off_type i = 0; i < size; ++i)
- info->cvec[i] = data(i)->value();
- }
-
Derived &
init(size_type _x, size_type _y)
{
#endif
}
+ void
+ prepare()
+ {
+ Info *info = this->info();
+ size_type size = this->size();
+
+ for (off_type i = 0; i < size; ++i)
+ data(i)->prepare(info);
+
+ info->cvec.resize(size);
+ for (off_type i = 0; i < size; ++i)
+ info->cvec[i] = data(i)->value();
+ }
+
/**
* Reset stat value to default
*/
}
void
- update(Info *info, DistData &data)
+ prepare(Info *info, DistData &data)
{
const Params *params = safe_cast<const Params *>(info->storageParams);
samples += number;
}
- void
- update(Info *info, DistData &data)
- {
- data.sum = sum;
- data.squares = squares;
- data.samples = samples;
- }
-
/**
* Return the number of entries in this stat, 1
* @return 1.
*/
bool zero() const { return samples == Counter(); }
+ void
+ prepare(Info *info, DistData &data)
+ {
+ data.sum = sum;
+ data.squares = squares;
+ data.samples = samples;
+ }
+
/**
* Reset stat value to default
*/
squares += value * value;
}
- void
- update(Info *info, DistData &data)
- {
- data.sum = sum;
- data.squares = squares;
- data.samples = curTick;
- }
-
/**
* Return the number of entries, in this case 1.
* @return 1.
*/
bool zero() const { return sum == Counter(); }
+ void
+ prepare(Info *info, DistData &data)
+ {
+ data.sum = sum;
+ data.squares = squares;
+ data.samples = curTick;
+ }
+
/**
* Reset stat value to default
*/
bool zero() const { return data()->zero(); }
void
- update()
+ prepare()
{
Info *info = this->info();
- data()->update(info, info->data);
+ data()->prepare(info, info->data);
}
/**
#endif
}
- bool
- check() const
- {
- return storage != NULL;
- }
-
void
- update()
+ prepare()
{
- Derived &self = this->self();
Info *info = this->info();
+ size_type size = this->size();
+ info->data.resize(size);
+ for (off_type i = 0; i < size; ++i)
+ data(i)->prepare(info, info->data[i]);
+ }
- size_type size = self.size();
- info.data.resize(size);
- for (off_type i = 0; i < size; ++i) {
- data(i)->update(info, info.data[i]);
- }
+ bool
+ check() const
+ {
+ return storage != NULL;
}
};
Result total() const { return this->s.total(); }
VCounter &value() const { return cvec; }
- void
- visit(Visit &visitor)
- {
- this->update();
- this->s.update();
- visitor.visit(*this);
- }
-
std::string str() const { return this->s.str(); }
};
*/
bool zero() const;
- /**
- *
- */
- void update();
-
std::string str() const;
};
* @}
*/
-void check();
-void dump();
-void reset();
-void registerResetCallback(Callback *cb);
-
inline Temp
operator+(Temp l, Temp r)
{
return NodePtr(new SumNode<std::plus<Result> >(val));
}
+/**
+ * Enable the statistics package. Before the statistics package is
+ * enabled, all statistics must be created and initialized and once
+ * the package is enabled, no more statistics can be created.
+ */
+void enable();
+
+/**
+ * Prepare all stats for data access. This must be done before
+ * dumping and serialization.
+ */
+void prepare();
+
+/**
+ * Dump all statistics data to the registered outputs
+ */
+void dump();
+
+/**
+ * Reset all statistics to the base state
+ */
+void reset();
+/**
+ * Register a callback that should be called whenever statistics are
+ * reset
+ */
+void registerResetCallback(Callback *cb);
+
std::list<Info *> &statsList();
/* namespace Stats */ }