Skip to content

Commit

Permalink
Fix event log command event hierarchy.
Browse files Browse the repository at this point in the history
command should be cmd_name, to match what git is emitting. This also
fixes arguments, so that only relevant arguments are passed instead
of the entire sys.args, which will contain wrapper information

Change-Id: Id436accfff511292ec2c56798fffb2306dda38fc
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/443741
Commit-Queue: Josip Sokcevic <[email protected]>
Reviewed-by: Gavin Mak <[email protected]>
Tested-by: Josip Sokcevic <[email protected]>
  • Loading branch information
sokcevicG authored and LUCI committed Nov 22, 2024
1 parent b1613d7 commit fafd1ec
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 18 deletions.
10 changes: 6 additions & 4 deletions git_trace2_event_log_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,10 @@ def _CreateEventDict(self, event_name):
"time": datetime.datetime.now(datetime.timezone.utc).isoformat(),
}

def StartEvent(self):
def StartEvent(self, argv):
"""Append a 'start' event to the current log."""
start_event = self._CreateEventDict("start")
start_event["argv"] = sys.argv
start_event["argv"] = argv
self._log.append(start_event)

def ExitEvent(self, result):
Expand All @@ -159,9 +159,11 @@ def CommandEvent(self, name, subcommands):
name: Name of the primary command (ex: repo, git)
subcommands: List of the sub-commands (ex: version, init, sync)
"""
command_event = self._CreateEventDict("command")
command_event = self._CreateEventDict("cmd_name")
name = f"{name}-"
name += "-".join(subcommands)
command_event["name"] = name
command_event["subcommands"] = subcommands
command_event["hierarchy"] = name
self._log.append(command_event)

def LogConfigEvents(self, config, event_dict_name):
Expand Down
2 changes: 1 addition & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ def _RunLong(self, name, gopts, argv, git_trace2_event_log):
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()
git_trace2_event_log.StartEvent(["repo", name] + argv)
git_trace2_event_log.CommandEvent(name="repo", subcommands=[name])

def execute_command_helper():
Expand Down
22 changes: 9 additions & 13 deletions tests/test_git_trace2_event_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def test_start_event(self):
<version event>
<start event>
"""
self._event_log_module.StartEvent()
self._event_log_module.StartEvent([])
with tempfile.TemporaryDirectory(prefix="event_log_tests") as tempdir:
log_path = self._event_log_module.Write(path=tempdir)
self._log_data = self.readLog(log_path)
Expand Down Expand Up @@ -213,10 +213,8 @@ def test_command_event(self):
<version event>
<command event>
"""
name = "repo"
subcommands = ["init" "this"]
self._event_log_module.CommandEvent(
name="repo", subcommands=subcommands
name="repo", subcommands=["init", "this"]
)
with tempfile.TemporaryDirectory(prefix="event_log_tests") as tempdir:
log_path = self._event_log_module.Write(path=tempdir)
Expand All @@ -225,12 +223,10 @@ def test_command_event(self):
self.assertEqual(len(self._log_data), 2)
command_event = self._log_data[1]
self.verifyCommonKeys(self._log_data[0], expected_event_name="version")
self.verifyCommonKeys(command_event, expected_event_name="command")
self.verifyCommonKeys(command_event, expected_event_name="cmd_name")
# Check for 'command' event specific fields.
self.assertIn("name", command_event)
self.assertIn("subcommands", command_event)
self.assertEqual(command_event["name"], name)
self.assertEqual(command_event["subcommands"], subcommands)
self.assertEqual(command_event["name"], "repo-init-this")

def test_def_params_event_repo_config(self):
"""Test 'def_params' event data outputs only repo config keys.
Expand Down Expand Up @@ -382,17 +378,17 @@ def test_write_socket(self):
socket_path = os.path.join(tempdir, "server.sock")
server_ready = threading.Condition()
# Start "server" listening on Unix domain socket at socket_path.
server_thread = threading.Thread(
target=serverLoggingThread,
args=(socket_path, server_ready, received_traces),
)
try:
server_thread = threading.Thread(
target=serverLoggingThread,
args=(socket_path, server_ready, received_traces),
)
server_thread.start()

with server_ready:
server_ready.wait(timeout=120)

self._event_log_module.StartEvent()
self._event_log_module.StartEvent([])
path = self._event_log_module.Write(
path=f"af_unix:{socket_path}"
)
Expand Down

0 comments on commit fafd1ec

Please sign in to comment.