#include <vector>
#include "base/stats/events.hh"
-
-#if USE_MYSQL
-#include "base/cprintf.hh"
-#include "base/misc.hh"
-#include "base/mysql.hh"
-#include "base/stats/mysql.hh"
-#include "base/stats/mysql_run.hh"
-#include "base/str.hh"
-#endif
-
-#include "base/match.hh"
+#include "base/stats/output.hh"
#include "sim/host.hh"
-#include "sim/sim_object.hh"
-#include "sim/root.hh"
using namespace std;
Tick EventStart = ULL(0x7fffffffffffffff);
-#if USE_MYSQL
-class InsertEvent
-{
- private:
- char *query;
- int size;
- bool first;
- static const int maxsize = 1024*1024;
-
- typedef map<string, uint32_t> event_map_t;
- event_map_t events;
-
- MySQL::Connection &mysql;
- uint16_t run;
-
- public:
- InsertEvent()
- : mysql(MySqlDB.conn()), run(MySqlDB.run())
- {
- query = new char[maxsize + 1];
- size = 0;
- first = true;
- flush();
- }
- ~InsertEvent()
- {
- flush();
- }
-
- void flush();
- void insert(const string &stat);
-};
-
-void
-InsertEvent::insert(const string &stat)
-{
- assert(mysql.connected());
-
- event_map_t::iterator i = events.find(stat);
- uint32_t event;
- if (i == events.end()) {
- mysql.query(
- csprintf("SELECT en_id "
- "from event_names "
- "where en_name=\"%s\"",
- stat));
-
- MySQL::Result result = mysql.store_result();
- if (!result)
- panic("could not get a run\n%s\n", mysql.error);
-
- assert(result.num_fields() == 1);
- MySQL::Row row = result.fetch_row();
- if (row) {
- if (!to_number(row[0], event))
- panic("invalid event id: %s\n", row[0]);
- } else {
- mysql.query(
- csprintf("INSERT INTO "
- "event_names(en_name)"
- "values(\"%s\")",
- stat));
-
- if (mysql.error)
- panic("could not get a run\n%s\n", mysql.error);
-
- event = mysql.insert_id();
- }
- } else {
- event = (*i).second;
- }
-
- if (size + 1024 > maxsize)
- flush();
-
- if (!first) {
- query[size++] = ',';
- query[size] = '\0';
- }
-
- first = false;
-
- size += sprintf(query + size, "(%u,%u,%llu)",
- event, run, (unsigned long long)curTick);
-}
+extern list<Output *> OutputList;
+#if USE_MYSQL
void
-InsertEvent::flush()
+__event(const string &event)
{
- static const char query_header[] = "INSERT INTO "
- "events(ev_event, ev_run, ev_tick)"
- "values";
-
- if (size) {
- MySQL::Connection &mysql = MySqlDB.conn();
- assert(mysql.connected());
- mysql.query(query);
+ list<Output *>::iterator i = OutputList.begin();
+ list<Output *>::iterator end = OutputList.end();
+ for (; i != end; ++i) {
+ Output *output = *i;
+ if (!output->valid())
+ continue;
+
+ output->event(event);
}
-
- query[0] = '\0';
- size = sizeof(query_header);
- first = true;
- memcpy(query, query_header, size);
-}
-
-void
-__event(const string &stat)
-{
- static InsertEvent event;
- event.insert(stat);
}
#endif
#include "base/stats/statdb.hh"
#include "base/stats/types.hh"
#include "base/str.hh"
+#include "base/userinfo.hh"
#include "sim/host.hh"
using namespace std;
}
unsigned
-SetupStat::setup()
+SetupStat::setup(MySqlRun *run)
{
MySQL::Connection &mysql = run->conn();
return statid;
}
-InsertData::InsertData()
+InsertData::InsertData(MySqlRun *_run)
+ : run(_run)
{
query = new char[maxsize + 1];
size = 0;
data);
}
-struct InsertSubData
+InsertEvent::InsertEvent(MySqlRun *_run)
+ : run(_run)
{
- uint16_t stat;
- int16_t x;
- int16_t y;
- string name;
- string descr;
+ query = new char[maxsize + 1];
+ size = 0;
+ first = true;
+ flush();
+}
- void setup();
-};
+InsertEvent::~InsertEvent()
+{
+ flush();
+}
void
-InsertSubData::setup()
+InsertEvent::insert(const string &stat)
{
MySQL::Connection &mysql = run->conn();
assert(mysql.connected());
- stringstream insert;
- ccprintf(insert,
- "INSERT INTO subdata(sd_stat,sd_x,sd_y,sd_name,sd_descr) "
- "values(%d,%d,%d,\"%s\",\"%s\")",
- stat, x, y, name, descr);
- mysql.query(insert);
-// if (mysql.error)
-// panic("could not insert subdata\n%s\n", mysql.error);
+ event_map_t::iterator i = events.find(stat);
+ uint32_t event;
+ if (i == events.end()) {
+ mysql.query(
+ csprintf("SELECT en_id "
+ "from event_names "
+ "where en_name=\"%s\"",
+ stat));
+
+ MySQL::Result result = mysql.store_result();
+ if (!result)
+ panic("could not get a run\n%s\n", mysql.error);
+
+ assert(result.num_fields() == 1);
+ MySQL::Row row = result.fetch_row();
+ if (row) {
+ if (!to_number(row[0], event))
+ panic("invalid event id: %s\n", row[0]);
+ } else {
+ mysql.query(
+ csprintf("INSERT INTO "
+ "event_names(en_name)"
+ "values(\"%s\")",
+ stat));
+
+ if (mysql.error)
+ panic("could not get a run\n%s\n", mysql.error);
+
+ event = mysql.insert_id();
+ }
+ } else {
+ event = (*i).second;
+ }
- if (mysql.commit())
- panic("could not commit transaction\n%s\n", mysql.error);
+ if (size + 1024 > maxsize)
+ flush();
+
+ if (!first) {
+ query[size++] = ',';
+ query[size] = '\0';
+ }
+
+ first = false;
+
+ size += sprintf(query + size, "(%u,%u,%llu)",
+ event, run->run(), (unsigned long long)curTick);
}
void
-InsertFormula(uint16_t stat, const string &formula)
+InsertEvent::flush()
{
+ static const char query_header[] = "INSERT INTO "
+ "events(ev_event, ev_run, ev_tick)"
+ "values";
+
MySQL::Connection &mysql = run->conn();
assert(mysql.connected());
- stringstream insert_formula;
- ccprintf(insert_formula,
- "INSERT INTO formulas(fm_stat,fm_formula) values(%d, \"%s\")",
- stat, formula);
- mysql.query(insert_formula);
-// if (mysql.error)
-// panic("could not insert formula\n%s\n", mysql.error);
+ if (size)
+ mysql.query(query);
- stringstream insert_ref;
- ccprintf(insert_ref,
- "INSERT INTO formula_ref(fr_stat,fr_run) values(%d, %d)",
- stat, run->run());
+ query[0] = '\0';
+ size = sizeof(query_header);
+ first = true;
+ memcpy(query, query_header, size);
+}
- mysql.query(insert_ref);
-// if (mysql.error)
-// panic("could not insert formula reference\n%s\n", mysql.error);
+struct InsertSubData
+{
+ uint16_t stat;
+ int16_t x;
+ int16_t y;
+ string name;
+ string descr;
- if (mysql.commit())
- panic("could not commit transaction\n%s\n", mysql.error);
-}
+ void setup(MySqlRun *run);
+};
void
-UpdatePrereq(uint16_t stat, uint16_t prereq)
+InsertSubData::setup(MySqlRun *run)
{
MySQL::Connection &mysql = run->conn();
assert(mysql.connected());
- stringstream update;
- ccprintf(update, "UPDATE stats SET st_prereq=%d WHERE st_id=%d",
- prereq, stat);
- mysql.query(update);
- if (mysql.error)
- panic("could not update prereq\n%s\n", mysql.error);
+ stringstream insert;
+ ccprintf(insert,
+ "INSERT INTO subdata(sd_stat,sd_x,sd_y,sd_name,sd_descr) "
+ "values(%d,%d,%d,\"%s\",\"%s\")",
+ stat, x, y, name, descr);
+
+ mysql.query(insert);
+// if (mysql.error)
+// panic("could not insert subdata\n%s\n", mysql.error);
if (mysql.commit())
panic("could not commit transaction\n%s\n", mysql.error);
}
MySql::MySql()
- : run(new MySqlRun)
+ : run(new MySqlRun), newdata(run), newevent(run)
{}
MySql::~MySql()
bool
MySql::connected() const
{
- run->connected();
+ return run->connected();
}
void
for (i = stats().begin(); i != end; ++i) {
StatData *data = *i;
if (data->prereq) {
+ // update the prerequisite
uint16_t stat_id = find(data->id);
uint16_t prereq_id = find(data->prereq->id);
assert(stat_id && prereq_id);
- UpdatePrereq(stat_id, prereq_id);
+ stringstream update;
+ ccprintf(update, "UPDATE stats SET st_prereq=%d WHERE st_id=%d",
+ prereq_id, stat_id);
+ mysql.query(update);
+ if (mysql.error)
+ panic("could not update prereq\n%s\n", mysql.error);
+
+ if (mysql.commit())
+ panic("could not commit transaction\n%s\n", mysql.error);
}
}
if (!configure(data, "SCALAR"))
return;
- insert(data.id, stat.setup());
+ insert(data.id, stat.setup(run));
}
void
if (!configure(data, "VECTOR"))
return;
- uint16_t statid = stat.setup();
+ uint16_t statid = stat.setup(run);
if (!data.subnames.empty()) {
InsertSubData subdata;
subdata.descr = data.subdescs.empty() ? "" : data.subdescs[i];
if (!subdata.name.empty() || !subdata.descr.empty())
- subdata.setup();
+ subdata.setup(run);
}
}
stat.max = data.data.max;
stat.bktsize = data.data.bucket_size;
}
- insert(data.id, stat.setup());
+ insert(data.id, stat.setup(run));
}
void
stat.bktsize = data.data[0].bucket_size;
}
- uint16_t statid = stat.setup();
+ uint16_t statid = stat.setup(run);
if (!data.subnames.empty()) {
InsertSubData subdata;
subdata.name = data.subnames[i];
subdata.descr = data.subdescs.empty() ? "" : data.subdescs[i];
if (!subdata.name.empty() || !subdata.descr.empty())
- subdata.setup();
+ subdata.setup(run);
}
}
if (!configure(data, "VECTOR2D"))
return;
- uint16_t statid = stat.setup();
+ uint16_t statid = stat.setup(run);
if (!data.subnames.empty()) {
InsertSubData subdata;
subdata.name = data.subnames[i];
subdata.descr = data.subdescs.empty() ? "" : data.subdescs[i];
if (!subdata.name.empty() || !subdata.descr.empty())
- subdata.setup();
+ subdata.setup(run);
}
}
subdata.y = i;
subdata.name = data.y_subnames[i];
if (!subdata.name.empty())
- subdata.setup();
+ subdata.setup(run);
}
}
void
MySql::configure(const FormulaData &data)
{
+ MySQL::Connection &mysql = run->conn();
+ assert(mysql.connected());
+
configure(data, "FORMULA");
- insert(data.id, stat.setup());
- InsertFormula(find(data.id), data.str());
+ insert(data.id, stat.setup(run));
+
+ uint16_t stat = find(data.id);
+ string formula = data.str();
+
+ stringstream insert_formula;
+ ccprintf(insert_formula,
+ "INSERT INTO formulas(fm_stat,fm_formula) values(%d, \"%s\")",
+ stat, formula);
+
+ mysql.query(insert_formula);
+// if (mysql.error)
+// panic("could not insert formula\n%s\n", mysql.error);
+
+ stringstream insert_ref;
+ ccprintf(insert_ref,
+ "INSERT INTO formula_ref(fr_stat,fr_run) values(%d, %d)",
+ stat, run->run());
+
+ mysql.query(insert_ref);
+// if (mysql.error)
+// panic("could not insert formula reference\n%s\n", mysql.error);
+
+ if (mysql.commit())
+ panic("could not commit transaction\n%s\n", mysql.error);
}
bool
newdata.flush();
}
+void
+MySql::event(const std::string &event)
+{
+ newevent.insert(event);
+}
+
+
void
MySql::output(const ScalarData &data)
{
bool
initMySQL(string host, string user, string password, string database,
- string name, string sample, string project)
+ string name, string sample, string project)
{
extern list<Output *> OutputList;
static MySql mysql;
return true;
}
+
+/* end namespace Stats */ }