summaryrefslogtreecommitdiff
path: root/src/base/stats
diff options
context:
space:
mode:
authorThomas Grass <Thomas.Grass@ARM.com>2011-08-19 15:08:05 -0500
committerThomas Grass <Thomas.Grass@ARM.com>2011-08-19 15:08:05 -0500
commit3f1ae35c6db3321b5f7e0ef4a90e2610a468692b (patch)
tree0ff0c7143bf8331182f254930e7a944575acc0ca /src/base/stats
parent676a530b776ca3468a4c318bbe5bbf8b473bc5f2 (diff)
downloadgem5-3f1ae35c6db3321b5f7e0ef4a90e2610a468692b.tar.xz
Stats: Add a sparse histogram stat object.
Diffstat (limited to 'src/base/stats')
-rw-r--r--src/base/stats/info.hh14
-rw-r--r--src/base/stats/output.hh2
-rw-r--r--src/base/stats/text.cc86
-rw-r--r--src/base/stats/text.hh1
-rw-r--r--src/base/stats/types.hh3
5 files changed, 106 insertions, 0 deletions
diff --git a/src/base/stats/info.hh b/src/base/stats/info.hh
index fa7c8cc3d..2c5b44a38 100644
--- a/src/base/stats/info.hh
+++ b/src/base/stats/info.hh
@@ -234,6 +234,20 @@ class FormulaInfo : public VectorInfo
virtual std::string str() const = 0;
};
+/** Data structure of sparse histogram */
+struct SparseHistData
+{
+ MCounter cmap;
+ Counter samples;
+};
+
+
+class SparseHistInfo : public Info
+{
+ public:
+ /** Local storage for the entry values, used for printing. */
+ SparseHistData data;
+};
} // namespace Stats
diff --git a/src/base/stats/output.hh b/src/base/stats/output.hh
index 26c4c5bbd..9cd33a5f9 100644
--- a/src/base/stats/output.hh
+++ b/src/base/stats/output.hh
@@ -43,6 +43,7 @@ class DistInfo;
class VectorDistInfo;
class Vector2dInfo;
class FormulaInfo;
+class SparseHistInfo; // Sparse histogram
struct Output
{
@@ -57,6 +58,7 @@ struct Output
virtual void visit(const VectorDistInfo &info) = 0;
virtual void visit(const Vector2dInfo &info) = 0;
virtual void visit(const FormulaInfo &info) = 0;
+ virtual void visit(const SparseHistInfo &info) = 0; // Sparse histogram
};
} // namespace Stats
diff --git a/src/base/stats/text.cc b/src/base/stats/text.cc
index 45d59ff29..f8471f1a1 100644
--- a/src/base/stats/text.cc
+++ b/src/base/stats/text.cc
@@ -581,6 +581,92 @@ Text::visit(const FormulaInfo &info)
visit((const VectorInfo &)info);
}
+/*
+ This struct implements the output methods for the sparse
+ histogram stat
+*/
+struct SparseHistPrint
+{
+ string name;
+ string separatorString;
+ string desc;
+ Flags flags;
+ bool descriptions;
+ int precision;
+
+ const SparseHistData &data;
+
+ SparseHistPrint(const Text *text, const SparseHistInfo &info);
+ void init(const Text *text, const Info &info);
+ void operator()(ostream &stream) const;
+};
+
+/* Call initialization function */
+SparseHistPrint::SparseHistPrint(const Text *text, const SparseHistInfo &info)
+ : data(info.data)
+{
+ init(text, info);
+}
+
+/* Initialization function */
+void
+SparseHistPrint::init(const Text *text, const Info &info)
+{
+ name = info.name;
+ separatorString = info.separatorString;
+ desc = info.desc;
+ flags = info.flags;
+ precision = info.precision;
+ descriptions = text->descriptions;
+}
+
+/* Grab data from map and write to output stream */
+void
+SparseHistPrint::operator()(ostream &stream) const
+{
+ string base = name + separatorString;
+
+ ScalarPrint print;
+ print.precision = precision;
+ print.flags = flags;
+ print.descriptions = descriptions;
+ print.desc = desc;
+ print.pdf = NAN;
+ print.cdf = NAN;
+
+ print.name = base + "samples";
+ print.value = data.samples;
+ print(stream);
+
+ MCounter::const_iterator it;
+ for (it = data.cmap.begin(); it != data.cmap.end(); it++) {
+ stringstream namestr;
+ namestr << base;
+
+ namestr <<(*it).first;
+ print.name = namestr.str();
+ print.value = (*it).second;
+ print(stream);
+ }
+
+ print.pdf = NAN;
+ print.cdf = NAN;
+
+ print.name = base + "total";
+ print.value = total;
+ print(stream);
+}
+
+void
+Text::visit(const SparseHistInfo &info)
+{
+ if (noOutput(info))
+ return;
+
+ SparseHistPrint print(this, info);
+ print(*stream);
+}
+
Output *
initText(const string &filename, bool desc)
{
diff --git a/src/base/stats/text.hh b/src/base/stats/text.hh
index 24abaac97..7f7edaa91 100644
--- a/src/base/stats/text.hh
+++ b/src/base/stats/text.hh
@@ -67,6 +67,7 @@ class Text : public Output
virtual void visit(const VectorDistInfo &info);
virtual void visit(const Vector2dInfo &info);
virtual void visit(const FormulaInfo &info);
+ virtual void visit(const SparseHistInfo &info);
// Implement Output
virtual bool valid() const;
diff --git a/src/base/stats/types.hh b/src/base/stats/types.hh
index 9faa8d33d..831cc6db5 100644
--- a/src/base/stats/types.hh
+++ b/src/base/stats/types.hh
@@ -32,6 +32,7 @@
#define __BASE_STATS_TYPES_HH__
#include <limits>
+#include <map>
#include <vector>
#include "base/types.hh"
@@ -42,6 +43,8 @@ namespace Stats {
typedef double Counter;
/** vector of counters. */
typedef std::vector<Counter> VCounter;
+/** map of counters */
+typedef std::map<Counter, int> MCounter;
typedef std::numeric_limits<Counter> CounterLimits;