Get rid of the Trace ParamContext and give python direct
access to enabling/disabling tracing. Command line is unchanged except for the removal of --trace-cycle since it's not so clear what that means. --HG-- extra : convert_revision : c0164d92d3615d76d0c6acaabaafd92a9278212a
This commit is contained in:
@@ -133,6 +133,7 @@ base_sources = Split('''
|
||||
python/swig/debug_wrap.cc
|
||||
python/swig/main_wrap.cc
|
||||
python/swig/event_wrap.cc
|
||||
python/swig/trace_wrap.cc
|
||||
python/swig/pyevent.cc
|
||||
|
||||
sim/builder.cc
|
||||
@@ -149,7 +150,7 @@ base_sources = Split('''
|
||||
sim/stat_context.cc
|
||||
sim/stat_control.cc
|
||||
sim/system.cc
|
||||
sim/trace_context.cc
|
||||
sim/trace_control.cc
|
||||
''')
|
||||
|
||||
trace_reader_sources = Split('''
|
||||
|
||||
@@ -46,6 +46,7 @@ using namespace std;
|
||||
namespace Trace {
|
||||
const string DefaultName("global");
|
||||
FlagVec flags(NumFlags, false);
|
||||
bool enabled = true;
|
||||
|
||||
//
|
||||
// This variable holds the output stream for debug information. Other
|
||||
@@ -223,125 +224,3 @@ DataRecord::dump(ostream &os)
|
||||
}
|
||||
}
|
||||
} // namespace Trace
|
||||
|
||||
//
|
||||
// Returns the current output stream for debug information. As a
|
||||
// wrapper around Trace::dprintf_stream, this handles cases where debug
|
||||
// information is generated in the process of parsing .ini options,
|
||||
// before we process the option that sets up the debug output stream
|
||||
// itself.
|
||||
//
|
||||
std::ostream &
|
||||
DebugOut()
|
||||
{
|
||||
return *Trace::dprintf_stream;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////
|
||||
//
|
||||
// C-linkage functions for invoking from gdb
|
||||
//
|
||||
/////////////////////////////////////////////
|
||||
|
||||
//
|
||||
// Dump trace buffer to specified file (cout if NULL)
|
||||
//
|
||||
void
|
||||
dumpTrace(const char *filename)
|
||||
{
|
||||
if (filename != NULL) {
|
||||
ofstream out(filename);
|
||||
Trace::theLog.dump(out);
|
||||
out.close();
|
||||
}
|
||||
else {
|
||||
Trace::theLog.dump(cout);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Turn on/off trace output to cerr. Typically used when trace output
|
||||
// is only going to circular buffer, but you want to see what's being
|
||||
// sent there as you step through some code in gdb. This uses the
|
||||
// same facility as the "trace to file" feature, and will print error
|
||||
// messages rather than clobbering an existing ostream pointer.
|
||||
//
|
||||
void
|
||||
echoTrace(bool on)
|
||||
{
|
||||
if (on) {
|
||||
if (Trace::dprintf_stream != NULL) {
|
||||
cerr << "Already echoing trace to a file... go do a 'tail -f'"
|
||||
<< " on that file instead." << endl;
|
||||
} else {
|
||||
Trace::dprintf_stream = &cerr;
|
||||
}
|
||||
} else {
|
||||
if (Trace::dprintf_stream != &cerr) {
|
||||
cerr << "Not echoing trace to cerr." << endl;
|
||||
} else {
|
||||
Trace::dprintf_stream = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
void
|
||||
setTraceFlag(const char *string)
|
||||
{
|
||||
tweakTraceFlag(string, true);
|
||||
}
|
||||
|
||||
void
|
||||
clearTraceFlag(const char *string)
|
||||
{
|
||||
tweakTraceFlag(string, false);
|
||||
}
|
||||
|
||||
@@ -47,19 +47,16 @@ namespace Trace {
|
||||
|
||||
extern FlagVec flags;
|
||||
|
||||
#if TRACING_ON
|
||||
const bool On = true;
|
||||
#else
|
||||
const bool On = false;
|
||||
#endif
|
||||
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
|
||||
@@ -156,7 +153,11 @@ namespace Trace {
|
||||
|
||||
};
|
||||
|
||||
std::ostream &DebugOut();
|
||||
inline std::ostream &
|
||||
DebugOut()
|
||||
{
|
||||
return *Trace::dprintf_stream;
|
||||
}
|
||||
|
||||
// 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
|
||||
@@ -181,7 +182,7 @@ inline const std::string &name() { return Trace::DefaultName; }
|
||||
|
||||
#if TRACING_ON
|
||||
|
||||
#define DTRACE(x) (Trace::IsOn(Trace::x))
|
||||
#define DTRACE(x) (Trace::IsOn(Trace::x) && Trace::enabled)
|
||||
|
||||
#define DDUMP(x, data, count) do { \
|
||||
if (DTRACE(x)) \
|
||||
|
||||
@@ -108,6 +108,7 @@ def swig_it(basename):
|
||||
swig_it('main')
|
||||
swig_it('debug')
|
||||
swig_it('event')
|
||||
swig_it('trace')
|
||||
|
||||
# Action function to build the zip archive. Uses the PyZipFile module
|
||||
# included in the standard Python library.
|
||||
|
||||
@@ -30,11 +30,6 @@ import code, optparse, os, socket, sys
|
||||
from datetime import datetime
|
||||
from attrdict import attrdict
|
||||
|
||||
try:
|
||||
import info
|
||||
except ImportError:
|
||||
info = None
|
||||
|
||||
__all__ = [ 'options', 'arguments', 'main' ]
|
||||
|
||||
usage="%prog [m5 options] script.py [script options]"
|
||||
@@ -144,8 +139,6 @@ add_option("--trace-flags", metavar="FLAG[,FLAG]", action='append', split=',',
|
||||
help="Sets the flags for tracing")
|
||||
add_option("--trace-start", metavar="TIME", default='0s',
|
||||
help="Start tracing at TIME (must have units)")
|
||||
add_option("--trace-cycle", metavar="CYCLE", default='0',
|
||||
help="Start tracing at CYCLE")
|
||||
add_option("--trace-file", metavar="FILE", default="cout",
|
||||
help="Sets the output file for tracing [Default: %default]")
|
||||
add_option("--trace-circlebuf", metavar="SIZE", type="int", default=0,
|
||||
@@ -211,6 +204,8 @@ def parse_args():
|
||||
return opts,args
|
||||
|
||||
def main():
|
||||
import defines
|
||||
import info
|
||||
import internal
|
||||
|
||||
parse_args()
|
||||
@@ -278,14 +273,26 @@ def main():
|
||||
for when in options.debug_break:
|
||||
internal.debug.schedBreakCycle(int(when))
|
||||
|
||||
# set tracing options
|
||||
objects.Trace.flags = options.trace_flags
|
||||
objects.Trace.start = options.trace_start
|
||||
objects.Trace.cycle = options.trace_cycle
|
||||
objects.Trace.file = options.trace_file
|
||||
objects.Trace.bufsize = options.trace_circlebuf
|
||||
objects.Trace.dump_on_exit = options.trace_dumponexit
|
||||
objects.Trace.ignore = options.trace_ignore
|
||||
for flag in options.trace_flags:
|
||||
internal.trace.setFlag(flag)
|
||||
|
||||
if options.trace_start is not None:
|
||||
internal.trace.enabled = False
|
||||
def enable_trace():
|
||||
internal.event.enabled = True
|
||||
internal.event.create(enable_trace, options.trace_start)
|
||||
|
||||
if options.trace_file is not None:
|
||||
internal.trace.file(options.trace_file)
|
||||
|
||||
if options.trace_bufsize is not None:
|
||||
internal.trace.buffer_size(options.bufsize)
|
||||
|
||||
#if options.trace_dumponexit:
|
||||
# internal.trace.dumpOnExit = True
|
||||
|
||||
for ignore in options.trace_ignore:
|
||||
internal.trace.ignore(ignore)
|
||||
|
||||
# set execution trace options
|
||||
objects.ExecutionTrace.speculative = options.speculative
|
||||
@@ -309,7 +316,7 @@ def main():
|
||||
|
||||
# we want readline if we're doing anything interactive
|
||||
if options.interactive or options.pdb:
|
||||
exec("import readline", scope)
|
||||
exec "import readline" in scope
|
||||
|
||||
# if pdb was requested, execfile the thing under pdb, otherwise,
|
||||
# just do the execfile normally
|
||||
|
||||
@@ -3,7 +3,6 @@ from m5.params import *
|
||||
from Serialize import Serialize
|
||||
from Serialize import Statreset
|
||||
from Statistics import Statistics
|
||||
from Trace import Trace
|
||||
from ExeTrace import ExecutionTrace
|
||||
|
||||
class Root(SimObject):
|
||||
@@ -15,9 +14,7 @@ class Root(SimObject):
|
||||
output_file = Param.String('cout', "file to dump simulator output to")
|
||||
checkpoint = Param.String('', "checkpoint file to load")
|
||||
# stats = Param.Statistics(Statistics(), "statistics object")
|
||||
# trace = Param.Trace(Trace(), "trace object")
|
||||
# serialize = Param.Serialize(Serialize(), "checkpoint generation options")
|
||||
stats = Statistics()
|
||||
trace = Trace()
|
||||
exetrace = ExecutionTrace()
|
||||
serialize = Serialize()
|
||||
|
||||
85
src/python/swig/trace.i
Normal file
85
src/python/swig/trace.i
Normal file
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* Copyright (c) 2006 The Regents of The University of Michigan
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met: redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer;
|
||||
* redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution;
|
||||
* neither the name of the copyright holders nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* Authors: Nathan Binkert
|
||||
*/
|
||||
|
||||
%module trace
|
||||
|
||||
%{
|
||||
#include "base/trace.hh"
|
||||
#include "sim/host.hh"
|
||||
#include "sim/trace_control.hh"
|
||||
|
||||
inline void
|
||||
set(const char *flag)
|
||||
{
|
||||
setTraceFlag(flag);
|
||||
}
|
||||
|
||||
inline void
|
||||
clear(const char *flag)
|
||||
{
|
||||
clearTraceFlag(flag);
|
||||
}
|
||||
|
||||
inline void
|
||||
ignore(const char *expr)
|
||||
{
|
||||
Trace::ignore.setExpression(expr);
|
||||
}
|
||||
|
||||
inline void
|
||||
buffer_size(int num_lines)
|
||||
{
|
||||
if ((int)num_lines > 0)
|
||||
Trace::theLog.init(num_lines);
|
||||
}
|
||||
|
||||
inline void
|
||||
dump(const char *filename)
|
||||
{
|
||||
dumpTrace(filename);
|
||||
}
|
||||
|
||||
using Trace::enabled;
|
||||
%}
|
||||
|
||||
%inline %{
|
||||
extern void ignore(const char *expr);
|
||||
extern void set(const char *string);
|
||||
extern void clear(const char *string);
|
||||
extern void buffer_size(int num_lines);
|
||||
extern void dump(const char *filename);
|
||||
extern bool enabled;
|
||||
%}
|
||||
|
||||
%wrapper %{
|
||||
// fix up module name to reflect the fact that it's inside the m5 package
|
||||
#undef SWIG_name
|
||||
#define SWIG_name "m5.internal._trace"
|
||||
%}
|
||||
Reference in New Issue
Block a user