From 30bc354e25cb5ccfbbb276a93ec54195e6b966a4 Mon Sep 17 00:00:00 2001 From: Ian Kasprzak Date: Wed, 23 Dec 2020 10:08:20 -0800 Subject: 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 Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/292262 Reviewed-by: Mike Frysinger Reviewed-by: Jonathan Nieder --- main.py | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'main.py') diff --git a/main.py b/main.py index e152de4f..a7c3c684 100755 --- a/main.py +++ b/main.py @@ -50,6 +50,7 @@ import event_log from repo_trace import SetTrace from git_command import user_agent from git_config import init_ssh, close_ssh, RepoConfig +from git_trace2_event_log import EventLog from command import InteractiveCommand from command import MirrorSafeCommand from command import GitcAvailableCommand, GitcClientCommand @@ -130,6 +131,8 @@ global_options.add_option('--version', global_options.add_option('--event-log', dest='event_log', action='store', help='filename of event log to append timeline to') +global_options.add_option('--git-trace2-event-log', action='store', + help='directory to write git trace2 event log to') class _Repo(object): @@ -211,6 +214,7 @@ class _Repo(object): file=sys.stderr) return 1 + git_trace2_event_log = EventLog() cmd.repodir = self.repodir cmd.client = RepoClient(cmd.repodir) cmd.manifest = cmd.client.manifest @@ -261,6 +265,8 @@ class _Repo(object): start = time.time() cmd_event = cmd.event_log.Add(name, event_log.TASK_COMMAND, start) cmd.event_log.SetParent(cmd_event) + git_trace2_event_log.StartEvent() + try: cmd.ValidateOptions(copts, cargs) result = cmd.Execute(copts, cargs) @@ -303,10 +309,13 @@ class _Repo(object): cmd.event_log.FinishEvent(cmd_event, finish, result is None or result == 0) + git_trace2_event_log.ExitEvent(result) + if gopts.event_log: cmd.event_log.Write(os.path.abspath( os.path.expanduser(gopts.event_log))) + git_trace2_event_log.Write(gopts.git_trace2_event_log) return result -- cgit v1.2.3-54-g00ecf