From: Nathan Binkert Date: Mon, 28 Jun 2004 20:49:35 +0000 (-0400) Subject: fix up the recordEvent stuff to support ignoring events X-Git-Tag: m5_1.0_tutorial~286 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=838273a196c66f3c6ee834ae865db14f313ef1bc;p=gem5.git fix up the recordEvent stuff to support ignoring events arch/alpha/ev5.cc: cpu/simple_cpu/simple_cpu.cc: update for new event interface base/stats/events.cc: implement the ignore event function which matches sim objects from which to ignore events. Make insert event like insert data and make it able to insert many events in a single transaction with the database. base/stats/events.hh: Make it possible to ignore events sim/sim_object.cc: make recordEvent a member function of SimObject to implement the ignore function easily sim/sim_object.hh: implement the ignore event stuff in the sim object. This is a bit of a hack, but an easy place to put it. --HG-- extra : convert_revision : ba3f25a14ad03662c53fb35514860d69be8cd4f0 --- diff --git a/arch/alpha/ev5.cc b/arch/alpha/ev5.cc index d2ca71b3a..b043ed0ee 100644 --- a/arch/alpha/ev5.cc +++ b/arch/alpha/ev5.cc @@ -6,6 +6,7 @@ #include "base/kgdb.h" #include "base/remote_gdb.hh" #include "base/stats/events.hh" +#include "cpu/base_cpu.hh" #include "cpu/exec_context.hh" #include "cpu/fast_cpu/fast_cpu.hh" #include "sim/debug.hh" @@ -163,7 +164,7 @@ void ExecContext::ev5_trap(Fault fault) { DPRINTF(Fault, "Fault %s\n", FaultName(fault)); - Stats::recordEvent(csprintf("Fault %s", FaultName(fault))); + cpu->recordEvent(csprintf("Fault %s", FaultName(fault))); assert(!misspeculating()); kernelStats.fault(fault); diff --git a/base/stats/events.cc b/base/stats/events.cc index b579981e9..ed25e2423 100644 --- a/base/stats/events.cc +++ b/base/stats/events.cc @@ -26,6 +26,8 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include + #ifdef USE_MYSQL #include "base/cprintf.hh" #include "base/misc.hh" @@ -33,9 +35,9 @@ #include "base/stats/events.hh" #include "base/stats/mysql.hh" #include "base/stats/mysql_run.hh" -#include "base/str.hh" #endif +#include "base/str.hh" #include "sim/host.hh" #include "sim/universe.hh" @@ -45,20 +47,80 @@ namespace Stats { Tick EventStart = ULL(0xffffffffffffffff); +vector event_ignore; +vector > ignore_tokens; +vector ignore_size; +int event_ignore_size; + +bool +ignoreEvent(const string &name) +{ + vector name_tokens; + tokenize(name_tokens, name, '.'); + int ntsize = name_tokens.size(); + + for (int i = 0; i < event_ignore_size; ++i) { + bool match = true; + int jstop = ignore_size[i]; + for (int j = 0; j < jstop; ++j) { + if (j >= ntsize) + break; + + const string &ignore = ignore_tokens[i][j]; + if (ignore != "*" && ignore != name_tokens[j]) { + match = false; + break; + } + } + + if (match == true) + return true; + } + + return false; +} + #ifdef USE_MYSQL -typedef map event_map_t; -event_map_t event_map; +class InsertEvent +{ + private: + char *query; + int size; + bool first; + static const int maxsize = 1024*1024; + + typedef map 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 -__event(const string &stat) +InsertEvent::insert(const string &stat) { - MySQL::Connection &mysql = MySqlDB.conn(); - uint16_t run = MySqlDB.run(); assert(mysql.connected()); - event_map_t::iterator i = event_map.find(stat); + event_map_t::iterator i = events.find(stat); uint32_t event; - if (i == event_map.end()) { + if (i == events.end()) { mysql.query( csprintf("SELECT en_id " "from event_names " @@ -90,16 +152,45 @@ __event(const string &stat) event = (*i).second; } - mysql.query( - csprintf("INSERT INTO " - "events(ev_event, ev_run, ev_tick)" - "values(%d, %d, %d)", - event, run, curTick)); + if (size + 1024 > maxsize) + flush(); + + if (!first) { + query[size++] = ','; + query[size] = '\0'; + } - if (mysql.error) - panic("could not get a run\n%s\n", mysql.error); + first = false; + size += sprintf(query + size, "(%u,%u,%llu)", + event, run, curTick); } + +void +InsertEvent::flush() +{ + if (size) { + MySQL::Connection &mysql = MySqlDB.conn(); + assert(mysql.connected()); + mysql.query(query); + } + + query[0] = '\0'; + size = 0; + first = true; + strcpy(query, "INSERT INTO " + "events(ev_event, ev_run, ev_tick)" + "values"); + size = strlen(query); +} + +void +__event(const string &stat) +{ + static InsertEvent event; + event.insert(stat); +} + #endif /* namespace Stats */ } diff --git a/base/stats/events.hh b/base/stats/events.hh index 49c060645..3a7d85644 100644 --- a/base/stats/events.hh +++ b/base/stats/events.hh @@ -42,6 +42,8 @@ void __event(const std::string &stat); bool MySqlConnected(); #endif +bool ignoreEvent(const std::string &name); + inline void recordEvent(const std::string &stat) { diff --git a/cpu/simple_cpu/simple_cpu.cc b/cpu/simple_cpu/simple_cpu.cc index bf4cbfbe2..2c7f78cff 100644 --- a/cpu/simple_cpu/simple_cpu.cc +++ b/cpu/simple_cpu/simple_cpu.cc @@ -406,7 +406,7 @@ SimpleCPU::read(Addr addr, T &data, unsigned flags) } if (!dcacheInterface && (memReq->flags & UNCACHEABLE)) - Stats::recordEvent("Uncached Read"); + recordEvent("Uncached Read"); return fault; } @@ -494,7 +494,7 @@ SimpleCPU::write(T data, Addr addr, unsigned flags, uint64_t *res) *res = memReq->result; if (!dcacheInterface && (memReq->flags & UNCACHEABLE)) - Stats::recordEvent("Uncached Write"); + recordEvent("Uncached Write"); return fault; } diff --git a/sim/sim_object.cc b/sim/sim_object.cc index cab629f8d..39219b500 100644 --- a/sim/sim_object.cc +++ b/sim/sim_object.cc @@ -32,6 +32,7 @@ #include "base/inifile.hh" #include "base/misc.hh" #include "base/trace.hh" +#include "base/stats/events.hh" #include "sim/configfile.hh" #include "sim/host.hh" #include "sim/sim_object.hh" @@ -58,6 +59,7 @@ SimObject::SimObjectList SimObject::simObjectList; SimObject::SimObject(const string &_name) : objName(_name) { + doRecordEvent = !Stats::ignoreEvent(_name); simObjectList.push_back(this); } @@ -170,4 +172,11 @@ SimObject::serializeAll(ostream &os) } } +void +SimObject::recordEvent(const std::string &stat) +{ + if (doRecordEvent) + Stats::recordEvent(stat); +} + DEFINE_SIM_OBJECT_CLASS_NAME("SimObject", SimObject) diff --git a/sim/sim_object.hh b/sim/sim_object.hh index 1a9ed363d..770cd558e 100644 --- a/sim/sim_object.hh +++ b/sim/sim_object.hh @@ -82,6 +82,10 @@ class SimObject : public Serializable // static: call nameOut() & serialize() on all SimObjects static void serializeAll(std::ostream &); + + public: + bool doRecordEvent; + void recordEvent(const std::string &stat); }; #endif // __SIM_OBJECT_HH__