def _collect_metrics(self, func, command_name, *args, **kwargs): self.add('command', command_name) try: start = time.time() func(*args, **kwargs) exception = None # pylint: disable=bare-except except: exception = sys.exc_info() finally: self.add('execution_time', time.time() - start) # Print the exception before the metrics notice, so that the notice is # clearly visible even if gclient fails. if exception and not isinstance(exception[1], SystemExit): traceback.print_exception(*exception) exit_code = metrics_utils.return_code_from_exception(exception) self.add('exit_code', exit_code) # Print the metrics notice only if the user has not explicitly opted in # or out. if self.config.opted_in is None: metrics_utils.print_notice(self.config.countdown) # Add metrics regarding environment information. self.add('timestamp', metrics_utils.seconds_to_weeks(time.time())) self.add('python_version', metrics_utils.get_python_version()) self.add('host_os', gclient_utils.GetMacWinOrLinux()) self.add('host_arch', detect_host_arch.HostArch()) self.add('depot_tools_age', metrics_utils.get_repo_timestamp(DEPOT_TOOLS)) self._upload_metrics_data() sys.exit(exit_code)
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
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 # splitted 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('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', metrics_utils.seconds_to_weeks(time.time())) self.add('python_version', metrics_utils.get_python_version()) self.add('host_os', gclient_utils.GetMacWinOrLinux()) self.add('host_arch', detect_host_arch.HostArch()) self.add('depot_tools_age', metrics_utils.get_repo_timestamp(DEPOT_TOOLS)) self._upload_metrics_data() if exception: raise exception[0], exception[1], exception[2] return result