From: Nathan Binkert Date: Mon, 19 Jan 2009 17:59:13 +0000 (-0800) Subject: tracing: panic() if people try to use tracing, but TRACING_ON is not set. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=0876c822dd25e57e8811ceb31f67a3536c9855b0;p=gem5.git tracing: panic() if people try to use tracing, but TRACING_ON is not set. Also clean things up so that help strings can more easily be added. Move the help function into trace.py --- diff --git a/src/SConscript b/src/SConscript index fed0355cf..5ba89381d 100644 --- a/src/SConscript +++ b/src/SConscript @@ -175,30 +175,25 @@ Export('UnitTest') # # Trace Flags # -all_flags = {} -trace_flags = [] -def TraceFlag(name, desc=''): - if name in all_flags: +trace_flags = {} +def TraceFlag(name, desc=None): + if name in trace_flags: raise AttributeError, "Flag %s already specified" % name - flag = (name, (), desc) - trace_flags.append(flag) - all_flags[name] = () + trace_flags[name] = (name, (), desc) -def CompoundFlag(name, flags, desc=''): - if name in all_flags: +def CompoundFlag(name, flags, desc=None): + if name in trace_flags: raise AttributeError, "Flag %s already specified" % name compound = tuple(flags) for flag in compound: - if flag not in all_flags: + if flag not in trace_flags: raise AttributeError, "Trace flag %s not found" % flag - if all_flags[flag]: + if trace_flags[flag][1]: raise AttributeError, \ "Compound flag can't point to another compound flag" - flag = (name, compound, desc) - trace_flags.append(flag) - all_flags[name] = compound + trace_flags[name] = (name, compound, desc) Export('TraceFlag') Export('CompoundFlag') @@ -666,14 +661,16 @@ def traceFlagsPy(target, source, env): val = eval(s.get_contents()) allFlags.append(val) - print >>f, 'baseFlags = [' + allFlags.sort() + + print >>f, 'basic = [' for flag, compound, desc in allFlags: if not compound: print >>f, " '%s'," % flag print >>f, " ]" print >>f - print >>f, 'compoundFlags = [' + print >>f, 'compound = [' print >>f, " 'All'," for flag, compound, desc in allFlags: if compound: @@ -681,10 +678,10 @@ def traceFlagsPy(target, source, env): print >>f, " ]" print >>f - print >>f, "allFlags = frozenset(baseFlags + compoundFlags)" + print >>f, "all = frozenset(basic + compound)" print >>f - print >>f, 'compoundFlagMap = {' + print >>f, 'compoundMap = {' all = tuple([flag for flag,compound,desc in allFlags if not compound]) print >>f, " 'All' : %s," % (all, ) for flag, compound, desc in allFlags: @@ -693,7 +690,7 @@ def traceFlagsPy(target, source, env): print >>f, " }" print >>f - print >>f, 'flagDescriptions = {' + print >>f, 'descriptions = {' print >>f, " 'All' : 'All flags'," for flag, compound, desc in allFlags: print >>f, " '%s' : '%s'," % (flag, desc) @@ -847,7 +844,7 @@ extern const Flags *compoundFlags[]; f.close() -flags = [ Value(f) for f in trace_flags ] +flags = [ Value(f) for f in trace_flags.values() ] env.Command('base/traceflags.py', flags, traceFlagsPy) PySource('m5', 'base/traceflags.py') diff --git a/src/python/SConscript b/src/python/SConscript index 94119c77d..726254c1d 100644 --- a/src/python/SConscript +++ b/src/python/SConscript @@ -48,6 +48,7 @@ PySource('m5', 'm5/simulate.py') PySource('m5', 'm5/smartdict.py') PySource('m5', 'm5/stats.py') PySource('m5', 'm5/ticks.py') +PySource('m5', 'm5/trace.py') PySource('m5.util', 'm5/util/__init__.py') PySource('m5.util', 'm5/util/attrdict.py') PySource('m5.util', 'm5/util/jobfile.py') diff --git a/src/python/m5/main.py b/src/python/m5/main.py index 4853c8908..4e9714705 100644 --- a/src/python/m5/main.py +++ b/src/python/m5/main.py @@ -138,6 +138,13 @@ def main(): import event import info import internal + import trace + + def check_tracing(): + if defines.TRACING_ON: + return + + panic("Tracing is not enabled. Compile with TRACING_ON") # load the options.py config file to allow people to set their own # default options @@ -221,21 +228,9 @@ def main(): print if options.trace_help: - import traceflags - done = True - print "Base Flags:" - traceflags.baseFlags.sort() - print_list(traceflags.baseFlags, indent=4) - print - print "Compound Flags:" - traceflags.compoundFlags.sort() - for flag in traceflags.compoundFlags: - if flag == 'All': - continue - print " %s:" % flag - print_list(traceflags.compoundFlagMap[flag], indent=8) - print + check_tracing() + trace.help() if options.list_sim_objects: import SimObject @@ -306,7 +301,7 @@ def main(): internal.debug.schedBreakCycle(int(when)) if options.trace_flags: - import traceflags + check_tracing() on_flags = [] off_flags = [] @@ -315,7 +310,7 @@ def main(): if flag.startswith('-'): flag = flag[1:] off = True - if flag not in traceflags.allFlags and flag != "All": + if flag not in trace.flags.all and flag != "All": print >>sys.stderr, "invalid trace flag '%s'" % flag sys.exit(1) @@ -325,24 +320,23 @@ def main(): on_flags.append(flag) for flag in on_flags: - internal.trace.set(flag) + trace.set(flag) for flag in off_flags: - internal.trace.clear(flag) + trace.clear(flag) if options.trace_start: - def enable_trace(): - internal.trace.cvar.enabled = True - - e = event.create(enable_trace) + check_tracing() + e = event.create(trace.enable) event.mainq.schedule(e, options.trace_start) else: - internal.trace.cvar.enabled = True + trace.enable() - internal.trace.output(options.trace_file) + trace.output(options.trace_file) for ignore in options.trace_ignore: - internal.trace.ignore(ignore) + check_tracing() + trace.ignore(ignore) sys.argv = arguments sys.path = [ os.path.dirname(sys.argv[0]) ] + sys.path diff --git a/src/python/m5/trace.py b/src/python/m5/trace.py new file mode 100644 index 000000000..9e2351dbe --- /dev/null +++ b/src/python/m5/trace.py @@ -0,0 +1,20 @@ +import internal +import traceflags as flags + +from internal.trace import clear, output, set, ignore + +def enable(): + internal.trace.cvar.enabled = True + +def help(): + print "Base Flags:" + for flag in trace.flags.basic: + print " %s: %s" % (flag, trace.flags.descriptions[flag]) + print + print "Compound Flags:" + for flag in trace.flags.compound: + if flag == 'All': + continue + print " %s: %s" % (flag, trace.flags.descriptions[flag]) + print_list(trace.flags.compoundMap[flag], indent=8) + print