PageRenderTime 25ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/lab/run_trace.py

https://bitbucket.org/ned/coveragepy/
Python | 35 lines | 21 code | 10 blank | 4 comment | 3 complexity | 048d49bdea677fa2534860db090879a3 MD5 | raw file
Possible License(s): Apache-2.0
  1. # Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0
  2. # For details: https://bitbucket.org/ned/coveragepy/src/default/NOTICE.txt
  3. """Run a simple trace function on a file of Python code."""
  4. import os, sys
  5. nest = 0
  6. def trace(frame, event, arg):
  7. global nest
  8. if nest is None:
  9. # This can happen when Python is shutting down.
  10. return None
  11. print "%s%s %s %d @%d" % (
  12. " " * nest,
  13. event,
  14. os.path.basename(frame.f_code.co_filename),
  15. frame.f_lineno,
  16. frame.f_lasti,
  17. )
  18. if event == 'call':
  19. nest += 1
  20. if event == 'return':
  21. nest -= 1
  22. return trace
  23. the_program = sys.argv[1]
  24. sys.settrace(trace)
  25. execfile(the_program)