Gabe Black has uploaded this change for review. (
https://gem5-review.googlesource.com/c/public/gem5/+/45007 )
Change subject: base,python: Simplify how we check if a debug flag is
enabled.
......................................................................
base,python: Simplify how we check if a debug flag is enabled.
Compound debug flags are intended to be a way to enable or disable a
group of simple debug flags at once, so that you don't need to enumerate
every more specialized flag in an area to get a broad amount of
debugging, nor do you give up the ability to select a general area
easily by making more specific flags.
It doesn't, however, make a lot of sense to check the value of a
compound debug flag, since it could be enabled but then have individual
subflags disabled. Exactly whether that means the compound flag should
be enabled or not is not clear, and figuring it out takes a fair amount
of work since each member simple flag needs to be visited.
Also, by having different behavior depending on the flag type, the
"enabled" method needed to be virtual.
This change eliminates the virtual method and moves the _tracing bool
member into the base class. If a subclass (only SimpleFlag currently)
wants to start or stop tracing based on itself, it should set or clear
this flag. Also, the "enabled" method has been renamed to "tracing",
since that's actually what it tracked. Being enabled by itself is not
sufficient to be tracing since there is also a global enable.
In addition to simplifying the code, this should speed up checks of
debug flags significantly since the call to tracing (formerly enabled)
can be inlined and will involve only a simple dereference. Also, since
_tracing is the first member of the class, we avoid having to even
calculate an offset into the object.
Finally, rather than duplicate the logic to convert a flag to bool in
the python wrapper, we can just use a cast to bool and take advantage of
the version in C++.
Change-Id: I3dc64c2364f0239294093686ddac6fcc8441f306
---
M src/base/debug.cc
M src/base/debug.hh
M src/python/pybind11/debug.cc
3 files changed, 9 insertions(+), 24 deletions(-)
diff --git a/src/base/debug.cc b/src/base/debug.cc
index 38eb25f..34bc4f4 100644
--- a/src/base/debug.cc
+++ b/src/base/debug.cc
@@ -137,20 +137,6 @@
}
bool
-CompoundFlag::enabled() const
-{
- if (_kids.empty())
- return false;
-
- for (auto& k : _kids) {
- if (!k->enabled())
- return false;
- }
-
- return true;
-}
-
-bool
changeFlag(const char *s, bool value)
{
Flag *f = findFlag(s);
@@ -188,7 +174,7 @@
FlagsMap::iterator end = allFlags().end();
for (; i != end; ++i) {
SimpleFlag *f = dynamic_cast<SimpleFlag *>(i->second);
- if (f && f->enabled())
+ if (f && f->tracing())
ccprintf(os, "%s\n", f->name());
}
}
diff --git a/src/base/debug.hh b/src/base/debug.hh
index 4b77e16..c5d3f53 100644
--- a/src/base/debug.hh
+++ b/src/base/debug.hh
@@ -62,6 +62,8 @@
virtual void sync() { }
+ bool _tracing = false; // tracing is enabled and flag is on
+
public:
Flag(const char *name, const char *desc);
virtual ~Flag();
@@ -69,11 +71,12 @@
std::string name() const { return _name; }
std::string desc() const { return _desc; }
+ bool tracing() const { return _tracing; }
+
virtual void enable() = 0;
virtual void disable() = 0;
- virtual bool enabled() const = 0;
- operator bool() const { return enabled(); }
+ operator bool() const { return tracing(); }
static void globalEnable();
static void globalDisable();
@@ -85,7 +88,6 @@
/** Whether this flag changes debug formatting. */
const bool _isFormat = false;
- bool _tracing = false; // tracing is enabled and flag is on
bool _enabled = false; // flag enablement status
void sync() override { _tracing = _globalEnable && _enabled; }
@@ -95,8 +97,6 @@
: Flag(name, desc), _isFormat(is_format)
{}
- bool enabled() const override { return _tracing; }
-
void enable() override { _enabled = true; sync(); }
void disable() override { _enabled = false; sync(); }
@@ -127,7 +127,6 @@
void enable() override;
void disable() override;
- bool enabled() const override;
};
typedef std::map<std::string, Flag *> FlagsMap;
diff --git a/src/python/pybind11/debug.cc b/src/python/pybind11/debug.cc
index a2b5406..cca0f9c 100644
--- a/src/python/pybind11/debug.cc
+++ b/src/python/pybind11/debug.cc
@@ -94,9 +94,9 @@
.def_property_readonly("desc", &Debug::Flag::desc)
.def("enable", &Debug::Flag::enable)
.def("disable", &Debug::Flag::disable)
- .def_property("enabled",
+ .def_property("tracing",
[](const Debug::Flag *flag) {
- return flag->enabled();
+ return flag->tracing();
},
[](Debug::Flag *flag, bool state) {
if (state) {
@@ -106,7 +106,7 @@
}
})
.def("__bool__", [](const Debug::Flag *flag) {
- return flag->enabled();
+ return (bool)*flag;
})
;
--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/45007
To unsubscribe, or for help writing mail filters, visit
https://gem5-review.googlesource.com/settings
Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: I3dc64c2364f0239294093686ddac6fcc8441f306
Gerrit-Change-Number: 45007
Gerrit-PatchSet: 1
Gerrit-Owner: Gabe Black <[email protected]>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s