Browse Source

metrics: Collect full timestamps.

Update metrics.README.md and add a metrics_version field.

Bug: None
Change-Id: I17d9032bd787af2a6fc49f80d59e05152d5223b7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/1406256
Reviewed-by: Andy Perelson <ajp@chromium.org>
Reviewed-by: Edward Lesmes <ehmaldonado@chromium.org>
Commit-Queue: Edward Lesmes <ehmaldonado@chromium.org>
Edward Lemur 6 years ago
parent
commit
18df41e0cf
4 changed files with 9 additions and 16 deletions
  1. 3 3
      metrics.README.md
  2. 2 1
      metrics.py
  3. 1 11
      metrics_utils.py
  4. 3 1
      tests/metrics_test.py

+ 3 - 3
metrics.README.md

@@ -34,8 +34,8 @@ First, some words about what data we are **NOT** collecting:
 
 
 The metrics we're collecting are:
 The metrics we're collecting are:
 
 
-- A timestamp, with a week resolution.
-- The age of your depot\_tools checkout, with a week resolution.
+- The time when the command was run.
+- The age of your depot\_tools checkout.
 - Your version of Python (in the format major.minor.micro).
 - Your version of Python (in the format major.minor.micro).
 - Your version of Git (in the format major.minor.micro).
 - Your version of Git (in the format major.minor.micro).
 - The OS of your machine (i.e. win, linux or mac).
 - The OS of your machine (i.e. win, linux or mac).
@@ -47,7 +47,7 @@ The metrics we're collecting are:
 - The exit code.
 - The exit code.
 - The project you're working on. We only record data about projects you can
 - The project you're working on. We only record data about projects you can
   fetch using depot\_tools' fetch command (e.g. Chromium, WebRTC, V8, etc)
   fetch using depot\_tools' fetch command (e.g. Chromium, WebRTC, V8, etc)
-- The age of your project checkout, with a week resolution.
+- The age of your project checkout.
 - What features are you using in your DEPS and .gclient files. For example:
 - What features are you using in your DEPS and .gclient files. For example:
   - Are you setting `use_relative_paths=True`?
   - Are you setting `use_relative_paths=True`?
   - Are you using `recursedeps`?
   - Are you using `recursedeps`?

+ 2 - 1
metrics.py

@@ -198,6 +198,7 @@ class MetricsCollector(object):
         return func(*args, **kwargs)
         return func(*args, **kwargs)
 
 
     self._collecting_metrics = True
     self._collecting_metrics = True
+    self.add('metrics_version', metrics_utils.CURRENT_VERSION)
     self.add('command', command_name)
     self.add('command', command_name)
     try:
     try:
       start = time.time()
       start = time.time()
@@ -213,7 +214,7 @@ class MetricsCollector(object):
     self.add('exit_code', exit_code)
     self.add('exit_code', exit_code)
 
 
     # Add metrics regarding environment information.
     # Add metrics regarding environment information.
-    self.add('timestamp', metrics_utils.seconds_to_weeks(time.time()))
+    self.add('timestamp', time.time())
     self.add('python_version', metrics_utils.get_python_version())
     self.add('python_version', metrics_utils.get_python_version())
     self.add('host_os', gclient_utils.GetMacWinOrLinux())
     self.add('host_os', gclient_utils.GetMacWinOrLinux())
     self.add('host_arch', detect_host_arch.HostArch())
     self.add('host_arch', detect_host_arch.HostArch())

+ 1 - 11
metrics_utils.py

@@ -183,15 +183,6 @@ def return_code_from_exception(exception):
   return 1
   return 1
 
 
 
 
-def seconds_to_weeks(duration):
-  """Transform a |duration| from seconds to weeks approximately.
-
-  Drops the lowest 19 bits of the integer representation, which ammounts to
-  about 6 days.
-  """
-  return int(duration) >> 19
-
-
 def extract_known_subcommand_args(args):
 def extract_known_subcommand_args(args):
   """Extract the known arguments from the passed list of args."""
   """Extract the known arguments from the passed list of args."""
   known_args = []
   known_args = []
@@ -276,8 +267,7 @@ def get_repo_timestamp(path_to_repo):
   if p.returncode != 0:
   if p.returncode != 0:
     return None
     return None
 
 
-  # Get the age of the checkout in weeks.
-  return seconds_to_weeks(stdout.strip())
+  return stdout.strip()
 
 
 def print_boxed_text(out, min_width, lines):
 def print_boxed_text(out, min_width, lines):
   [EW, NS, SE, SW, NE, NW] = list('=|++++')
   [EW, NS, SE, SW, NE, NW] = list('=|++++')

+ 3 - 1
tests/metrics_test.py

@@ -68,11 +68,13 @@ class MetricsCollectorTest(unittest.TestCase):
     mock.patch('metrics_utils.get_git_version',
     mock.patch('metrics_utils.get_git_version',
                lambda: '2.18.1').start()
                lambda: '2.18.1').start()
 
 
+    self.maxDiff = None
     self.default_metrics = {
     self.default_metrics = {
+        "metrics_version": 0,
         "python_version": "2.7.13",
         "python_version": "2.7.13",
         "git_version": "2.18.1",
         "git_version": "2.18.1",
         "execution_time": 1000,
         "execution_time": 1000,
-        "timestamp": 0,
+        "timestamp": 3000,
         "exit_code": 0,
         "exit_code": 0,
         "command": "fun",
         "command": "fun",
         "depot_tools_age": 1234,
         "depot_tools_age": 1234,