From 18df41e0cf48746aed7db65a862a7c279d30e801 Mon Sep 17 00:00:00 2001 From: Edward Lemur Date: Fri, 26 Apr 2019 00:42:04 +0000 Subject: [PATCH] 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 Reviewed-by: Edward Lesmes Commit-Queue: Edward Lesmes --- metrics.README.md | 6 +++--- metrics.py | 3 ++- metrics_utils.py | 12 +----------- tests/metrics_test.py | 4 +++- 4 files changed, 9 insertions(+), 16 deletions(-) diff --git a/metrics.README.md b/metrics.README.md index 8b7ed58dd..9cc1db122 100644 --- a/metrics.README.md +++ b/metrics.README.md @@ -34,8 +34,8 @@ First, some words about what data we are **NOT** collecting: 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 Git (in the format major.minor.micro). - 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 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) -- 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: - Are you setting `use_relative_paths=True`? - Are you using `recursedeps`? diff --git a/metrics.py b/metrics.py index 00d6e6d5b..937dbcd43 100644 --- a/metrics.py +++ b/metrics.py @@ -198,6 +198,7 @@ class MetricsCollector(object): return func(*args, **kwargs) self._collecting_metrics = True + self.add('metrics_version', metrics_utils.CURRENT_VERSION) self.add('command', command_name) try: start = time.time() @@ -213,7 +214,7 @@ class MetricsCollector(object): self.add('exit_code', exit_code) # 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('host_os', gclient_utils.GetMacWinOrLinux()) self.add('host_arch', detect_host_arch.HostArch()) diff --git a/metrics_utils.py b/metrics_utils.py index 5df124a74..2235a7fd7 100644 --- a/metrics_utils.py +++ b/metrics_utils.py @@ -183,15 +183,6 @@ def return_code_from_exception(exception): 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): """Extract the known arguments from the passed list of args.""" known_args = [] @@ -276,8 +267,7 @@ def get_repo_timestamp(path_to_repo): if p.returncode != 0: 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): [EW, NS, SE, SW, NE, NW] = list('=|++++') diff --git a/tests/metrics_test.py b/tests/metrics_test.py index b2e9fd605..37c884835 100644 --- a/tests/metrics_test.py +++ b/tests/metrics_test.py @@ -68,11 +68,13 @@ class MetricsCollectorTest(unittest.TestCase): mock.patch('metrics_utils.get_git_version', lambda: '2.18.1').start() + self.maxDiff = None self.default_metrics = { + "metrics_version": 0, "python_version": "2.7.13", "git_version": "2.18.1", "execution_time": 1000, - "timestamp": 0, + "timestamp": 3000, "exit_code": 0, "command": "fun", "depot_tools_age": 1234,