base: remove Trace::enabled flag

The DTRACE() macro tests both Trace::enabled and the specific flag. This
change uses the same administrative interface for enabling/disabling
tracing, but masks the SimpleFlags settings directly. This eliminates a
load for every DTRACE() test, e.g. DPRINTF.
This commit is contained in:
Curtis Dunham 2015-09-30 15:21:55 -05:00
parent ccf4f6c3d7
commit 02881a7bf3
13 changed files with 72 additions and 35 deletions

View file

@ -68,6 +68,8 @@ allFlags()
return flags; return flags;
} }
bool SimpleFlag::_active = false;
Flag * Flag *
findFlag(const std::string &name) findFlag(const std::string &name)
{ {
@ -94,18 +96,34 @@ Flag::~Flag()
// should find and remove flag. // should find and remove flag.
} }
void
SimpleFlag::enableAll()
{
_active = true;
for (auto& i : allFlags())
i.second->sync();
}
void
SimpleFlag::disableAll()
{
_active = false;
for (auto& i : allFlags())
i.second->sync();
}
void void
CompoundFlag::enable() CompoundFlag::enable()
{ {
SimpleFlag::enable(); for (auto& k : _kids)
for_each(_kids.begin(), _kids.end(), mem_fun(&Flag::enable)); k->enable();
} }
void void
CompoundFlag::disable() CompoundFlag::disable()
{ {
SimpleFlag::disable(); for (auto& k : _kids)
for_each(_kids.begin(), _kids.end(), mem_fun(&Flag::disable)); k->disable();
} }
struct AllFlags : public Flag struct AllFlags : public Flag

View file

@ -45,7 +45,6 @@ class Flag
protected: protected:
const char *_name; const char *_name;
const char *_desc; const char *_desc;
std::vector<Flag *> _kids;
public: public:
Flag(const char *name, const char *desc); Flag(const char *name, const char *desc);
@ -53,33 +52,43 @@ class Flag
std::string name() const { return _name; } std::string name() const { return _name; }
std::string desc() const { return _desc; } std::string desc() const { return _desc; }
std::vector<Flag *> kids() { return _kids; } virtual std::vector<Flag *> kids() { return std::vector<Flag*>(); }
virtual void enable() = 0; virtual void enable() = 0;
virtual void disable() = 0; virtual void disable() = 0;
virtual void sync() {}
}; };
class SimpleFlag : public Flag class SimpleFlag : public Flag
{ {
static bool _active; // whether debug tracings are enabled
protected: protected:
bool _status; bool _tracing; // tracing is enabled and flag is on
bool _status; // flag status
public: public:
SimpleFlag(const char *name, const char *desc) SimpleFlag(const char *name, const char *desc)
: Flag(name, desc), _status(false) : Flag(name, desc), _status(false)
{ } { }
bool status() const { return _status; } bool status() const { return _tracing; }
operator bool() const { return _status; } operator bool() const { return _tracing; }
bool operator!() const { return !_status; } bool operator!() const { return !_tracing; }
void enable() { _status = true; } void enable() { _status = true; sync(); }
void disable() { _status = false; } void disable() { _status = false; sync(); }
void sync() { _tracing = _active && _status; }
static void enableAll();
static void disableAll();
}; };
class CompoundFlag : public SimpleFlag class CompoundFlag : public Flag
{ {
protected: protected:
std::vector<Flag *> _kids;
void void
addFlag(Flag *f) addFlag(Flag *f)
{ {
@ -99,7 +108,7 @@ class CompoundFlag : public SimpleFlag
Flag *f14 = nullptr, Flag *f15 = nullptr, Flag *f14 = nullptr, Flag *f15 = nullptr,
Flag *f16 = nullptr, Flag *f17 = nullptr, Flag *f16 = nullptr, Flag *f17 = nullptr,
Flag *f18 = nullptr, Flag *f19 = nullptr) Flag *f18 = nullptr, Flag *f19 = nullptr)
: SimpleFlag(name, desc) : Flag(name, desc)
{ {
addFlag(f00); addFlag(f01); addFlag(f02); addFlag(f03); addFlag(f04); addFlag(f00); addFlag(f01); addFlag(f02); addFlag(f03); addFlag(f04);
addFlag(f05); addFlag(f06); addFlag(f07); addFlag(f08); addFlag(f09); addFlag(f05); addFlag(f06); addFlag(f07); addFlag(f08); addFlag(f09);
@ -107,6 +116,8 @@ class CompoundFlag : public SimpleFlag
addFlag(f15); addFlag(f16); addFlag(f17); addFlag(f18); addFlag(f19); addFlag(f15); addFlag(f16); addFlag(f17); addFlag(f18); addFlag(f19);
} }
std::vector<Flag *> kids() { return _kids; }
void enable(); void enable();
void disable(); void disable();
}; };

View file

@ -39,6 +39,7 @@
#include <sstream> #include <sstream>
#include <string> #include <string>
#include "base/debug.hh"
#include "base/misc.hh" #include "base/misc.hh"
#include "base/output.hh" #include "base/output.hh"
#include "base/str.hh" #include "base/str.hh"
@ -54,8 +55,6 @@ const std::string &name()
namespace Trace namespace Trace
{ {
bool enabled = false;
// This variable holds the output logger for debug information. Other // This variable holds the output logger for debug information. Other
// than setting up/redirecting this logger, do *NOT* reference this // than setting up/redirecting this logger, do *NOT* reference this
// directly // directly
@ -87,6 +86,18 @@ setDebugLogger(Logger *logger)
debug_logger = logger; debug_logger = logger;
} }
void
enable()
{
Debug::SimpleFlag::enableAll();
}
void
disable()
{
Debug::SimpleFlag::disableAll();
}
ObjectMatch ignore; ObjectMatch ignore;
void void

