Will Bradley | 88b1ffc | 2019-08-19 15:09:39 -0600 | [diff] [blame] | 1 | # -*- coding: utf-8 -*- |
| 2 | # Copyright 2019 The Chromium OS Authors. All rights reserved. |
| 3 | # Use of this source code is governed by a BSD-style license that can be |
| 4 | # found in the LICENSE file. |
| 5 | |
| 6 | """The build API Metrics Emit entry point.""" |
| 7 | |
| 8 | from __future__ import print_function |
| 9 | |
| 10 | from chromite.lib import commandline |
| 11 | from chromite.utils import metrics |
| 12 | |
| 13 | |
| 14 | def main(argv): |
| 15 | """Emit a metric event.""" |
| 16 | parser = commandline.ArgumentParser(description=__doc__) |
| 17 | parser.add_argument('op', choices=metrics.VALID_OPS, |
| 18 | help='Which metric event operator to emit.') |
| 19 | parser.add_argument('name', |
| 20 | help='The name of the metric event as you would like it ' |
| 21 | 'to appear downstream in data stores.') |
| 22 | parser.add_argument('key', nargs='?', |
| 23 | help='A unique key for this invocation to ensure that ' |
| 24 | 'start and stop timers can be matched.') |
| 25 | opts = parser.parse_args(argv) |
| 26 | |
| 27 | timestamp = metrics.current_milli_time() |
| 28 | key = opts.key or opts.name |
| 29 | metrics.append_metrics_log(timestamp, opts.name, opts.op, key=key) |