aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAri Hausman-Cohen <arihc@google.com>2015-10-23 10:55:25 -0700
committerAri Hausman-Cohen <arihc@google.com>2015-10-26 15:00:14 -0700
commite7af44c08837fa50eddc1300877f18bce08274ad (patch)
tree6078ba53cb20d9e6879616d3361f1466eb486db0
parent0ef2d11b7a55f484603fdfd92264099b6a4a82df (diff)
downloadbdk-e7af44c08837fa50eddc1300877f18bce08274ad.tar.gz
Moving build metrics into brunch product build.
BUG: 25082075 Change-Id: I596ca1b2b8f0a53be2e793474bd74853e3d537b1
-rw-r--r--brunch/lib/commands/product/build.py30
-rw-r--r--brunch/lib/core/config.py25
2 files changed, 55 insertions, 0 deletions
diff --git a/brunch/lib/commands/product/build.py b/brunch/lib/commands/product/build.py
index 9509b17..cfbba79 100644
--- a/brunch/lib/commands/product/build.py
+++ b/brunch/lib/commands/product/build.py
@@ -18,10 +18,13 @@
import argparse
import os
+import time
from cli import clicommand
from core import config
from core import util
+from metrics.data_types import brillo_ga_hits
+from metrics import send_hits
class Build(clicommand.Command):
"""Build a product project from the current directory"""
@@ -58,15 +61,42 @@ class Build(clicommand.Command):
# Don't pass along the first '--' since it was meant for argparse.
args.make_args.count('--') and args.make_args.remove('--')
+ # If user options haven't been set up yet, do so.
+ # TODO(arihc): move this to install script instead of here.
+ user_store = config.UserStore()
+ if not user_store.complete():
+ user_store.initialize()
+
+ envcmd = 'make'
+ start_time = time.time()
+
if args.submodule == True:
print "Building submodule only . . ."
ret = os.system('make -f %s/tools/bdk/build/wrap-product.mk %s ' \
'HERE="%s" ENVCMD=mm BUILDTYPE=%s %s' %
(sdk_path, no_java, os.getcwd(), args.buildtype,
util.AsShellArgs(args.make_args)))
+ envcmd = 'mm'
else:
# Change to the product path and build the whole product.
ret = os.system('cd %s;make -f %s/tools/bdk/build/wrap-product.mk %s BUILDTYPE=%s %s' %
(args.product_path, sdk_path, no_java, args.buildtype,
util.AsShellArgs(args.make_args)))
+
+ end_time = time.time()
+ build_time = int(end_time - start_time)
+
+ # Determine the envcmd for reporting purposes
+ for arg in args.make_args:
+ split_arg = arg.split('=')
+ if split_arg[0] == 'ENVCMD' and len(split_arg) > 1:
+ envcmd = split_arg[1]
+
+ # TODO(arihc): also check for not --help, since this is what build_time > 0
+ # is primarily checking for, and the wrapper runs lunch first,
+ # making basically all builds > 0 time.
+ if user_store.metrics_opt_in != '0' and ret == 0 and build_time > 0:
+ send_hits.SendHitAndRetries(brillo_ga_hits.BuildTiming(envcmd,
+ build_time))
+
return util.GetExitCode(ret)
diff --git a/brunch/lib/core/config.py b/brunch/lib/core/config.py
index e565ede..123eede 100644
--- a/brunch/lib/core/config.py
+++ b/brunch/lib/core/config.py
@@ -16,6 +16,8 @@
import os
import sqlite3
+import sys
+import uuid
import util
@@ -118,6 +120,29 @@ class UserStore(Store):
def __init__(self, table='user', file_path=util.USER_DB):
super(UserStore, self).__init__(table, file_path)
+ def initialize(self, opt_in=None):
+ """Sets up the user store.
+
+ Prompts the user for information when necessary.
+ """
+ # Check for opt in
+ print ("To help improve the quality of this product, we collect\n"
+ "anonymized data on how the BDK is used. You may choose to opt out\n"
+ "of this collection now (by choosing 'N' at the below prompt),\n"
+ "or at any point in the future by running the following command:\n"
+ " brunch config metrics disable")
+ while opt_in is None:
+ print 'Do you want to help improve the Project Brillo BDK?'
+ print '(Y/n) ',
+ sys.stdout.flush()
+ choice = sys.stdin.readline().strip().upper()
+ if not choice or choice == 'Y':
+ opt_in = True
+ elif choice == 'N':
+ opt_in = False
+ self.metrics_opt_in = opt_in
+
+ self.uid = str(uuid.uuid4())
class ProductStore(Store):
REQUIRED_PROPS = [ 'name', 'device', 'manufacturer', \