# HG changeset patch # User Chris Manchester # Date 1541016236 0 # Node ID b42fc1ea86f31b66547e101e9407a1cdfdfa6464 # Parent 3d5dd552a434bf277c1239f986f9d901f75b050f Bug 1497638 - Gather telemetry for mach commands other than build. r=ted,firefox-build-system-reviewers,nalexander Differential Revision: https://phabricator.services.mozilla.com/D10177 diff --git a/build/mach_bootstrap.py b/build/mach_bootstrap.py --- a/build/mach_bootstrap.py +++ b/build/mach_bootstrap.py @@ -198,17 +198,18 @@ def bootstrap(topsrcdir, mozilla_dir=Non return True # The environment is likely a machine invocation. if sys.stdin.closed or not sys.stdin.isatty(): return True return False - def post_dispatch_handler(context, handler, args): + def post_dispatch_handler(context, handler, instance, result, + start_time, end_time, args): """Perform global operations after command dispatch. """ # Don't do anything when... if should_skip_dispatch(context, handler): return # We call mach environment in client.mk which would cause the diff --git a/python/mach/mach/registrar.py b/python/mach/mach/registrar.py --- a/python/mach/mach/registrar.py +++ b/python/mach/mach/registrar.py @@ -1,15 +1,16 @@ # This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. from __future__ import absolute_import, unicode_literals from .base import MachError +import time INVALID_COMMAND_CONTEXT = r''' It looks like you tried to run a mach command from an invalid context. The %s command failed to meet the following conditions: %s Run |mach help| to show a list of all commands available to the current context. '''.lstrip() @@ -78,29 +79,34 @@ class MachRegistrar(object): fail_conditions.append(c) if fail_conditions: print(self._condition_failed_message(handler.name, fail_conditions)) return 1 fn = getattr(instance, handler.method) + start_time = time.time() + if debug_command: import pdb result = pdb.runcall(fn, **kwargs) else: result = fn(**kwargs) + end_time = time.time() + result = result or 0 assert isinstance(result, (int, long)) if context and not debug_command: postrun = getattr(context, 'post_dispatch_handler', None) if postrun: - postrun(context, handler, args=kwargs) + postrun(context, handler, instance, result, + start_time, end_time, args=kwargs) return result def dispatch(self, name, context=None, argv=None, subcommand=None, **kwargs): """Dispatch/run a command. Commands can use this to call other commands. """