From: Nathan Binkert Date: Thu, 9 Apr 2009 05:22:50 +0000 (-0700) Subject: stats: disallow duplicate statistic names. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=c87c9950dfa094b0c3820f9abca721b0d32d2a09;p=gem5.git stats: disallow duplicate statistic names. --- diff --git a/src/base/statistics.cc b/src/base/statistics.cc index 0a59248e7..1f3562384 100644 --- a/src/base/statistics.cc +++ b/src/base/statistics.cc @@ -32,7 +32,6 @@ #include #include #include -#include #include #include "base/callback.hh" @@ -114,6 +113,14 @@ StorageParams::~StorageParams() { } +typedef map NameMapType; +NameMapType & +nameMap() +{ + static NameMapType the_map; + return the_map; +} + int Info::id_count = 0; int debug_break_id = -1; @@ -130,6 +137,24 @@ Info::~Info() { } +void +Info::setName(const string &name) +{ + pair p = + nameMap().insert(make_pair(name, this)); + + Info *other = p.first->second; + bool result = p.second; + + if (!result) { + // using other->name instead of just name to avoid a compiler + // warning. They should be the same. + panic("same statistic name used twice! name=%s\n", other->name); + } + + this->name = name; +} + bool Info::less(Info *stat1, Info *stat2) { diff --git a/src/base/statistics.hh b/src/base/statistics.hh index 88704207d..cd5be21ce 100644 --- a/src/base/statistics.hh +++ b/src/base/statistics.hh @@ -114,6 +114,9 @@ class Info Info(); virtual ~Info(); + /** Set the name of this statistic */ + void setName(const std::string &name); + /** * Check that this stat has been set up properly and is ready for * use @@ -402,10 +405,10 @@ class DataWrap : public InfoAccess * @return A reference to this stat. */ Derived & - name(const std::string &_name) + name(const std::string &name) { Info *info = this->info(); - info->name = _name; + info->setName(name); info->flags |= print; return this->self(); }