stats: Fix incorrect name conflict panic with grouped stats
authorAndreas Sandberg <andreas.sandberg@arm.com>
Fri, 6 Sep 2019 17:43:31 +0000 (18:43 +0100)
committerAndreas Sandberg <andreas.sandberg@arm.com>
Tue, 10 Sep 2019 15:55:50 +0000 (15:55 +0000)
Info::setName() performs a sanity check to ensure that the same stat
name isn't used twice. This doesn't work for new-style stats with a
parent group since the name is only unique within the group. Disable
the check for new-style stats since these usually use names generated
from member variable names.

Change-Id: I590abe6040407c6a4fe582c0782a418165ff5588
Signed-off-by: Andreas Sandberg <andreas.sandberg@arm.com>
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/20760
Maintainer: Jason Lowe-Power <jason@lowepower.com>
Reviewed-by: Jason Lowe-Power <jason@lowepower.com>
Tested-by: kokoro <noreply+kokoro@google.com>
src/base/statistics.cc
src/base/statistics.hh
src/base/stats/info.hh

index a186f976312278a35526defec52f0dbec8ad43b2..5e6882c79a3924be2f97694b369748efd59db9ac 100644 (file)
@@ -202,20 +202,26 @@ validateStatName(const string &name)
 
 void
 Info::setName(const string &name)
+{
+    setName(nullptr, name);
+}
+
+void
+Info::setName(const Group *parent, const string &name)
 {
     if (!validateStatName(name))
         panic("invalid stat name '%s'", name);
 
-    pair<NameMapType::iterator, bool> p =
-        nameMap().insert(make_pair(name, this));
-
-    Info *other = p.first->second;
-    bool result = p.second;
+    // We only register the stat with the nameMap() if we are using
+    // old-style stats without a parent group. New-style stats should
+    // be unique since their names should correspond to a member
+    // variable.
+    if (!parent) {
+        auto p = nameMap().insert(make_pair(name, this));
 
-    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);
+        if (!p.second)
+            panic("same statistic name used twice! name=%s\n",
+                  name);
     }
 
     this->name = name;
index f4fa123e970d71780883f1c2495adae18dd8deee..07f29599541c80d1e4f309a3d7f91a1f903c7d7c 100644 (file)
@@ -262,7 +262,7 @@ class DataWrap : public InfoAccess
             parent->addStat(info);
 
         if (name) {
-            info->setName(name);
+            info->setName(parent, name);
             info->flags.set(display);
         }
 
index 6ce7376a4a38ebe3f4bf3f5b47af7af47b2b00c0..c03b51183c80e97fd4e9f675529c5e50c8e54712 100644 (file)
@@ -36,6 +36,8 @@
 
 namespace Stats {
 
+class Group;
+
 typedef uint16_t FlagsType;
 typedef ::Flags<FlagsType> Flags;
 
@@ -97,6 +99,7 @@ class Info
 
     /** Set the name of this statistic */
     void setName(const std::string &name);
+    void setName(const Group *parent, const std::string &name);
     void setSeparator(std::string _sep) { separatorString = _sep;}
 
     /**