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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Chris Manchester 2018-10-31 20:03:56 +00:00
Родитель d730afbefd
Коммит 9b3b733a84
4 изменённых файлов: 31 добавлений и 14 удалений

Просмотреть файл

@ -235,7 +235,8 @@ def bootstrap(topsrcdir, mozilla_dir=None):
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.
@ -249,7 +250,24 @@ def bootstrap(topsrcdir, mozilla_dir=None):
if not context.settings.build.telemetry:
return
# Every n-th operation
from mozbuild.telemetry import gather_telemetry
from mozbuild.base import MozbuildObject
if not isinstance(instance, MozbuildObject):
instance = MozbuildObject.from_environment()
try:
substs = instance.substs
except Exception:
substs = {}
# We gather telemetry for every operation...
gather_telemetry(command=handler.name, success=(result == 0),
start_time=start_time, end_time=end_time,
mach_context=context, substs=substs,
paths=[instance.topsrcdir, instance.topobjdir])
# But only submit about every n-th operation
if random.randint(1, TELEMETRY_SUBMISSION_FREQUENCY) != 1:
return

Просмотреть файл

@ -5,6 +5,7 @@
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
@ -83,19 +84,24 @@ class MachRegistrar(object):
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

Просмотреть файл

@ -56,9 +56,6 @@ from ..compilation.warnings import (
from ..shellutil import (
quote as shell_quote,
)
from ..telemetry import (
gather_telemetry,
)
from ..util import (
FileAvoidWrite,
mkdir,
@ -1285,10 +1282,6 @@ class BuildDriver(MozbuildObject):
# Display a notification when the build completes.
self.notify('Build complete' if not status else 'Build failed')
gather_telemetry(command='build', success=(status == 0), monitor=monitor,
mach_context=mach_context, substs=self.substs,
paths=[self.topsrcdir, self.topobjdir])
if status:
return status

Просмотреть файл

@ -239,8 +239,8 @@ def filter_args(command, argv, paths):
return [filter_path(arg) for arg in args]
def gather_telemetry(command='', success=False, monitor=None, mach_context=None, substs={},
paths=[]):
def gather_telemetry(command='', success=False, start_time=None, end_time=None,
mach_context=None, substs={}, paths=[]):
'''
Gather telemetry about the build and the user's system and pass it to the telemetry
handler to be stored for later submission.
@ -251,12 +251,12 @@ def gather_telemetry(command='', success=False, monitor=None, mach_context=None,
data = {
'client_id': get_client_id(mach_context.state_dir),
# Simplest way to get an rfc3339 datetime string, AFAICT.
'time': datetime.utcfromtimestamp(monitor.start_time).isoformat(b'T') + 'Z',
'time': datetime.utcfromtimestamp(start_time).isoformat(b'T') + 'Z',
'command': command,
'argv': filter_args(command, sys.argv, paths),
'success': success,
# TODO: use a monotonic clock: https://bugzilla.mozilla.org/show_bug.cgi?id=1481624
'duration_ms': int(monitor.elapsed * 1000),
'duration_ms': int((end_time - start_time) * 1000),
'build_opts': get_build_opts(substs),
'system': get_system_info(),
# TODO: exception: https://bugzilla.mozilla.org/show_bug.cgi?id=1481617