tracing: panic() if people try to use tracing, but TRACING_ON is not set.
authorNathan Binkert <nate@binkert.org>
Mon, 19 Jan 2009 17:59:13 +0000 (09:59 -0800)
committerNathan Binkert <nate@binkert.org>
Mon, 19 Jan 2009 17:59:13 +0000 (09:59 -0800)
Also clean things up so that help strings can more easily be added.
Move the help function into trace.py

src/SConscript
src/python/SConscript
src/python/m5/main.py
src/python/m5/trace.py [new file with mode: 0644]

index fed0355cfc5bd7f806b2c7e4d36fb1f6bb8465c2..5ba89381d1eb03ffd1847fac35be4090fac43d14 100644 (file)
@@ -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')
 
index 94119c77d5e0b6132f6590f57ef3698feebc710c..726254c1dfa38870766c29bd32d3f6b4879e059f 100644 (file)
@@ -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')
index 4853c89080f57d1ba4dfea2fa486b51de3187770..4e97147058a21d8b0a38db9cffb6e1441756809d 100644 (file)
@@ -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 (file)
index 0000000..9e2351d
--- /dev/null
@@ -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