*/
#include <iomanip>
-#include <iostream>
+#include <fstream>
#include <list>
#include <map>
#include <string>
list_t printStats;
map_t statMap;
+ ofstream *stream;
+ Python *py;
+
public:
- void dump(ostream &stream, const string &name, DisplayMode mode);
+ Data();
+ ~Data();
+
+ void dump(ostream &stream, 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);
+ void python_start(const string &file);
+ void python_dump(const string &name, const string &subname);
+ void python(const string &name, const string &subname,
+ const string &bin);
StatData *find(void *stat);
void mapStat(void *stat, StatData *data);
static std::string name() { return "Statistics Database"; }
};
+Data::Data()
+ : stream(0), py(0)
+{
+}
+
+Data::~Data()
+{
+ if (stream) {
+ delete py;
+ ccprintf(*stream, "if __name__ == '__main__':\n");
+ ccprintf(*stream, " program_display()\n");
+ stream->close();
+ delete stream;
+ }
+}
void
-Data::dump(ostream &stream, const string &name, DisplayMode mode)
+Data::dump(ostream &stream, DisplayMode mode)
{
MainBin *orig = MainBin::curBin();
switch (mode) {
- case mode_python:
- python(stream, name);
- break;
case mode_m5:
case mode_simplescalar:
display(stream, mode);
}
void
-Data::python(ostream &stream, const string &name)
+Data::python_start(const string &file)
{
- Python py(stream);
+ if (stream)
+ panic("can't start python twice!");
- ccprintf(stream, "import sys\n");
- ccprintf(stream, "sys.path.append('.')\n");
- ccprintf(stream, "from m5stats import *\n\n");
+ stream = new ofstream(file.c_str(), ios::trunc);
+ py = new Python(*stream);
+
+ ccprintf(*stream, "import sys\n");
+ ccprintf(*stream, "sys.path.append('.')\n");
+ ccprintf(*stream, "from m5stats import *\n\n");
+}
+
+void
+Data::python_dump(const string &name, const string &subname)
+{
+ if (!py)
+ panic("Can't dump python without first opening the file");
if (bins.empty()) {
- python(py, name, "");
+ python(name, subname, "");
} else {
list<MainBin *>::iterator i = bins.begin();
list<MainBin *>::iterator end = bins.end();
while (i != end) {
(*i)->activate();
- python(py, name, (*i)->name());
+ python(name, subname, (*i)->name());
++i;
}
}
-
- py.next();
- ccprintf(stream, "if __name__ == '__main__':\n");
- ccprintf(stream, " program_display()\n");
+ py->next();
}
void
-Data::python(Python &py, const string &name, const string &bin)
+Data::python(const string &name, const string &subname, const string &bin)
{
- py.start("collections.append");
- py.start("Collection");
- py.qarg(name);
- py.qarg(bin);
- py.qarg(hostname());
- py.qarg(Time::start.date());
+ py->start("collections.append");
+ py->start("Collection");
+ py->qarg(name);
+ py->qarg(subname);
+ py->qarg(bin);
+ py->qarg(hostname());
+ py->qarg(Time::start.date());
+ py->startList();
list_t::iterator i = allStats.begin();
list_t::iterator end = allStats.end();
while (i != end) {
StatData *stat = *i;
- stat->python(py);
+ stat->python(*py);
++i;
}
- py.end();
- py.end();
+ py->endList();
+ py->end();
+ py->end();
}
StatData *
{
py.start("Scalar");
py.qarg(name);
- py.qarg(desc);
+ py.qqqarg(desc);
py.kwarg("binned", binned());
py.kwarg("precision", precision);
py.kwarg("flags", flags);
py.start("Vector");
py.qarg(name);
- py.qarg(desc);
+ py.qqqarg(desc);
py.kwarg("binned", binned());
py.kwarg("precision", precision);
py.kwarg("flags", flags);
py.start("Formula");
py.qarg(name);
- py.qarg(desc);
+ py.qqqarg(desc);
py.kwarg("binned", binned());
py.kwarg("precision", precision);
py.kwarg("flags", flags);
py.start("Dist");
py.qarg(name);
- py.qarg(desc);
+ py.qqqarg(desc);
py.kwarg("binned", binned());
py.kwarg("precision", precision);
py.kwarg("flags", flags);
py.start("VectorDist");
py.qarg(name);
- py.qarg(desc);
+ py.qqqarg(desc);
py.kwarg("binned", binned());
py.kwarg("precision", precision);
py.kwarg("flags", flags);
py.start("Vector2d");
py.qarg(name);
- py.qarg(desc);
+ py.qqqarg(desc);
py.kwarg("binned", binned());
py.kwarg("precision", precision);
py.kwarg("flags", flags);
void
FormulaBase::val(rvec_t &vec) const
{
- vec = root->val();
+ if (root)
+ vec = root->val();
}
result_t
FormulaBase::total() const
{
- return root->total();
+ return root ? root->total() : 0.0;
}
size_t
}
void
-dump(ostream &stream, const string &name, DisplayMode mode)
+dump(ostream &stream, DisplayMode mode)
+{
+ Database::StatDB().dump(stream, mode);
+}
+
+void
+python_start(const string &file)
{
- Database::StatDB().dump(stream, name, mode);
+ Database::StatDB().python_start(file);
}
+void
+python_dump(const string &name, const string &subname)
+{
+ Database::StatDB().python_dump(name, subname);
+}
+
+
CallbackQueue resetQueue;
void