diff options
| author | Ian Kasprzak <iankaz@google.com> | 2020-12-23 10:08:20 -0800 |
|---|---|---|
| committer | Ian Kasprzak <iankaz@google.com> | 2021-01-06 17:49:41 +0000 |
| commit | 30bc354e25cb5ccfbbb276a93ec54195e6b966a4 (patch) | |
| tree | bf4e82ca88ade5a57b2fb1e46a6a8991c84f7b98 /main.py | |
| parent | ce9b6c43b2394f3f8c9413abfa3a10597de54223 (diff) | |
| download | git-repo-30bc354e25cb5ccfbbb276a93ec54195e6b966a4.tar.gz | |
Enable git trace2 event format logging.
Ways to enable logging:
1) Set git's trace2.eventtarget config variable to desired logging path
2) Specify path via --git_trace2_event_log option
A unique logfile name is generated per repo execution (based on the repo session-id).
Testing:
1) Verified git config 'trace2.eventtarget' and flag enable logging.
2) Verified version/start/end events are expected format:
https://git-scm.com/docs/api-trace2#_event_format
3) Unit tests
Bug: https://crbug.com/gerrit/13706
Change-Id: I335eba68124055321c4149979bec36ac16ef81eb
Tested-by: Ian Kasprzak <iankaz@google.com>
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/292262
Reviewed-by: Mike Frysinger <vapier@google.com>
Reviewed-by: Jonathan Nieder <jrn@google.com>
Diffstat (limited to 'main.py')
| -rwxr-xr-x | main.py | 9 |
1 files changed, 9 insertions, 0 deletions
| @@ -50,6 +50,7 @@ import event_log | |||
| 50 | from repo_trace import SetTrace | 50 | from repo_trace import SetTrace |
| 51 | from git_command import user_agent | 51 | from git_command import user_agent |
| 52 | from git_config import init_ssh, close_ssh, RepoConfig | 52 | from git_config import init_ssh, close_ssh, RepoConfig |
| 53 | from git_trace2_event_log import EventLog | ||
| 53 | from command import InteractiveCommand | 54 | from command import InteractiveCommand |
| 54 | from command import MirrorSafeCommand | 55 | from command import MirrorSafeCommand |
| 55 | from command import GitcAvailableCommand, GitcClientCommand | 56 | from command import GitcAvailableCommand, GitcClientCommand |
| @@ -130,6 +131,8 @@ global_options.add_option('--version', | |||
| 130 | global_options.add_option('--event-log', | 131 | global_options.add_option('--event-log', |
| 131 | dest='event_log', action='store', | 132 | dest='event_log', action='store', |
| 132 | help='filename of event log to append timeline to') | 133 | help='filename of event log to append timeline to') |
| 134 | global_options.add_option('--git-trace2-event-log', action='store', | ||
| 135 | help='directory to write git trace2 event log to') | ||
| 133 | 136 | ||
| 134 | 137 | ||
| 135 | class _Repo(object): | 138 | class _Repo(object): |
| @@ -211,6 +214,7 @@ class _Repo(object): | |||
| 211 | file=sys.stderr) | 214 | file=sys.stderr) |
| 212 | return 1 | 215 | return 1 |
| 213 | 216 | ||
| 217 | git_trace2_event_log = EventLog() | ||
| 214 | cmd.repodir = self.repodir | 218 | cmd.repodir = self.repodir |
| 215 | cmd.client = RepoClient(cmd.repodir) | 219 | cmd.client = RepoClient(cmd.repodir) |
| 216 | cmd.manifest = cmd.client.manifest | 220 | cmd.manifest = cmd.client.manifest |
| @@ -261,6 +265,8 @@ class _Repo(object): | |||
| 261 | start = time.time() | 265 | start = time.time() |
| 262 | cmd_event = cmd.event_log.Add(name, event_log.TASK_COMMAND, start) | 266 | cmd_event = cmd.event_log.Add(name, event_log.TASK_COMMAND, start) |
| 263 | cmd.event_log.SetParent(cmd_event) | 267 | cmd.event_log.SetParent(cmd_event) |
| 268 | git_trace2_event_log.StartEvent() | ||
| 269 | |||
| 264 | try: | 270 | try: |
| 265 | cmd.ValidateOptions(copts, cargs) | 271 | cmd.ValidateOptions(copts, cargs) |
| 266 | result = cmd.Execute(copts, cargs) | 272 | result = cmd.Execute(copts, cargs) |
| @@ -303,10 +309,13 @@ class _Repo(object): | |||
| 303 | 309 | ||
| 304 | cmd.event_log.FinishEvent(cmd_event, finish, | 310 | cmd.event_log.FinishEvent(cmd_event, finish, |
| 305 | result is None or result == 0) | 311 | result is None or result == 0) |
| 312 | git_trace2_event_log.ExitEvent(result) | ||
| 313 | |||
| 306 | if gopts.event_log: | 314 | if gopts.event_log: |
| 307 | cmd.event_log.Write(os.path.abspath( | 315 | cmd.event_log.Write(os.path.abspath( |
| 308 | os.path.expanduser(gopts.event_log))) | 316 | os.path.expanduser(gopts.event_log))) |
| 309 | 317 | ||
| 318 | git_trace2_event_log.Write(gopts.git_trace2_event_log) | ||
| 310 | return result | 319 | return result |
| 311 | 320 | ||
| 312 | 321 | ||
