ARM: Improve memory instruction disassembly.
[gem5.git] / src / base / statistics.hh
index 6240be7a21338ee426985c98441d5bd25a9a0b1a..0f001dccb6d43efcb8cd7ecf67df620ec96cd9c2 100644 (file)
 #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;
 
@@ -77,96 +77,14 @@ extern Tick curTick;
 /* 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(); }
@@ -179,51 +97,26 @@ class InfoWrap : public Base
     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(); }
 
@@ -244,81 +137,27 @@ class VectorInfo : public InfoWrap<Stat, VectorInfoBase>
     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
@@ -356,11 +195,11 @@ 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); }
@@ -402,11 +241,11 @@ class DataWrap : public InfoAccess
      * @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; }
@@ -442,9 +281,9 @@ class DataWrap : public InfoAccess
      * @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();
     }
 
@@ -463,11 +302,11 @@ class DataWrap : public InfoAccess
     }
 };
 
-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!
@@ -539,11 +378,11 @@ class DataWrapVec : public DataWrap<Derived, InfoType>
     }
 };
 
-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
@@ -743,7 +582,7 @@ class AvgStor
  * Storage template.
  */
 template <class Derived, class Stor>
-class ScalarBase : public DataWrap<Derived, ScalarInfo>
+class ScalarBase : public DataWrap<Derived, ScalarInfoProxy>
 {
   public:
     typedef Stor Storage;
@@ -857,7 +696,7 @@ class ScalarBase : public DataWrap<Derived, ScalarInfo>
     void prepare() { data()->prepare(this->info()); }
 };
 
-class ProxyInfo : public ScalarInfoBase
+class ProxyInfo : public ScalarInfo
 {
   public:
     std::string str() const { return to_string(value()); }
@@ -897,7 +736,7 @@ class FunctorProxy : public ProxyInfo
 };
 
 template <class Derived>
-class ValueBase : public DataWrap<Derived, ScalarInfo>
+class ValueBase : public DataWrap<Derived, ScalarInfoProxy>
 {
   private:
     ProxyInfo *proxy;
@@ -961,13 +800,13 @@ class ScalarProxy
      * 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:
     /**
@@ -1073,7 +912,7 @@ class ScalarProxy
  * 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;
@@ -1082,7 +921,7 @@ class VectorBase : public DataWrapVec<Derived, VectorInfo>
     /** 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. */
@@ -1292,17 +1131,17 @@ class VectorProxy
 };
 
 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;
@@ -1430,18 +1269,9 @@ class DistStor
 {
   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:
@@ -1535,7 +1365,7 @@ class DistStor
         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];
@@ -1558,8 +1388,8 @@ class DistStor
 
         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)
@@ -1575,12 +1405,12 @@ class DistStor
  * 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:
@@ -1595,7 +1425,7 @@ class FancyStor
     /**
      * Create and initialize this storage.
      */
-    FancyStor(Info *info)
+    SampleStor(Info *info)
         : sum(Counter()), squares(Counter()), samples(Counter())
     { }
 
@@ -1651,12 +1481,12 @@ class FancyStor
  * 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:
@@ -1669,7 +1499,7 @@ class AvgFancy
     /**
      * Create and initialize this storage.
      */
-    AvgFancy(Info *info)
+    AvgSampleStor(Info *info)
         : sum(Counter()), squares(Counter())
     {}
 
@@ -1723,10 +1553,10 @@ class AvgFancy
  * 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;
 
@@ -1806,15 +1636,15 @@ template <class Stat>
 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;
@@ -2017,11 +1847,11 @@ typedef RefCountingPtr<Node> NodePtr;
 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
@@ -2084,10 +1914,10 @@ class ScalarProxyNode : public Node
 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(); };
 
@@ -2443,9 +2273,9 @@ class Distribution : public DistBase<Distribution, DistStor>
 
 /**
  * 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:
     /**
@@ -2459,9 +2289,9 @@ class StandardDeviation : public DistBase<StandardDeviation, FancyStor>
 
 /**
  * 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:
     /**
@@ -2475,7 +2305,7 @@ class AverageDeviation : public DistBase<AverageDeviation, AvgFancy>
 
 /**
  * A vector of distributions.
- * @sa Stat, VectorDistBase, DistStor
+ * @sa VectorDistBase, DistStor
  */
 class VectorDistribution : public VectorDistBase<VectorDistribution, DistStor>
 {
@@ -2495,7 +2325,7 @@ 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();
@@ -2504,10 +2334,10 @@ class VectorDistribution : public VectorDistBase<VectorDistribution, DistStor>
 
 /**
  * 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:
     /**
@@ -2525,10 +2355,10 @@ class VectorStandardDeviation
 
 /**
  * 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:
     /**
@@ -2544,21 +2374,15 @@ class VectorAverageDeviation
     }
 };
 
-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(); }
 
@@ -2580,7 +2404,7 @@ class Temp;
  * 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 */