summaryrefslogtreecommitdiff
path: root/base/statistics.cc
diff options
context:
space:
mode:
authorNathan Binkert <binkertn@umich.edu>2003-12-24 03:25:36 -0500
committerNathan Binkert <binkertn@umich.edu>2003-12-24 03:25:36 -0500
commit55d94ba2e8d0375504f0a6e61d46c9ddc5b8b5d3 (patch)
treef7de5f53ead518febe9a9a018043e78f5ae3d646 /base/statistics.cc
parent3f5ca9e5e81cb921e10ba395f74a6fadd793525c (diff)
downloadgem5-55d94ba2e8d0375504f0a6e61d46c9ddc5b8b5d3.tar.xz
Add python output support to the statistics package!
base/statistics.cc: base/statistics.hh: - add python output support to the statistics package - each statistic type has a python() member function that takes a Python object to which the stat will output it's python representation - add getStatData hack so that the StatData pointer can be looked up by the proxies with their opaque pointer to the stat they're proxying for. This is necessary because the proxy really proxies for the bin and not the stat. Be nice to figure out how to get rid of it. The hack is used so that the str() function of a proxy can properly name itself. - To print formula stats, every stat has a str() function that converts that stat to a string that python can execute to get a value. test/Makefile: add python stuff test/stattest.cc: add more tests and test python support --HG-- extra : convert_revision : 513814ab0a125606897f2c57dccdf22879032ef9
Diffstat (limited to 'base/statistics.cc')
-rw-r--r--base/statistics.cc226
1 files changed, 226 insertions, 0 deletions
diff --git a/base/statistics.cc b/base/statistics.cc
index 03a99b80e..04d4032d3 100644
--- a/base/statistics.cc
+++ b/base/statistics.cc
@@ -35,9 +35,12 @@
#include "base/callback.hh"
#include "base/cprintf.hh"
+#include "base/hostinfo.hh"
#include "base/misc.hh"
+#include "base/python.hh"
#include "base/statistics.hh"
#include "base/str.hh"
+#include "base/time.hh"
#include "base/trace.hh"
#ifdef __M5_NAN
@@ -82,6 +85,8 @@ namespace Database
public:
void dump(ostream &stream, const string &name, DisplayMode mode);
void display(ostream &stream, DisplayMode mode);
+ void python(ostream &stream, const string &name);
+ void python(Python &py, const string &name, const string &bin);
StatData *find(void *stat);
void mapStat(void *stat, StatData *data);
@@ -101,6 +106,9 @@ Data::dump(ostream &stream, const string &name, DisplayMode mode)
MainBin *orig = MainBin::curBin();
switch (mode) {
+ case mode_python:
+ python(stream, name);
+ break;
case mode_m5:
case mode_simplescalar:
display(stream, mode);
@@ -149,6 +157,53 @@ Data::display(ostream &stream, DisplayMode mode)
}
}
+void
+Data::python(ostream &stream, const string &name)
+{
+ Python py(stream);
+
+ ccprintf(stream, "import sys\n");
+ ccprintf(stream, "sys.path.append('.')\n");
+ ccprintf(stream, "from m5stats import *\n\n");
+
+ if (bins.empty()) {
+ python(py, name, "");
+ } else {
+ list<MainBin *>::iterator i = bins.begin();
+ list<MainBin *>::iterator end = bins.end();
+
+ while (i != end) {
+ (*i)->activate();
+ python(py, name, (*i)->name());
+ ++i;
+ }
+ }
+
+ py.next();
+ ccprintf(stream, "if __name__ == '__main__':\n");
+ ccprintf(stream, " program_display()\n");
+}
+
+void
+Data::python(Python &py, const string &name, const string &bin)
+{
+ py.start("collections.append");
+ py.start("Collection");
+ py.qarg(name);
+ py.qarg(bin);
+ py.qarg(hostname());
+ py.qarg(Time::start.date());
+ list_t::iterator i = allStats.begin();
+ list_t::iterator end = allStats.end();
+ while (i != end) {
+ StatData *stat = *i;
+ stat->python(py);
+ ++i;
+ }
+ py.end();
+ py.end();
+}
+
StatData *
Data::find(void *stat)
{
@@ -272,6 +327,12 @@ DataAccess::find() const
return Database::StatDB().find(const_cast<void *>((const void *)this));
}
+const StatData *
+getStatData(const void *stat)
+{
+ return Database::StatDB().find(const_cast<void *>(stat));
+}
+
void
DataAccess::map(StatData *data)
{
@@ -902,6 +963,165 @@ VectorDistDataBase::display(ostream &stream, DisplayMode mode) const
}
void
+ScalarDataBase::python(Python &py) const
+{
+ py.start("Scalar");
+ py.qarg(name);
+ py.qarg(desc);
+ py.kwarg("binned", binned());
+ py.kwarg("precision", precision);
+ py.kwarg("flags", flags);
+ if (prereq)
+ py.qkwarg("prereq", prereq->name);
+ py.kwarg("value", val());
+ py.end();
+}
+
+void
+VectorDataBase::python(Python &py) const
+{
+ const_cast<VectorDataBase *>(this)->update();
+
+ py.start("Vector");
+ py.qarg(name);
+ py.qarg(desc);
+ py.kwarg("binned", binned());
+ py.kwarg("precision", precision);
+ py.kwarg("flags", flags);
+ if (prereq)
+ py.qkwarg("prereq", prereq->name);
+ py.kwarg("value", val());
+ if (!subnames.empty())
+ py.qkwarg("subnames", subnames);
+ if (!subdescs.empty())
+ py.qkwarg("subdescs", subdescs);
+ py.end();
+}
+
+void
+DistDataData::python(Python &py, const string &name) const
+{
+ string s = name.empty() ? "" : name + "=";
+
+ if (samples == 0 || fancy)
+ s += "SimpleDist";
+ else
+ s += "FullDist";
+
+ py.start(s);
+ py.arg(sum);
+ py.arg(squares);
+ py.arg(samples);
+ if (samples && !fancy) {
+ py.arg(min_val);
+ py.arg(min_val);
+ py.arg(underflow);
+ py.arg(vec);
+ py.arg(overflow);
+ py.arg(min);
+ py.arg(max);
+ py.arg(bucket_size);
+ py.arg(size);
+ }
+ py.end();
+}
+
+void
+FormulaDataBase::python(Python &py) const
+{
+ const_cast<FormulaDataBase *>(this)->update();
+
+ py.start("Formula");
+ py.qarg(name);
+ py.qarg(desc);
+ py.kwarg("binned", binned());
+ py.kwarg("precision", precision);
+ py.kwarg("flags", flags);
+ if (prereq)
+ py.qkwarg("prereq", prereq->name);
+ py.qkwarg("formula", str());
+ if (!subnames.empty())
+ py.qkwarg("subnames", subnames);
+ if (!subdescs.empty())
+ py.qkwarg("subdescs", subdescs);
+ py.end();
+}
+
+void
+DistDataBase::python(Python &py) const
+{
+ const_cast<DistDataBase *>(this)->update();
+
+ py.start("Dist");
+ py.qarg(name);
+ py.qarg(desc);
+ py.kwarg("binned", binned());
+ py.kwarg("precision", precision);
+ py.kwarg("flags", flags);
+ if (prereq)
+ py.qkwarg("prereq", prereq->name);
+ data.python(py, "dist");
+ py.end();
+}
+
+void
+VectorDistDataBase::python(Python &py) const
+{
+ const_cast<VectorDistDataBase *>(this)->update();
+
+ py.start("VectorDist");
+ py.qarg(name);
+ py.qarg(desc);
+ py.kwarg("binned", binned());
+ py.kwarg("precision", precision);
+ py.kwarg("flags", flags);
+ if (prereq)
+ py.qkwarg("prereq", prereq->name);
+ if (!subnames.empty())
+ py.qkwarg("subnames", subnames);
+ if (!subdescs.empty())
+ py.qkwarg("subdescs", subdescs);
+
+ py.tuple("dist");
+ typedef std::vector<DistDataData>::const_iterator iter;
+ iter i = data.begin();
+ iter end = data.end();
+ while (i != end) {
+ i->python(py, "");
+ ++i;
+ }
+ py.endTuple();
+ py.end();
+}
+
+void
+Vector2dDataBase::python(Python &py) const
+{
+ const_cast<Vector2dDataBase *>(this)->update();
+
+ py.start("Vector2d");
+ py.qarg(name);
+ py.qarg(desc);
+ py.kwarg("binned", binned());
+ py.kwarg("precision", precision);
+ py.kwarg("flags", flags);
+ if (prereq)
+ py.qkwarg("prereq", prereq->name);
+
+ py.kwarg("value", vec);
+ if (!subnames.empty())
+ py.qkwarg("subnames", subnames);
+ if (!subdescs.empty())
+ py.qkwarg("subdescs", subdescs);
+ if (!y_subnames.empty())
+ py.qkwarg("ysubnames", y_subnames);
+
+ py.kwarg("x", x);
+ py.kwarg("y", y);
+ py.end();
+}
+
+void
FormulaBase::val(rvec_t &vec) const
{
vec = root->val();
@@ -949,6 +1169,12 @@ FormulaBase::update(StatData *)
{
}
+string
+FormulaBase::str() const
+{
+ return root ? root->str() : "";
+}
+
Formula::Formula()
{
setInit();