changeset 45c8a91d1174 in /z/repo/m5
details: http://repo.m5sim.org/m5?cmd=changeset;node=45c8a91d1174
description:
stats: disallow duplicate statistic names.
diffstat:
2 files changed, 31 insertions(+), 3 deletions(-)
src/base/statistics.cc | 27 ++++++++++++++++++++++++++-
src/base/statistics.hh | 7 +++++--
diffs (77 lines):
diff -r 044903442dcb -r 45c8a91d1174 src/base/statistics.cc
--- a/src/base/statistics.cc Wed Apr 08 22:22:49 2009 -0700
+++ b/src/base/statistics.cc Wed Apr 08 22:22:50 2009 -0700
@@ -32,7 +32,6 @@
#include <fstream>
#include <list>
#include <map>
-#include <set>
#include <string>
#include "base/callback.hh"
@@ -114,6 +113,14 @@
{
}
+typedef map<std::string, Info *> NameMapType;
+NameMapType &
+nameMap()
+{
+ static NameMapType the_map;
+ return the_map;
+}
+
int Info::id_count = 0;
int debug_break_id = -1;
@@ -130,6 +137,24 @@
{
}
+void
+Info::setName(const string &name)
+{
+ pair<NameMapType::iterator, bool> 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 -r 044903442dcb -r 45c8a91d1174 src/base/statistics.hh
--- a/src/base/statistics.hh Wed Apr 08 22:22:49 2009 -0700
+++ b/src/base/statistics.hh Wed Apr 08 22:22:50 2009 -0700
@@ -114,6 +114,9 @@
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 @@
* @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();
}
_______________________________________________
m5-dev mailing list
[email protected]
http://m5sim.org/mailman/listinfo/m5-dev