summaryrefslogtreecommitdiff
path: root/lab/run_trace.py
diff options
context:
space:
mode:
Diffstat (limited to 'lab/run_trace.py')
-rw-r--r--lab/run_trace.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/lab/run_trace.py b/lab/run_trace.py
new file mode 100644
index 00000000..ea0a6cb7
--- /dev/null
+++ b/lab/run_trace.py
@@ -0,0 +1,35 @@
+# Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0
+# For details: https://bitbucket.org/ned/coveragepy/src/default/NOTICE.txt
+
+"""Run a simple trace function on a file of Python code."""
+
+import os, sys
+
+nest = 0
+
+def trace(frame, event, arg):
+ global nest
+
+ if nest is None:
+ # This can happen when Python is shutting down.
+ return None
+
+ print "%s%s %s %d @%d" % (
+ " " * nest,
+ event,
+ os.path.basename(frame.f_code.co_filename),
+ frame.f_lineno,
+ frame.f_lasti,
+ )
+
+ if event == 'call':
+ nest += 1
+ if event == 'return':
+ nest -= 1
+
+ return trace
+
+the_program = sys.argv[1]
+
+sys.settrace(trace)
+execfile(the_program)