diff --git a/main.py b/main.py index e629b30f..a22c6a1f 100755 --- a/main.py +++ b/main.py @@ -216,6 +216,21 @@ class _Repo(object): self._PrintHelp(short=True) return 1 + run = lambda: self._RunLong(name, gopts, argv) or 0 + with Trace('starting new command: %s', ', '.join([name] + argv), + first_trace=True): + if gopts.trace_python: + import trace + tracer = trace.Trace(count=False, trace=True, timing=True, + ignoredirs=set(sys.path[1:])) + result = tracer.runfunc(run) + else: + result = run() + return result + + def _RunLong(self, name, gopts, argv): + """Execute the (longer running) requested subcommand.""" + result = 0 SetDefaultColoring(gopts.color) git_trace2_event_log = EventLog() @@ -663,15 +678,7 @@ def _Main(argv): if gopts.trace_to_stderr: SetTraceToStderr() - with Trace('starting new command: %s', ', '.join([name] + argv), first_trace=True): - run = lambda: repo._Run(name, gopts, argv) or 0 - if gopts.trace_python: - import trace - tracer = trace.Trace(count=False, trace=True, timing=True, - ignoredirs=set(sys.path[1:])) - result = tracer.runfunc(run) - else: - result = run() + result = repo._Run(name, gopts, argv) or 0 except KeyboardInterrupt: print('aborted by user', file=sys.stderr) result = 1 diff --git a/repo_trace.py b/repo_trace.py index 0ff3b694..03542950 100644 --- a/repo_trace.py +++ b/repo_trace.py @@ -119,7 +119,7 @@ def _GetTraceFile(): # TODO: refactor to pass repodir to Trace. repo_dir = os.path.dirname(os.path.dirname(__file__)) trace_file = os.path.join(repo_dir, _TRACE_FILE_NAME) - print('Trace outputs in %s' % trace_file) + print('Trace outputs in %s' % trace_file, file=sys.stderr) return trace_file def _ClearOldTraces():