add in the files to the SConscript for split caches
[gem5.git] / base / trace.cc
index 156110376197560878d432b606229fa1620cdb75..90db7f045c094ae04156f4bdb43d14c28d51d575 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003 The Regents of The University of Michigan
+ * Copyright (c) 2001-2005 The Regents of The University of Michigan
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -51,39 +51,7 @@ FlagVec flags(NumFlags, false);
 //
 ostream *dprintf_stream = &cerr;
 
-int dprintf_ignore_size;
-vector<string> dprintf_ignore;
-vector<vector<string> > ignore_tokens;
-vector<int> ignore_size;
-
-bool
-dprintf_ignore_name(const string &name)
-{
-    vector<string> name_tokens;
-    tokenize(name_tokens, name, '.');
-    int ntsize = name_tokens.size();
-
-    for (int i = 0; i < dprintf_ignore_size; ++i) {
-        bool match = true;
-        int jstop = ignore_size[i];
-        for (int j = 0; j < jstop; ++j) {
-            if (j >= ntsize)
-                break;
-
-            const string &ignore = ignore_tokens[i][j];
-            if (ignore != "*" && ignore != name_tokens[j]) {
-                match = false;
-                break;
-            }
-        }
-
-        if (match == true)
-            return true;
-    }
-
-    return false;
-}
-
+ObjectMatch ignore;
 
 Log theLog;
 
@@ -103,7 +71,7 @@ Log::init(int _size)
 
     size = _size;
 
-    buffer = new (Record *)[size];
+    buffer = new Record *[size];
 
     for (int i = 0; i < size; ++i) {
         buffer[i] = NULL;
@@ -130,6 +98,8 @@ 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);
     }
 
     // no buffering: justget rid of it now
@@ -184,7 +154,6 @@ PrintfRecord::~PrintfRecord()
     delete &args;
 }
 
-
 void
 PrintfRecord::dump(ostream &os)
 {
@@ -206,30 +175,26 @@ PrintfRecord::dump(ostream &os)
     os.flush();
 }
 
-
-
-RawDataRecord::RawDataRecord(Tick _cycle,
-                                    const uint8_t *_data, int _len)
-    : Record(_cycle), len(_len)
+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);
 }
 
-
-RawDataRecord::~RawDataRecord()
+DataRecord::~DataRecord()
 {
     delete [] data;
 }
 
-
 void
-RawDataRecord::dump(ostream &os)
+DataRecord::dump(ostream &os)
 {
     int c, i, j;
 
     for (i = 0; i < len; i += 16) {
-        ccprintf(os, "%08x  ", i);
+        ccprintf(os, "%d: %s: %08x  ", cycle, name, i);
         c = len - i;
         if (c > 16) c = 16;
 
@@ -320,3 +285,66 @@ echoTrace(bool on)
         }
     }
 }
+
+extern "C"
+void
+printTraceFlags()
+{
+    using namespace Trace;
+    for (int i = 0; i < numFlagStrings; ++i)
+        if (flags[i])
+            cprintf("%s\n", flagStrings[i]);
+}
+
+void
+tweakTraceFlag(const char *string, bool value)
+{
+    using namespace Trace;
+    std::string str(string);
+
+    for (int i = 0; i < numFlagStrings; ++i) {
+        if (str != flagStrings[i])
+            continue;
+
+        int idx = i;
+
+        if (idx < NumFlags) {
+            flags[idx] = value;
+        } else {
+            idx -= NumFlags;
+            if (idx >= NumCompoundFlags) {
+                ccprintf(cerr, "Invalid compound flag");
+                return;
+            }
+
+            const Flags *flagVec = compoundFlags[idx];
+
+            for (int j = 0; flagVec[j] != -1; ++j) {
+                if (flagVec[j] >= NumFlags) {
+                    ccprintf(cerr, "Invalid compound flag");
+                    return;
+                }
+                flags[flagVec[j]] = value;
+            }
+        }
+
+        cprintf("flag %s was %s\n", string, value ? "set" : "cleared");
+        return;
+    }
+
+    cprintf("could not find flag %s\n", string);
+}
+
+extern "C"
+void
+setTraceFlag(const char *string)
+{
+    tweakTraceFlag(string, true);
+}
+
+extern "C"
+void
+clearTraceFlag(const char *string)
+{
+    tweakTraceFlag(string, false);
+}