summaryrefslogtreecommitdiff
path: root/src/base/stats
diff options
context:
space:
mode:
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;