static bool less(StatData *stat1, StatData *stat2);
};
-struct ScalarData : public StatData
+class ScalarData : public StatData
{
+ public:
virtual Counter value() const = 0;
virtual Result result() const = 0;
virtual Result total() const = 0;
+ virtual void visit(Visit &visitor) { visitor.visit(*this); }
};
template <class Stat>
virtual Result total() const { return s.total(); }
virtual void reset() { s.reset(); }
virtual bool zero() const { return s.zero(); }
-
- virtual void visit(Visit &visitor) { visitor.visit(*this); }
};
struct VectorData : public StatData
return ptr;
}
+ protected:
+ /**
+ * Copy constructor, copies are not allowed.
+ */
+ Wrap(const Wrap &stat);
+ /**
+ * Can't copy stats.
+ */
+ void operator=(const Wrap &);
+
public:
Wrap()
{
return _bin->data(*_params);
}
- protected:
- /**
- * Copy constructor, copies are not allowed.
- */
- ScalarBase(const ScalarBase &stat);
- /**
- * Can't copy stats.
- */
- const ScalarBase &operator=(const ScalarBase &);
-
public:
/**
* Return the current value of this stat as its base type.
};
+class ProxyData : public ScalarData
+{
+ public:
+ virtual void visit(Visit &visitor) { visitor.visit(*this); }
+ virtual bool binned() const { return false; }
+ virtual std::string str() const { return to_string(value()); }
+ virtual size_t size() const { return 1; }
+ virtual bool zero() const { return value() == 0; }
+ virtual bool check() const { return true; }
+ virtual void reset() { }
+};
+
+template <class T>
+class ValueProxy : public ProxyData
+{
+ private:
+ T *scalar;
+
+ public:
+ ValueProxy(T &val) : scalar(&val) {}
+ virtual Counter value() const { return *scalar; }
+ virtual Result result() const { return *scalar; }
+ virtual Result total() const { return *scalar; }
+};
+
+template <class T>
+class FunctorProxy : public ProxyData
+{
+ private:
+ T *functor;
+
+ public:
+ FunctorProxy(T &func) : functor(&func) {}
+ virtual Counter value() const { return (*functor)(); }
+ virtual Result result() const { return (*functor)(); }
+ virtual Result total() const { return (*functor)(); }
+};
+
+class ValueBase : public DataAccess
+{
+ private:
+ ProxyData *proxy;
+
+ public:
+ ValueBase() : proxy(NULL) { }
+ ~ValueBase() { if (proxy) delete proxy; }
+
+ template <class T>
+ void scalar(T &value)
+ {
+ proxy = new ValueProxy<T>(value);
+ setInit();
+ }
+
+ template <class T>
+ void functor(T &func)
+ {
+ proxy = new FunctorProxy<T>(func);
+ setInit();
+ }
+
+ Counter value() { return proxy->value(); }
+ Result result() const { return proxy->result(); }
+ Result total() const { return proxy->total(); };
+ size_t size() const { return proxy->size(); }
+
+ bool binned() const { return proxy->binned(); }
+ std::string str() const { return proxy->str(); }
+ bool zero() const { return proxy->zero(); }
+ bool check() const { return proxy != NULL; }
+ void reset() { }
+};
+
//////////////////////////////////////////////////////////////////////
//
// Vector Statistics
return _bin->data(index, *_params);
}
- protected:
- // Copying stats is not allowed
- /** Copying stats isn't allowed. */
- VectorBase(const VectorBase &stat);
- /** Copying stats isn't allowed. */
- const VectorBase &operator=(const VectorBase &);
-
public:
void value(VCounter &vec) const
{
return _bin->data(index, *_params);
}
- protected:
- // Copying stats is not allowed
- Vector2dBase(const Vector2dBase &stat);
- const Vector2dBase &operator=(const Vector2dBase &);
-
public:
Vector2dBase() {}
return _bin->data(*_params);
}
- protected:
- // Copying stats is not allowed
- /** Copies are not allowed. */
- DistBase(const DistBase &stat);
- /** Copies are not allowed. */
- const DistBase &operator=(const DistBase &);
-
public:
DistBase() { }
return _bin->data(index, *_params);
}
- protected:
- // Copying stats is not allowed
- VectorDistBase(const VectorDistBase &stat);
- const VectorDistBase &operator=(const VectorDistBase &);
-
public:
VectorDistBase() {}
virtual std::string str() const { return to_string(vresult[0]); }
};
-template <class T>
-class FunctorNode : public Node
-{
- private:
- T &functor;
- mutable VResult vresult;
-
- public:
- FunctorNode(T &f) : functor(f) { vresult.resize(1); }
- const VResult &result() const
- {
- vresult[0] = (Result)functor();
- return vresult;
- }
- virtual Result total() const { return (Result)functor(); };
-
- virtual size_t size() const { return 1; }
- /**
- * Return true if stat is binned.
- *@return False since Functors aren't binned
- */
- virtual bool binned() const { return false; }
- virtual std::string str() const { return to_string(functor()); }
-};
-
-template <class T>
-class ScalarNode : public Node
-{
- private:
- T &scalar;
- mutable VResult vresult;
-
- public:
- ScalarNode(T &s) : scalar(s) { vresult.resize(1); }
- const VResult &result() const
- {
- vresult[0] = (Result)scalar;
- return vresult;
- }
- virtual Result total() const { return (Result)scalar; };
-
- virtual size_t size() const { return 1; }
- /**
- * Return true if stat is binned.
- *@return False since Scalar's aren't binned
- */
- virtual bool binned() const { return false; }
- virtual std::string str() const { return to_string(scalar); }
-};
-
template <class Op>
struct OpString;
void operator=(const U &v) { Base::operator=(v); }
};
+class Value
+ : public Wrap<Value,
+ ValueBase,
+ ScalarStatData>
+{
+ public:
+ /** The base implementation. */
+ typedef ValueBase Base;
+
+ template <class T>
+ Value &scalar(T &value)
+ {
+ Base::scalar(value);
+ return *this;
+ }
+
+ template <class T>
+ Value &functor(T &func)
+ {
+ Base::functor(func);
+ return *this;
+ }
+};
+
/**
* A stat that calculates the per cycle average of a value.
* @sa Stat, ScalarBase, AvgStor
Temp(const Scalar<Bin> &s)
: node(new ScalarStatNode(s.statData())) { }
+ /**
+ * Create a new ScalarStatNode.
+ * @param s The ScalarStat to place in a node.
+ */
+ Temp(const Value &s)
+ : node(new ScalarStatNode(s.statData())) { }
+
/**
* Create a new ScalarStatNode.
* @param s The ScalarStat to place in a node.
return NodePtr(new ConstNode<T>(val));
}
-template <typename T>
-inline Temp
-functor(T &val)
-{
- return NodePtr(new FunctorNode<T>(val));
-}
-
-template <typename T>
-inline Temp
-scalar(T &val)
-{
- return NodePtr(new ScalarNode<T>(val));
-}
-
inline Temp
sum(Temp val)
{
#include "base/str.hh"
#include "base/time.hh"
#include "base/stats/output.hh"
+#include "cpu/base_cpu.hh"
#include "sim/eventq.hh"
#include "sim/sim_object.hh"
#include "sim/stat_control.hh"
using namespace std;
Statistics::Formula hostInstRate;
-Statistics::Formula hostMemory;
-Statistics::Formula hostSeconds;
Statistics::Formula hostTickRate;
+Statistics::Value hostMemory;
+Statistics::Value hostSeconds;
-Statistics::Formula simInsts;
+Statistics::Value simTicks;
+Statistics::Value simInsts;
+Statistics::Value simFreq;
Statistics::Formula simSeconds;
-Statistics::Formula simTicks;
namespace Statistics {
InitSimStats()
{
simInsts
+ .functor(BaseCPU::numSimulatedInstructions)
.name("sim_insts")
.desc("Number of instructions simulated")
.precision(0)
.desc("Number of seconds simulated")
;
+ simFreq
+ .scalar(ticksPerSecond)
+ .name("sim_freq")
+ .desc("Frequency of simulated ticks")
+ ;
+
simTicks
+ .scalar(curTick)
.name("sim_ticks")
.desc("Number of ticks simulated")
;
;
hostMemory
+ .functor(memUsage)
.name("host_mem_usage")
.desc("Number of bytes of host memory used")
.prereq(hostMemory)
;
hostSeconds
+ .functor(statElapsedTime)
.name("host_seconds")
.desc("Real time elapsed on the host")
.precision(2)
.precision(0)
;
- simInsts = constant(0);
- simTicks = scalar(curTick) - scalar(startTick);
- simSeconds = simTicks / scalar(ticksPerSecond);
- hostMemory = functor(memUsage);
- hostSeconds = functor(statElapsedTime);
+ simSeconds = simTicks / simFreq;
hostInstRate = simInsts / hostSeconds;
hostTickRate = simTicks / hostSeconds;