changeset 00251eb95de7 in /z/repo/m5
details: http://repo.m5sim.org/m5?cmd=changeset;node=00251eb95de7
description:
        stats: create an enable phase, and a prepare phase.
        Enable more or less takes the place of check, but also allows stats to
        do some other configuration.  Prepare moves all of the code that readies
        a stat for dumping into a separate function in preparation for 
supporting
        serialization of certain pieces of statistics data.
        While we're at it, clean up the visitor code and some of the python 
code.

diffstat:

7 files changed, 215 insertions(+), 162 deletions(-)
src/base/statistics.cc    |   67 ++++++++---
src/base/statistics.hh    |  264 +++++++++++++++++++++------------------------
src/base/stats/output.cc  |    3 
src/python/m5/core.py     |    7 +
src/python/m5/simulate.py |   14 +-
src/python/m5/stats.py    |   19 ++-
src/python/swig/stats.i   |    3 

diffs (truncated from 758 to 300 lines):

diff -r 4f887be9e1b6 -r 00251eb95de7 src/base/statistics.cc
--- a/src/base/statistics.cc    Thu Mar 05 19:09:53 2009 -0800
+++ b/src/base/statistics.cc    Thu Mar 05 19:09:53 2009 -0800
@@ -32,6 +32,7 @@
 #include <fstream>
 #include <list>
 #include <map>
+#include <set>
 #include <string>
 
 #include "base/callback.hh"
@@ -174,6 +175,41 @@
     return true;
 }
 
+void
+Info::enable()
+{
+}
+
+void
+VectorInfoBase::enable()
+{
+    size_type s = size();
+    if (subnames.size() < s)
+        subnames.resize(s);
+    if (subdescs.size() < s)
+        subdescs.resize(s);
+}
+
+void
+VectorDistInfoBase::enable()
+{
+    size_type s = size();
+    if (subnames.size() < s)
+        subnames.resize(s);
+    if (subdescs.size() < s)
+        subdescs.resize(s);
+}
+
+void
+Vector2dInfoBase::enable()
+{
+    if (subnames.size() < x)
+        subnames.resize(x);
+    if (subdescs.size() < x)
+        subdescs.resize(x);
+    if (y_subnames.size() < y)
+        y_subnames.resize(y);
+}
 
 Formula::Formula()
 {
@@ -244,11 +280,6 @@
     return true;
 }
 
-void
-Formula::update()
-{
-}
-
 string
 Formula::str() const
 {
@@ -256,7 +287,7 @@
 }
 
 void
-check()
+enable()
 {
     typedef list<Info *>::iterator iter_t;
 
@@ -277,17 +308,21 @@
 
     statsList().sort(Info::less);
 
-    if (i == end)
-        return;
+    for (i = statsList().begin(); i != end; ++i) {
+        Info *info = *i;
+        info->enable();
+    }
+}
 
-    iter_t last = i;
-    ++i;
-
-    for (i = statsList().begin(); i != end; ++i) {
-        if ((*i)->name == (*last)->name)
-            panic("same name used twice! name=%s\n", (*i)->name);
-
-        last = i;
+void
+prepare()
+{
+    list<Info *>::iterator i = statsList().begin();
+    list<Info *>::iterator end = statsList().end();
+    while (i != end) {
+        Info *info = *i;
+        info->prepare();
+        ++i;
     }
 }
 
diff -r 4f887be9e1b6 -r 00251eb95de7 src/base/statistics.hh
--- a/src/base/statistics.hh    Thu Mar 05 19:09:53 2009 -0800
+++ b/src/base/statistics.hh    Thu Mar 05 19:09:53 2009 -0800
@@ -123,6 +123,16 @@
     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;
@@ -159,7 +169,13 @@
     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(); }
 };
 
@@ -169,7 +185,6 @@
     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>
@@ -191,23 +206,13 @@
     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>
@@ -237,14 +242,6 @@
     }
 
     Result total() const { return this->s.total(); }
-
-    void
-    visit(Visit &visitor)
-    {
-        this->update();
-        this->s.update();
-        visitor.visit(*this);
-    }
 };
 
 struct DistData
@@ -271,13 +268,6 @@
 {
   public:
     DistInfo(Stat &stat) : InfoWrap<Stat, DistInfoBase>(stat) {}
-
-    void
-    visit(Visit &visitor)
-    {
-        this->s.update();
-        visitor.visit(*this);
-    }
 };
 
 class VectorDistInfoBase : public Info
@@ -288,6 +278,7 @@
     /** 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. */
@@ -295,17 +286,6 @@
 
   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>
@@ -315,14 +295,6 @@
     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
@@ -339,13 +311,7 @@
     /** 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>
@@ -353,14 +319,6 @@
 {
   public:
     Vector2dInfo(Stat &stat) : InfoWrap<Stat, Vector2dInfoBase>(stat) {}
-
-    void
-    visit(Visit &visitor)
-    {
-        this->update();
-        this->s.update();
-        visitor.visit(*this);
-    }
 };
 
 class InfoAccess
@@ -382,7 +340,7 @@
     /**
      * Reset the stat to the default state.
      */
-    void reset() {}
+    void reset() { }
 
     /**
      * @return true if this stat has a value and satisfies its
@@ -525,7 +483,7 @@
     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)
@@ -559,6 +517,17 @@
     }
 
     void
+    prepare()
+    {
+        Derived &self = this->self();
_______________________________________________
m5-dev mailing list
m5-dev@m5sim.org
http://m5sim.org/mailman/listinfo/m5-dev

Reply via email to