Skip to content

Commit

Permalink
Bug 1497638 - Gather telemetry for mach commands other than build. r=…
Browse files Browse the repository at this point in the history
…ted,firefox-build-system-reviewers,nalexander

Differential Revision: https://phabricator.services.mozilla.com/D10177

--HG--
extra : moz-landing-system : lando
  • Loading branch information
chmanchester committed Oct 31, 2018
1 parent d730afb commit 9b3b733
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 14 deletions.
22 changes: 20 additions & 2 deletions build/mach_bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,8 @@ def should_skip_dispatch(context, handler):

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.
Expand All @@ -249,7 +250,24 @@ def post_dispatch_handler(context, handler, args):
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

Expand Down
8 changes: 7 additions & 1 deletion python/mach/mach/registrar.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -83,19 +84,24 @@ def _run_command_handler(self, handler, context=None, debug_command=False, **kwa

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

Expand Down
7 changes: 0 additions & 7 deletions python/mozbuild/mozbuild/controller/building.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,6 @@
from ..shellutil import (
quote as shell_quote,
)
from ..telemetry import (
gather_telemetry,
)
from ..util import (
FileAvoidWrite,
mkdir,
Expand Down Expand Up @@ -1285,10 +1282,6 @@ def backend_out_of_date(backend_file):
# 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

Expand Down
8 changes: 4 additions & 4 deletions python/mozbuild/mozbuild/telemetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,8 @@ def filter_path(p):
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.
Expand All @@ -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
Expand Down

0 comments on commit 9b3b733

Please sign in to comment.