View file

@ -116,8 +116,9 @@ std::ostream &output();
/** Delete the current global logger and assign a new one */ /** Delete the current global logger and assign a new one */
void setDebugLogger(Logger *logger); void setDebugLogger(Logger *logger);
/** Enable debug logging */ /** Enable/disable debug logging */
extern bool enabled; void enable();
void disable();
} // namespace Trace } // namespace Trace
@ -160,7 +161,7 @@ class Named
#if TRACING_ON #if TRACING_ON
#define DTRACE(x) ((Debug::x) && Trace::enabled) #define DTRACE(x) (Debug::x)
#define DDUMP(x, data, count) do { \ #define DDUMP(x, data, count) do { \
using namespace Debug; \ using namespace Debug; \

View file

@ -75,9 +75,6 @@ class ExeTracer : public InstTracer
if (!Debug::ExecEnable) if (!Debug::ExecEnable)
return NULL; return NULL;
if (!Trace::enabled)
return NULL;
return new ExeTracerRecord(when, tc, return new ExeTracerRecord(when, tc,
staticInst, pc, macroStaticInst); staticInst, pc, macroStaticInst);
} }

View file

@ -123,8 +123,8 @@ InstPBTraceRecord*
InstPBTrace::getInstRecord(Tick when, ThreadContext *tc, const StaticInstPtr si, InstPBTrace::getInstRecord(Tick when, ThreadContext *tc, const StaticInstPtr si,
TheISA::PCState pc, const StaticInstPtr mi) TheISA::PCState pc, const StaticInstPtr mi)
{ {
// Only record the trace if Exec debugging in enabled // Only record the trace if Exec debugging is enabled
if (!Trace::enabled || !Debug::ExecEnable) if (!Debug::ExecEnable)
return NULL; return NULL;
return new InstPBTraceRecord(*this, when, tc, si, pc, mi); return new InstPBTraceRecord(*this, when, tc, si, pc, mi);

View file

@ -71,9 +71,6 @@ class IntelTrace : public InstTracer
if (!Debug::ExecEnable) if (!Debug::ExecEnable)
return NULL; return NULL;
if (!Trace::enabled)
return NULL;
return new IntelTraceRecord(when, tc, staticInst, pc, macroStaticInst); return new IntelTraceRecord(when, tc, staticInst, pc, macroStaticInst);
} }
}; };

View file

@ -32,7 +32,7 @@ import util
from internal.trace import output, ignore from internal.trace import output, ignore
def disable(): def disable():
internal.trace.cvar.enabled = False internal.trace.disable()
def enable(): def enable():
internal.trace.cvar.enabled = True internal.trace.enable()

View file

@ -54,9 +54,11 @@ ignore(const char *expr)
Trace::getDebugLogger()->setIgnore(ignore); Trace::getDebugLogger()->setIgnore(ignore);
} }
using Trace::enabled; inline void enable() { Trace::enable(); }
inline void disable() { Trace::disable(); }
%} %}
extern void output(const char *string); extern void output(const char *string);
extern void ignore(const char *expr); extern void ignore(const char *expr);
extern bool enabled; extern void enable();
extern void disable();

View file

@ -117,7 +117,7 @@ main(int argc, char **argv)
Stats::initSimStats(); Stats::initSimStats();
Stats::registerHandlers(CxxConfig::statsReset, CxxConfig::statsDump); Stats::registerHandlers(CxxConfig::statsReset, CxxConfig::statsDump);
Trace::enabled = true; Trace::enable();
setDebugFlag("Terminal"); setDebugFlag("Terminal");
// setDebugFlag("CxxConfig"); // setDebugFlag("CxxConfig");

View file

@ -162,7 +162,7 @@ SimControl::SimControl(sc_core::sc_module_name name,
Stats::initSimStats(); Stats::initSimStats();
Stats::registerHandlers(CxxConfig::statsReset, CxxConfig::statsDump); Stats::registerHandlers(CxxConfig::statsReset, CxxConfig::statsDump);
Trace::enabled = true; Trace::enable();
setDebugFlag("Terminal"); setDebugFlag("Terminal");
checkpoint_restore = false; checkpoint_restore = false;

View file

@ -241,7 +241,7 @@ Gem5TopLevelModule::Gem5TopLevelModule(sc_core::sc_module_name name,
Stats::initSimStats(); Stats::initSimStats();
Stats::registerHandlers(CxxConfig::statsReset, CxxConfig::statsDump); Stats::registerHandlers(CxxConfig::statsReset, CxxConfig::statsDump);
Trace::enabled = true; Trace::enable();
config_file = new CxxIniFile(); config_file = new CxxIniFile();

View file

@ -142,7 +142,7 @@ SimControl::SimControl(sc_core::sc_module_name name,
Stats::initSimStats(); Stats::initSimStats();
Stats::registerHandlers(CxxConfig::statsReset, CxxConfig::statsDump); Stats::registerHandlers(CxxConfig::statsReset, CxxConfig::statsDump);
Trace::enabled = true; Trace::enable();
sim_end = 0; sim_end = 0;
debug = false; debug = false;