diff options
| author | LaMont Jones <lamontjones@google.com> | 2022-11-07 23:19:14 +0000 |
|---|---|---|
| committer | LaMont Jones <lamontjones@google.com> | 2022-11-08 19:54:20 +0000 |
| commit | a3ff64cae54fca4738f49668c4ee6678969000c3 (patch) | |
| tree | e38240ccf36f9bf3af250df57e7dc248a125c6b0 | |
| parent | 776138a93898491739352f9d599fa048e943d6b6 (diff) | |
| download | git-repo-a3ff64cae54fca4738f49668c4ee6678969000c3.tar.gz | |
Improve always-on-trace
Notes to the user need to go to stderr, and tracing should not be on for
fast exiting invocations (such as --help).
This makes it so that release/update-manpages works.
Change-Id: Ib183193c868a78c295a184c01c4532cd53d512eb
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/350794
Tested-by: LaMont Jones <lamontjones@google.com>
Reviewed-by: Xin Li <delphij@google.com>
| -rwxr-xr-x | main.py | 25 | ||||
| -rw-r--r-- | repo_trace.py | 2 |
2 files changed, 17 insertions, 10 deletions
| @@ -216,6 +216,21 @@ class _Repo(object): | |||
| 216 | self._PrintHelp(short=True) | 216 | self._PrintHelp(short=True) |
| 217 | return 1 | 217 | return 1 |
| 218 | 218 | ||
| 219 | run = lambda: self._RunLong(name, gopts, argv) or 0 | ||
| 220 | with Trace('starting new command: %s', ', '.join([name] + argv), | ||
| 221 | first_trace=True): | ||
| 222 | if gopts.trace_python: | ||
| 223 | import trace | ||
| 224 | tracer = trace.Trace(count=False, trace=True, timing=True, | ||
| 225 | ignoredirs=set(sys.path[1:])) | ||
| 226 | result = tracer.runfunc(run) | ||
| 227 | else: | ||
| 228 | result = run() | ||
| 229 | return result | ||
| 230 | |||
| 231 | def _RunLong(self, name, gopts, argv): | ||
| 232 | """Execute the (longer running) requested subcommand.""" | ||
| 233 | result = 0 | ||
| 219 | SetDefaultColoring(gopts.color) | 234 | SetDefaultColoring(gopts.color) |
| 220 | 235 | ||
| 221 | git_trace2_event_log = EventLog() | 236 | git_trace2_event_log = EventLog() |
| @@ -663,15 +678,7 @@ def _Main(argv): | |||
| 663 | if gopts.trace_to_stderr: | 678 | if gopts.trace_to_stderr: |
| 664 | SetTraceToStderr() | 679 | SetTraceToStderr() |
| 665 | 680 | ||
| 666 | with Trace('starting new command: %s', ', '.join([name] + argv), first_trace=True): | 681 | result = repo._Run(name, gopts, argv) or 0 |
| 667 | run = lambda: repo._Run(name, gopts, argv) or 0 | ||
| 668 | if gopts.trace_python: | ||
| 669 | import trace | ||
| 670 | tracer = trace.Trace(count=False, trace=True, timing=True, | ||
| 671 | ignoredirs=set(sys.path[1:])) | ||
| 672 | result = tracer.runfunc(run) | ||
| 673 | else: | ||
| 674 | result = run() | ||
| 675 | except KeyboardInterrupt: | 682 | except KeyboardInterrupt: |
| 676 | print('aborted by user', file=sys.stderr) | 683 | print('aborted by user', file=sys.stderr) |
| 677 | result = 1 | 684 | 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(): | |||
| 119 | # TODO: refactor to pass repodir to Trace. | 119 | # TODO: refactor to pass repodir to Trace. |
| 120 | repo_dir = os.path.dirname(os.path.dirname(__file__)) | 120 | repo_dir = os.path.dirname(os.path.dirname(__file__)) |
| 121 | trace_file = os.path.join(repo_dir, _TRACE_FILE_NAME) | 121 | trace_file = os.path.join(repo_dir, _TRACE_FILE_NAME) |
| 122 | print('Trace outputs in %s' % trace_file) | 122 | print('Trace outputs in %s' % trace_file, file=sys.stderr) |
| 123 | return trace_file | 123 | return trace_file |
| 124 | 124 | ||
| 125 | def _ClearOldTraces(): | 125 | def _ClearOldTraces(): |
