aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Fung <stevefung@google.com>2016-04-21 00:04:01 -0700
committerSteve Fung <stevefung@google.com>2016-04-21 00:04:01 -0700
commite643f7567cf7af79086711110b607f7608dd28fb (patch)
tree378962a7edb26b13cdb51c00dd55e1e6cd905666
parentaa9237ae7ff032eae67a2b1cf01bb8bfc5be8ff3 (diff)
downloadbdk-e643f7567cf7af79086711110b607f7608dd28fb.tar.gz
Add command type to metrics
In order to make Bdk metrics more useful, send the command type in all hits. Bug: 28054708 Change-Id: Ib2d0b68a61e790d4c58af221562a76d9214c8d49
-rw-r--r--cli/lib/cli/climanager.py2
-rw-r--r--cli/lib/metrics/metrics_util.py16
2 files changed, 18 insertions, 0 deletions
diff --git a/cli/lib/cli/climanager.py b/cli/lib/cli/climanager.py
index ca072b6..d350bcb 100644
--- a/cli/lib/cli/climanager.py
+++ b/cli/lib/cli/climanager.py
@@ -24,6 +24,7 @@ import textwrap
from cli import clicommand
from cli import importutils
import error
+from metrics import metrics_util
class Error(error.Error):
@@ -256,6 +257,7 @@ class Cli(object):
"""
self.args = self._ParseArgs(args)
command = self.args.command_type()
+ metrics_util.set_command_type(command)
result = command.RunWithMetrics(self.args)
# Enforce the return type with a useful message.
diff --git a/cli/lib/metrics/metrics_util.py b/cli/lib/metrics/metrics_util.py
index cb96a60..23a3f55 100644
--- a/cli/lib/metrics/metrics_util.py
+++ b/cli/lib/metrics/metrics_util.py
@@ -46,6 +46,7 @@ _BRILLO_CD_CPU_SPEED = 4
_BRILLO_CD_RAM = 5
_BRILLO_CD_BDK = 6
_BRILLO_CD_RESULT = 7
+_BRILLO_CD_TYPE = 8
_BRILLO_PROTOCOL_VERSION = 1
@@ -100,6 +101,7 @@ def get_custom_dimensions(result=None):
cds[_BRILLO_CD_CPU_SPEED] = _get_cpu_speed()
cds[_BRILLO_CD_RAM] = _get_ram()
cds[_BRILLO_CD_BDK] = util.GetBDKVersion()
+ cds[_BRILLO_CD_TYPE] = _MetricsUtilState.get_command_type()
if result is not None:
cds[_BRILLO_CD_RESULT] = result
return cds
@@ -191,6 +193,11 @@ def send_retries():
send_hit_fields(hit_fields)
+def set_command_type(command_type):
+ """Set the command type for any metrics being sent."""
+ _MetricsUtilState.set_command_type(command_type)
+
+
class _MetricsUtilState(object):
"""Metrics utility State.
@@ -200,6 +207,7 @@ class _MetricsUtilState(object):
user_store = user_config.USER_CONFIG
initialized = False
+ _command_type = ''
@classmethod
def initialize(cls):
@@ -207,3 +215,11 @@ class _MetricsUtilState(object):
if not cls.user_store.complete():
cls.user_store.initialize()
cls.initialized = True
+
+ @classmethod
+ def get_command_type(cls):
+ return cls._command_type
+
+ @classmethod
+ def set_command_type(cls, command_type):
+ cls._command_type = command_type.parser.prog