def test_get_git_version_unrecognized(self, mockPopen): """Tests that we can get the git version.""" mockProcess = mock.Mock() mockProcess.communicate.side_effect = [('Blah blah blah', 'blah blah')] mockPopen.side_effect = [mockProcess] self.assertIsNone(metrics_utils.get_git_version())
def test_get_git_version(self, mockPopen): """Tests that we can get the git version.""" mockProcess = mock.Mock() mockProcess.communicate.side_effect = [(b'git version 2.18.0.123.foo', '')] mockPopen.side_effect = [mockProcess] self.assertEqual('2.18.0', metrics_utils.get_git_version())
def _collect_metrics(self, func, command_name, *args, **kwargs): # If we're already collecting metrics, just execute the function. # e.g. git-cl split invokes git-cl upload several times to upload each # split CL. if self.collecting_metrics: # Don't collect metrics for this function. # e.g. Don't record the arguments git-cl split passes to git-cl upload. with self.pause_metrics_collection(): return func(*args, **kwargs) self._collecting_metrics = True self.add('metrics_version', metrics_utils.CURRENT_VERSION) self.add('command', command_name) try: start = time.time() result = func(*args, **kwargs) exception = None # pylint: disable=bare-except except: exception = sys.exc_info() finally: self.add('execution_time', time.time() - start) exit_code = metrics_utils.return_code_from_exception(exception) self.add('exit_code', exit_code) # Add metrics regarding environment information. self.add('timestamp', int(time.time())) self.add('python_version', metrics_utils.get_python_version()) self.add('host_os', gclient_utils.GetMacWinAixOrLinux()) self.add('host_arch', detect_host_arch.HostArch()) depot_tools_age = metrics_utils.get_repo_timestamp(DEPOT_TOOLS) if depot_tools_age is not None: self.add('depot_tools_age', int(depot_tools_age)) git_version = metrics_utils.get_git_version() if git_version: self.add('git_version', git_version) bot_metrics = metrics_utils.get_bot_metrics() if bot_metrics: self.add('bot_metrics', bot_metrics) self._upload_metrics_data() if exception: gclient_utils.reraise(exception[0], exception[1], exception[2]) return result