changeset 7772a8bf76ee in /z/repo/m5
details: http://repo.m5sim.org/m5?cmd=changeset;node=7772a8bf76ee
description:
        stats: unify the two stats distribution type better

diffstat:

 src/base/statistics.hh  |  34 ++++++++++++++++++++++++++++++++++
 src/base/stats/info.hh  |  31 ++++++++-----------------------
 src/base/stats/mysql.cc |  14 ++++++++------
 src/base/stats/text.cc  |  36 ++++++++----------------------------
 4 files changed, 58 insertions(+), 57 deletions(-)

diffs (257 lines):

diff -r ad631c296c9b -r 7772a8bf76ee src/base/statistics.hh
--- a/src/base/statistics.hh    Wed Jul 21 15:53:53 2010 -0700
+++ b/src/base/statistics.hh    Wed Jul 21 18:54:53 2010 -0700
@@ -160,6 +160,11 @@
     Vector2dInfoProxy(Stat &stat) : InfoProxy<Stat, Vector2dInfo>(stat) {}
 };
 
+struct StorageParams
+{
+    virtual ~StorageParams();
+};
+
 class InfoAccess
 {
   protected:
@@ -1269,6 +1274,12 @@
 // Non formula statistics
 //
 //////////////////////////////////////////////////////////////////////
+/** The parameters for a distribution stat. */
+struct DistParams : public StorageParams
+{
+    const DistType type;
+    DistParams(DistType t) : type(t) {}
+};
 
 /**
  * Templatized storage and interface for a distrbution stat.
@@ -1279,6 +1290,15 @@
     /** The parameters for a distribution stat. */
     struct Params : public DistParams
     {
+        /** 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;
+
         Params() : DistParams(Dist) {}
     };
 
@@ -1368,6 +1388,12 @@
     {
         const Params *params = safe_cast<const Params *>(info->storageParams);
 
+        assert(params->type == Dist);
+        data.type = params->type;
+        data.min = params->min;
+        data.max = params->max;
+        data.bucket_size = params->bucket_size;
+
         data.min_val = (min_val == CounterLimits::max()) ? 0 : min_val;
         data.max_val = (max_val == CounterLimits::min()) ? 0 : max_val;
         data.underflow = underflow;
@@ -1468,6 +1494,10 @@
     void
     prepare(Info *info, DistData &data)
     {
+        const Params *params = safe_cast<const Params *>(info->storageParams);
+
+        assert(params->type == Deviation);
+        data.type = params->type;
         data.sum = sum;
         data.squares = squares;
         data.samples = samples;
@@ -1540,6 +1570,10 @@
     void
     prepare(Info *info, DistData &data)
     {
+        const Params *params = safe_cast<const Params *>(info->storageParams);
+
+        assert(params->type == Deviation);
+        data.type = params->type;
         data.sum = sum;
         data.squares = squares;
         data.samples = curTick;
diff -r ad631c296c9b -r 7772a8bf76ee src/base/stats/info.hh
--- a/src/base/stats/info.hh    Wed Jul 21 15:53:53 2010 -0700
+++ b/src/base/stats/info.hh    Wed Jul 21 18:54:53 2010 -0700
@@ -61,11 +61,7 @@
 /** Mask of flags that can't be set directly */
 const FlagsType __reserved =    init | display;
 
-struct StorageParams
-{
-    virtual ~StorageParams();
-};
-
+struct StorageParams;
 struct Visit;
 
 class Info
@@ -168,8 +164,15 @@
     virtual Result total() const = 0;
 };
 
+enum DistType { Deviation, Dist };
+
 struct DistData
 {
+    DistType type;
+    Counter min;
+    Counter max;
+    Counter bucket_size;
+
     Counter min_val;
     Counter max_val;
     Counter underflow;
@@ -180,24 +183,6 @@
     Counter samples;
 };
 
-enum DistType { Deviation, Dist };
-
-struct DistParams : public StorageParams
-{
-    const DistType type;
-
-    /** 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;
-
-    explicit DistParams(DistType t) : type(t) {}
-};
-
 class DistInfo : public Info
 {
   public:
diff -r ad631c296c9b -r 7772a8bf76ee src/base/stats/mysql.cc
--- a/src/base/stats/mysql.cc   Wed Jul 21 15:53:53 2010 -0700
+++ b/src/base/stats/mysql.cc   Wed Jul 21 18:54:53 2010 -0700
@@ -481,9 +481,10 @@
     if (!configure(info, "DIST"))
         return;
 
-    const DistParams *params =
-        safe_cast<const DistParams *>(info.storageParams);
-    if (params->type == Dist) {
+    const DistStor::Params *params =
+        dynamic_cast<const DistStor::Params *>(info.storageParams);
+    if (params) {
+        assert(params->type == Dist);
         stat.size = params->buckets;
         stat.min = params->min;
         stat.max = params->max;
@@ -498,9 +499,10 @@
     if (!configure(info, "VECTORDIST"))
         return;
 
-    const DistParams *params =
-        safe_cast<const DistParams *>(info.storageParams);
-    if (params->type == Dist) {
+    const DistStor::Params *params =
+        dynamic_cast<const DistStor::Params *>(info.storageParams);
+    if (params) {
+        assert(params->type == Dist);
         stat.size = params->buckets;
         stat.min = params->min;
         stat.max = params->max;
diff -r ad631c296c9b -r 7772a8bf76ee src/base/stats/text.cc
--- a/src/base/stats/text.cc    Wed Jul 21 15:53:53 2010 -0700
+++ b/src/base/stats/text.cc    Wed Jul 21 18:54:53 2010 -0700
@@ -306,30 +306,24 @@
     bool descriptions;
     int precision;
 
-    Counter min;
-    Counter max;
-    Counter bucket_size;
-    size_type size;
-    DistType type;
-
     const DistData &data;
 
     DistPrint(const Text *text, const DistInfo &info);
     DistPrint(const Text *text, const VectorDistInfo &info, int i);
-    void init(const Text *text, const Info &info, const DistParams *params);
+    void init(const Text *text, const Info &info);
     void operator()(ostream &stream) const;
 };
 
 DistPrint::DistPrint(const Text *text, const DistInfo &info)
     : data(info.data)
 {
-    init(text, info, safe_cast<const DistParams *>(info.storageParams));
+    init(text, info);
 }
 
 DistPrint::DistPrint(const Text *text, const VectorDistInfo &info, int i)
     : data(info.data[i])
 {
-    init(text, info, safe_cast<const DistParams *>(info.storageParams));
+    init(text, info);
 
     name = info.name + "_" +
         (info.subnames[i].empty() ? (to_string(i)) : info.subnames[i]);
@@ -339,27 +333,13 @@
 }
 
 void
-DistPrint::init(const Text *text, const Info &info, const DistParams *params)
+DistPrint::init(const Text *text, const Info &info)
 {
     name = info.name;
     desc = info.desc;
     flags = info.flags;
     precision = info.precision;
     descriptions = text->descriptions;
-
-    type = params->type;
-    switch (type) {
-      case Dist:
-        min = params->min;
-        max = params->max;
-        bucket_size = params->bucket_size;
-        size = params->buckets;
-        break;
-      case Deviation:
-        break;
-      default:
-        panic("unknown distribution type");
-    }
 }
 
 void
@@ -391,10 +371,10 @@
     print.value = stdev;
     print(stream);
 
-    if (type == Deviation)
+    if (data.type == Deviation)
         return;
 
-    assert(size == data.cvec.size());
+    size_t size = data.cvec.size();
 
     Result total = 0.0;
     if (data.underflow != NAN)
@@ -419,8 +399,8 @@
         stringstream namestr;
         namestr << base;
 
-        Counter low = i * bucket_size + min;
-        Counter high = ::min(low + bucket_size - 1.0, max);
+        Counter low = i * data.bucket_size + data.min;
+        Counter high = ::min(low + data.bucket_size - 1.0, data.max);
         namestr << low;
         if (low < high)
             namestr << "-" << high;
_______________________________________________
m5-dev mailing list
m5-dev@m5sim.org
http://m5sim.org/mailman/listinfo/m5-dev

Reply via email to