| 388 | return _find_lines(code, strs) |
| 389 | |
| 390 | class Trace: |
| 391 | def __init__(self, count=1, trace=1, countfuncs=0, countcallers=0, |
| 392 | ignoremods=(), ignoredirs=(), infile=None, outfile=None, |
| 393 | timing=False): |
| 394 | """ |
| 395 | @param count true iff it should count number of times each |
| 396 | line is executed |
| 397 | @param trace true iff it should print out each line that is |
| 398 | being counted |
| 399 | @param countfuncs true iff it should just output a list of |
| 400 | (filename, modulename, funcname,) for functions |
| 401 | that were called at least once; This overrides |
| 402 | 'count' and 'trace' |
| 403 | @param ignoremods a list of the names of modules to ignore |
| 404 | @param ignoredirs a list of the names of directories to ignore |
| 405 | all of the (recursive) contents of |
| 406 | @param infile file from which to read stored counts to be |
| 407 | added into the results |
| 408 | @param outfile file in which to write the results |
| 409 | @param timing true iff timing information be displayed |
| 410 | """ |
| 411 | self.infile = infile |
| 412 | self.outfile = outfile |
| 413 | self.ignore = _Ignore(ignoremods, ignoredirs) |
| 414 | self.counts = {} # keys are (filename, linenumber) |
| 415 | self.pathtobasename = {} # for memoizing os.path.basename |
| 416 | self.donothing = 0 |
| 417 | self.trace = trace |
| 418 | self._calledfuncs = {} |
| 419 | self._callers = {} |
| 420 | self._caller_cache = {} |
| 421 | self.start_time = None |
| 422 | if timing: |
| 423 | self.start_time = _time() |
| 424 | if countcallers: |
| 425 | self.globaltrace = self.globaltrace_trackcallers |
| 426 | elif countfuncs: |
| 427 | self.globaltrace = self.globaltrace_countfuncs |
| 428 | elif trace and count: |
| 429 | self.globaltrace = self.globaltrace_lt |
| 430 | self.localtrace = self.localtrace_trace_and_count |
| 431 | elif trace: |
| 432 | self.globaltrace = self.globaltrace_lt |
| 433 | self.localtrace = self.localtrace_trace |
| 434 | elif count: |
| 435 | self.globaltrace = self.globaltrace_lt |
| 436 | self.localtrace = self.localtrace_count |
| 437 | else: |
| 438 | # Ahem -- do nothing? Okay. |
| 439 | self.donothing = 1 |
| 440 | |
| 441 | def run(self, cmd): |
| 442 | import __main__ |
| 443 | dict = __main__.__dict__ |
| 444 | self.runctx(cmd, dict, dict) |
| 445 | |
| 446 | def runctx(self, cmd, globals=None, locals=None): |
| 447 | if globals is None: globals = {} |
no outgoing calls
searching dependent graphs…