From 7954de13b79182e299163307c430ad96f9cdbd38 Mon Sep 17 00:00:00 2001 From: Raman Tenneti Date: Wed, 28 Jul 2021 14:36:49 -0700 Subject: sync: Added logging of repo sync state and config options for analysis. git_config.py: + Added SyncAnalysisState class, which saves the following data into the config object. ++ sys.argv, options, superproject's logging data. ++ repo.*, branch.* and remote.* parameters from config object. ++ current time as synctime. ++ Version number of the object. + All the keys for the above data are prepended with 'repo.syncstate.' + Added GetSyncAnalysisStateData and UpdateSyncAnalysisState methods to GitConfig object to save/get the above data. git_trace2_event_log.py: + Added LogConfigEvents method with code from DefParamRepoEvents to log events. sync.py: + superproject_logging_data is a dictionary that collects all the superproject data that is to be logged as trace2 event. + Sync at the end logs the previously saved syncstate.* parameters as previous_sync_state. Then it calls config's UpdateSyncAnalysisState to save and log all the current options, superproject logged data. docs/internal-fs-layout.md: + Added doc string explaining [repo.syncstate ...] sections of .repo/manifests.git/config file. test_git_config.py: + Added unit test for the new methods of GitConfig object. Tested: $ ./run_tests $ repo_dev init --use-superproject -u https://android.googlesource.com/platform/manifest Tested it by running the following command multiple times. $ repo_dev sync -j 20 repo sync has finished successfully Verified config file has [syncstate ...] data saved. Bug: [google internal] b/188573450 Change-Id: I1f914ce50f3382111b72940ca56de7c41b53d460 Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/313123 Tested-by: Raman Tenneti Reviewed-by: Mike Frysinger Reviewed-by: Xin Li --- git_trace2_event_log.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'git_trace2_event_log.py') diff --git a/git_trace2_event_log.py b/git_trace2_event_log.py index fae3d4c8..9c9e5a70 100644 --- a/git_trace2_event_log.py +++ b/git_trace2_event_log.py @@ -144,6 +144,19 @@ class EventLog(object): command_event['subcommands'] = subcommands self._log.append(command_event) + def LogConfigEvents(self, config, event_dict_name): + """Append a |event_dict_name| event for each config key in |config|. + + Args: + config: Configuration dictionary. + event_dict_name: Name of the event dictionary for items to be logged under. + """ + for param, value in config.items(): + event = self._CreateEventDict(event_dict_name) + event['param'] = param + event['value'] = value + self._log.append(event) + def DefParamRepoEvents(self, config): """Append a 'def_param' event for each repo.* config key to the current log. @@ -152,12 +165,7 @@ class EventLog(object): """ # Only output the repo.* config parameters. repo_config = {k: v for k, v in config.items() if k.startswith('repo.')} - - for param, value in repo_config.items(): - def_param_event = self._CreateEventDict('def_param') - def_param_event['param'] = param - def_param_event['value'] = value - self._log.append(def_param_event) + self.LogConfigEvents(repo_config, 'def_param') def ErrorEvent(self, msg, fmt): """Append a 'error' event to the current log.""" -- cgit v1.2.3-54-g00ecf