changeset 69bd1011dcf3 in /z/repo/gem5
details: http://repo.gem5.org/gem5?cmd=changeset;node=69bd1011dcf3
description:
        stats: add function for adding two histograms
        This patch adds a function to the HistStor class for adding two 
histograms.
        This functionality is required for Ruby.  It also adds support for 
printing
        histograms in a single line.

diffstat:

 src/base/statistics.cc |  21 +++++++++++++++++++++
 src/base/statistics.hh |  11 +++++++++--
 src/base/stats/text.cc |  36 +++++++++++++++++++++++++++++-------
 3 files changed, 59 insertions(+), 9 deletions(-)

diffs (158 lines):

diff -r 4aa1135c05d4 -r 69bd1011dcf3 src/base/statistics.cc
--- a/src/base/statistics.cc    Thu Jan 09 10:45:50 2014 -0600
+++ b/src/base/statistics.cc    Fri Jan 10 16:19:40 2014 -0600
@@ -352,6 +352,27 @@
     bucket_size *= 2;
 }
 
+void
+HistStor::add(HistStor *hs)
+{
+    int b_size = hs->size();
+    assert(size() == b_size);
+    assert(min_bucket == hs->min_bucket);
+
+    sum += hs->sum;
+    logs += hs->logs;
+    squares += hs->squares;
+    samples += hs->samples;
+
+    while(bucket_size > hs->bucket_size)
+        hs->grow_up();
+    while(bucket_size < hs->bucket_size)
+        grow_up();
+
+    for (uint32_t i = 0; i < b_size; i++)
+        cvec[i] += hs->cvec[i];
+}
+
 Formula::Formula()
 {
 }
diff -r 4aa1135c05d4 -r 69bd1011dcf3 src/base/statistics.hh
--- a/src/base/statistics.hh    Thu Jan 09 10:45:50 2014 -0600
+++ b/src/base/statistics.hh    Fri Jan 10 16:19:40 2014 -0600
@@ -228,12 +228,12 @@
     /**
      * Copy constructor, copies are not allowed.
      */
-    DataWrap(const DataWrap &stat);
+    DataWrap(const DataWrap &stat) {}
 
     /**
      * Can't copy stats.
      */
-    void operator=(const DataWrap &);
+    void operator=(const DataWrap &) {}
 
   public:
     DataWrap()
@@ -1502,6 +1502,7 @@
     void grow_up();
     void grow_out();
     void grow_convert();
+    void add(HistStor *);
 
     /**
      * Add a value to the distribution for the given number of times.
@@ -1840,6 +1841,12 @@
     {
         data()->reset(this->info());
     }
+
+    /**
+     *  Add the argument distribution to the this distibution.
+     */
+    void add(DistBase &d) { data()->add(d.data()); }
+
 };
 
 template <class Stat>
diff -r 4aa1135c05d4 -r 69bd1011dcf3 src/base/stats/text.cc
--- a/src/base/stats/text.cc    Thu Jan 09 10:45:50 2014 -0600
+++ b/src/base/stats/text.cc    Fri Jan 10 16:19:40 2014 -0600
@@ -210,7 +210,7 @@
 void
 ScalarPrint::operator()(ostream &stream, bool oneLine) const
 {
-    if ((flags.isSet(nozero) && value == 0.0) ||
+    if ((flags.isSet(nozero) && (!oneLine) && value == 0.0) ||
         (flags.isSet(nonan) && std::isnan(value)))
         return;
 
@@ -312,7 +312,6 @@
                 if (!desc.empty())
                     ccprintf(stream, " # %s", desc);
             }
-
             stream << endl;
         }
     }
@@ -325,10 +324,6 @@
         print.value = total;
         print(stream);
     }
-
-    if (flags.isSet(oneline) && ((!flags.isSet(nozero)) || (total != 0))) {
-        stream << endl;
-    }
 }
 
 struct DistPrint
@@ -380,6 +375,7 @@
 void
 DistPrint::operator()(ostream &stream) const
 {
+    if (flags.isSet(nozero) && data.samples == 0) return;
     string base = name + separatorString;
 
     ScalarPrint print;
@@ -390,6 +386,20 @@
     print.pdf = NAN;
     print.cdf = NAN;
 
+    if (flags.isSet(oneline)) {
+        print.name = base + "bucket_size";
+        print.value = data.bucket_size;
+        print(stream);
+
+        print.name = base + "min_bucket";
+        print.value = data.min;
+        print(stream);
+
+        print.name = base + "max_bucket";
+        print.value = data.max;
+        print(stream);
+    }
+
     print.name = base + "samples";
     print.value = data.samples;
     print(stream);
@@ -436,6 +446,10 @@
         print(stream);
     }
 
+    if (flags.isSet(oneline)) {
+        ccprintf(stream, "%-40s", name);
+    }
+
     for (off_type i = 0; i < size; ++i) {
         stringstream namestr;
         namestr << base;
@@ -448,7 +462,15 @@
 
         print.name = namestr.str();
         print.update(data.cvec[i], total);
-        print(stream);
+        print(stream, flags.isSet(oneline));
+    }
+
+    if (flags.isSet(oneline)) {
+        if (descriptions) {
+            if (!desc.empty())
+                ccprintf(stream, " # %s", desc);
+        }
+        stream << endl;
     }
 
     if (data.type == Dist && data.overflow != NAN) {
_______________________________________________
gem5-dev mailing list
[email protected]
http://m5sim.org/mailman/listinfo/gem5-dev

Reply via email to