summaryrefslogtreecommitdiff
path: root/src/base
diff options
context:
space:
mode:
authorNathan Binkert <binkertn@umich.edu>2007-02-10 15:14:50 -0800
committerNathan Binkert <binkertn@umich.edu>2007-02-10 15:14:50 -0800
commit184decd1963a7f016231f7614b5e739ad514ed37 (patch)
tree255576eeee2401b9148aa9610559cc9b5e024807 /src/base
parent63a82400596b9331d1babe88624f97209286d0b9 (diff)
downloadgem5-184decd1963a7f016231f7614b5e739ad514ed37.tar.xz
Clean up tracing stuff more, get rid of the trace log since
its not all that useful. Fix a few bugs with python/C++ integration. --HG-- extra : convert_revision : a706512f7dc8b0c88f1ff96fe35ab8fbf9548b78
Diffstat (limited to 'src/base')
-rw-r--r--src/base/trace.cc209
-rw-r--r--src/base/trace.hh138
2 files changed, 121 insertions, 226 deletions
diff --git a/src/base/trace.cc b/src/base/trace.cc
index efa76b044..7afb038be 100644
--- a/src/base/trace.cc
+++ b/src/base/trace.cc
@@ -37,8 +37,9 @@
#include <vector>
#include "base/misc.hh"
-#include "base/trace.hh"
+#include "base/output.hh"
#include "base/str.hh"
+#include "base/trace.hh"
#include "base/varargs.hh"
using namespace std;
@@ -55,149 +56,74 @@ bool enabled = true;
// output.
//
ostream *dprintf_stream = &cerr;
-
-ObjectMatch ignore;
-
-Log theLog;
-
-Log::Log()
+ostream &
+output()
{
- size = 0;
- buffer = NULL;
+ return *dprintf_stream;
}
-
void
-Log::init(int _size)
+setOutput(const string &filename)
{
- if (buffer != NULL) {
- fatal("Trace::Log::init called twice!");
- }
-
- size = _size;
-
- buffer = new Record *[size];
-
- for (int i = 0; i < size; ++i) {
- buffer[i] = NULL;
- }
-
- nextRecPtr = &buffer[0];
- wrapRecPtr = &buffer[size];
+ dprintf_stream = simout.find(filename);
}
+ObjectMatch ignore;
-Log::~Log()
+void
+dprintf(Tick when, const std::string &name, const char *format,
+ CPRINTF_DEFINITION)
{
- for (int i = 0; i < size; ++i) {
- delete buffer[i];
- }
-
- delete [] buffer;
-}
+ if (!name.empty() && ignore.match(name))
+ return;
+ std::ostream &os = *dprintf_stream;
-void
-Log::append(Record *rec)
-{
- // dump record to output stream if there's one open
- if (dprintf_stream != NULL) {
- rec->dump(*dprintf_stream);
- } else {
- rec->dump(cout);
- }
+ string fmt = "";
+ CPrintfArgsList args(VARARGS_ALLARGS);
- // no buffering: justget rid of it now
- if (buffer == NULL) {
- delete rec;
- return;
+ if (!name.empty()) {
+ fmt = "%s: " + fmt;
+ args.push_front(name);
}
- Record *oldRec = *nextRecPtr;
-
- if (oldRec != NULL) {
- // log has wrapped: overwrite
- delete oldRec;
+ if (when != (Tick)-1) {
+ fmt = "%7d: " + fmt;
+ args.push_front(when);
}
- *nextRecPtr = rec;
+ fmt += format;
- if (++nextRecPtr == wrapRecPtr) {
- nextRecPtr = &buffer[0];
- }
+ ccprintf(os, fmt.c_str(), args);
+ os.flush();
}
-
void
-Log::dump(ostream &os)
+dump(Tick when, const std::string &name, const void *d, int len)
{
- if (buffer == NULL) {
+ if (!name.empty() && ignore.match(name))
return;
- }
-
- Record **bufPtr = nextRecPtr;
-
- if (*bufPtr == NULL) {
- // next record slot is empty: log must not be full yet.
- // start dumping from beginning of buffer
- bufPtr = buffer;
- }
-
- do {
- Record *rec = *bufPtr;
-
- rec->dump(os);
- if (++bufPtr == wrapRecPtr) {
- bufPtr = &buffer[0];
- }
- } while (bufPtr != nextRecPtr);
-}
-
-PrintfRecord::~PrintfRecord()
-{}
+ std::ostream &os = *dprintf_stream;
-void
-PrintfRecord::dump(ostream &os)
-{
string fmt = "";
+ CPrintfArgsList args;
if (!name.empty()) {
fmt = "%s: " + fmt;
args.push_front(name);
}
- if (cycle != (Tick)-1) {
+ if (when != (Tick)-1) {
fmt = "%7d: " + fmt;
- args.push_front(cycle);
+ args.push_front(when);
}
- fmt += format;
-
- ccprintf(os, fmt.c_str(), args);
- os.flush();
-}
-
-DataRecord::DataRecord(Tick _cycle, const string &_name,
- const void *_data, int _len)
- : Record(_cycle), name(_name), len(_len)
-{
- data = new uint8_t[len];
- memcpy(data, _data, len);
-}
-
-DataRecord::~DataRecord()
-{
- delete [] data;
-}
-
-void
-DataRecord::dump(ostream &os)
-{
+ const char *data = static_cast<const char *>(d);
int c, i, j;
-
for (i = 0; i < len; i += 16) {
- ccprintf(os, "%d: %s: %08x ", cycle, name, i);
+ ccprintf(os, fmt, args);
+ ccprintf(os, "%08x ", i);
c = len - i;
if (c > 16) c = 16;
@@ -213,8 +139,7 @@ DataRecord::dump(ostream &os)
for (j = 0; j < c; j++) {
int ch = data[i + j] & 0x7f;
- ccprintf(os,
- "%c", (char)(isprint(ch) ? ch : ' '));
+ ccprintf(os, "%c", (char)(isprint(ch) ? ch : ' '));
}
ccprintf(os, "\n");
@@ -223,4 +148,66 @@ DataRecord::dump(ostream &os)
break;
}
}
-} // namespace Trace
+
+bool
+changeFlag(const char *s, bool value)
+{
+ using namespace Trace;
+ std::string str(s);
+
+ for (int i = 0; i < numFlagStrings; ++i) {
+ if (str != flagStrings[i])
+ continue;
+
+ if (i < NumFlags) {
+ flags[i] = value;
+ } else {
+ i -= NumFlags;
+
+ const Flags *flagVec = compoundFlags[i];
+ for (int j = 0; flagVec[j] != -1; ++j) {
+ if (flagVec[j] < NumFlags)
+ flags[flagVec[j]] = value;
+ }
+ }
+
+ return true;
+ }
+
+ // the flag was not found.
+ return false;
+}
+
+void
+dumpStatus()
+{
+ using namespace Trace;
+ for (int i = 0; i < numFlagStrings; ++i) {
+ if (flags[i])
+ cprintf("%s\n", flagStrings[i]);
+ }
+}
+
+/* namespace Trace */ }
+
+
+// add a set of functions that can easily be invoked from gdb
+extern "C" {
+ void
+ setTraceFlag(const char *string)
+ {
+ Trace::changeFlag(string, true);
+ }
+
+ void
+ clearTraceFlag(const char *string)
+ {
+ Trace::changeFlag(string, false);
+ }
+
+ void
+ dumpTraceStatus()
+ {
+ Trace::dumpStatus();
+ }
+/* extern "C" */ }
diff --git a/src/base/trace.hh b/src/base/trace.hh
index dbe98a11b..8e380d8e1 100644
--- a/src/base/trace.hh
+++ b/src/base/trace.hh
@@ -32,132 +32,35 @@
#ifndef __BASE_TRACE_HH__
#define __BASE_TRACE_HH__
+#include <string>
#include <vector>
#include "base/cprintf.hh"
#include "base/match.hh"
+#include "base/traceflags.hh"
#include "sim/host.hh"
#include "sim/root.hh"
-#include "base/traceflags.hh"
-
namespace Trace {
- typedef std::vector<bool> FlagVec;
-
- extern FlagVec flags;
-
- extern std::ostream *dprintf_stream;
-
- inline bool
- IsOn(int t)
- {
- return flags[t];
- }
-
- extern bool enabled;
-
- void dump(const uint8_t *data, int count);
-
- class Record
- {
- protected:
- Tick cycle;
-
- Record(Tick _cycle)
- : cycle(_cycle)
- {
- }
-
- public:
- virtual ~Record() {}
-
- virtual void dump(std::ostream &) = 0;
- };
-
- class PrintfRecord : public Record
- {
- private:
- const std::string &name;
- const char *format;
- CPrintfArgsList args;
-
- public:
- PrintfRecord(Tick cycle, const std::string &_name, const char *_format,
- CPRINTF_DECLARATION)
- : Record(cycle), name(_name), format(_format),
- args(VARARGS_ALLARGS)
- {
- }
-
- virtual ~PrintfRecord();
-
- virtual void dump(std::ostream &);
- };
-
- class DataRecord : public Record
- {
- private:
- const std::string &name;
- uint8_t *data;
- int len;
+std::ostream &output();
+void setOutput(const std::string &filename);
- public:
- DataRecord(Tick cycle, const std::string &name,
- const void *_data, int _len);
- virtual ~DataRecord();
+extern bool enabled;
+typedef std::vector<bool> FlagVec;
+extern FlagVec flags;
+inline bool IsOn(int t) { return flags[t]; }
+bool changeFlag(const char *str, bool value);
+void dumpStatus();
- virtual void dump(std::ostream &);
- };
+extern ObjectMatch ignore;
+extern const std::string DefaultName;
- class Log
- {
- private:
- int size; // number of records in log
- Record **buffer; // array of 'size' Record ptrs (circular buf)
- Record **nextRecPtr; // next slot to use in buffer
- Record **wrapRecPtr; // &buffer[size], for quick wrap check
+void dprintf(Tick when, const std::string &name, const char *format,
+ CPRINTF_DECLARATION);
+void dump(Tick when, const std::string &name, const void *data, int len);
- public:
- Log();
- ~Log();
-
- void init(int _size);
-
- void append(Record *); // append trace record to log
- void dump(std::ostream &); // dump contents to stream
- };
-
- extern Log theLog;
-
- extern ObjectMatch ignore;
-
- inline void
- dprintf(Tick when, const std::string &name, const char *format,
- CPRINTF_DECLARATION)
- {
- if (!name.empty() && ignore.match(name))
- return;
-
- theLog.append(new Trace::PrintfRecord(when, name, format,
- VARARGS_ALLARGS));
- }
-
- inline void
- dataDump(Tick when, const std::string &name, const void *data, int len)
- {
- theLog.append(new Trace::DataRecord(when, name, data, len));
- }
-
- extern const std::string DefaultName;
-
-};
-
-inline std::ostream &
-DebugOut()
-{
- return *Trace::dprintf_stream;
-}
+/* namespace Trace */ }
// This silly little class allows us to wrap a string in a functor
// object so that we can give a name() that DPRINTF will like
@@ -186,7 +89,7 @@ inline const std::string &name() { return Trace::DefaultName; }
#define DDUMP(x, data, count) do { \
if (DTRACE(x)) \
- Trace::dataDump(curTick, name(), data, count); \
+ Trace::dump(curTick, name(), data, count); \
} while (0)
#define DPRINTF(x, ...) do { \
@@ -199,6 +102,10 @@ inline const std::string &name() { return Trace::DefaultName; }
Trace::dprintf((Tick)-1, std::string(), __VA_ARGS__); \
} while (0)
+#define DDUMPN(data, count) do { \
+ Trace::dump(curTick, name(), data, count); \
+} while (0)
+
#define DPRINTFN(...) do { \
Trace::dprintf(curTick, name(), __VA_ARGS__); \
} while (0)
@@ -210,11 +117,12 @@ inline const std::string &name() { return Trace::DefaultName; }
#else // !TRACING_ON
#define DTRACE(x) (false)
+#define DDUMP(x, data, count) do {} while (0)
#define DPRINTF(x, ...) do {} while (0)
#define DPRINTFR(...) do {} while (0)
+#define DDUMPN(data, count) do {} while (0)
#define DPRINTFN(...) do {} while (0)
#define DPRINTFNR(...) do {} while (0)
-#define DDUMP(x, data, count) do {} while (0)
#endif // TRACING_ON