*/
#include <cassert>
+#include <cstdio>
#include <map>
#include <sstream>
#include <string>
if (mysql.commit())
panic("could not commit transaction\n%s\n", mysql.error);
-
- mysql.query("DELETE events"
- "FROM events"
- "LEFT JOIN runs ON ev_run=rn_id"
- "WHERE rn_id IS NULL");
-
- if (mysql.commit())
- panic("could not commit transaction\n%s\n", mysql.error);
-
- mysql.query("DELETE event_names"
- "FROM event_names"
- "LEFT JOIN events ON en_id=ev_event"
- "WHERE ev_event IS NULL");
-
- if (mysql.commit())
- panic("could not commit transaction\n%s\n", mysql.error);
}
void
data);
}
-InsertEvent::InsertEvent(MySqlRun *_run)
- : run(_run)
-{
- query = new char[maxsize + 1];
- size = 0;
- first = true;
- flush();
-}
-
-InsertEvent::~InsertEvent()
-{
- flush();
-}
-
-void
-InsertEvent::insert(const string &stat)
-{
- MySQL::Connection &mysql = run->conn();
- 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->run(), (unsigned long long)curTick);
-}
-
-void
-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());
-
- if (size)
- mysql.query(query);
-
- query[0] = '\0';
- size = sizeof(query_header);
- first = true;
- memcpy(query, query_header, size);
-}
-
struct InsertSubData
{
uint16_t stat;
}
MySql::MySql()
- : run(new MySqlRun), newdata(run), newevent(run)
+ : run(new MySqlRun), newdata(run)
{}
MySql::~MySql()
stat.name = info.name;
stat.descr = info.desc;
stat.type = type;
- stat.print = info.flags & print;
+ stat.print = info.flags & display;
stat.prec = info.precision;
stat.nozero = info.flags & nozero;
stat.nonan = info.flags & nonan;
if (!configure(info, "DIST"))
return;
- const DistParams *params =
- safe_cast<const DistParams *>(info.storageParams);
- if (params->type == Dist) {
+ const DistStor::Params *params =
+ dynamic_cast<const DistStor::Params *>(info.storageParams);
+ if (params) {
+ assert(params->type == Dist);
stat.size = params->buckets;
stat.min = params->min;
stat.max = params->max;
if (!configure(info, "VECTORDIST"))
return;
- const DistParams *params =
- safe_cast<const DistParams *>(info.storageParams);
- if (params->type == Dist) {
+ const DistStor::Params *params =
+ dynamic_cast<const DistStor::Params *>(info.storageParams);
+ if (params) {
+ assert(params->type == Dist);
stat.size = params->buckets;
stat.min = params->min;
stat.max = params->max;
configure();
// store sample #
- newdata.tick = curTick;
+ newdata.tick = curTick();
MySQL::Connection &mysql = run->conn();
newdata.flush();
}
-void
-MySql::event(const std::string &event)
-{
- newevent.insert(event);
-}
-
void
MySql::output(const ScalarInfo &info)
{
- if (!(info.flags & print))
+ if (!(info.flags & display))
return;
newdata.stat = find(info.id);
void
MySql::output(const VectorInfo &info)
{
- if (!(info.flags & print))
+ if (!(info.flags & display))
return;
newdata.stat = find(info.id);
void
MySql::output(const DistInfo &info)
{
- if (!(info.flags & print))
+ if (!(info.flags & display))
return;
newdata.stat = find(info.id);
void
MySql::output(const VectorDistInfo &info)
{
- if (!(info.flags & print))
+ if (!(info.flags & display))
return;
newdata.stat = find(info.id);
void
MySql::output(const Vector2dInfo &info)
{
- if (!(info.flags & print))
+ if (!(info.flags & display))
return;
newdata.stat = find(info.id);
return true;
}
-/* end namespace Stats */ }
+} // namespace Stats