blob: 2a2ae0822cec36ab6fcec663e6ded1e9d707dd2b [file] [log] [blame]
Kevin Cheng6001db32018-10-23 12:34:20 -07001# Copyright 2018 - The Android Open Source Project
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14r"""Acloud metrics functions."""
15
16import logging
Kevin Cheng6001db32018-10-23 12:34:20 -070017
18from acloud.internal import constants
Kevin Cheng6001db32018-10-23 12:34:20 -070019
20logger = logging.getLogger(__name__)
21
Sam Chiud09787a2019-07-08 20:45:07 +080022# pylint: disable=broad-except, import-error
Sam Chiue791f602019-05-03 15:18:10 +080023def LogUsage(argv):
24 """Log acloud start event.
Kevin Cheng6001db32018-10-23 12:34:20 -070025
Sam Chiue791f602019-05-03 15:18:10 +080026 Log acloud start event and the usage, following are the data we log:
27 - tool_name: All asuite tools are storing event in the same database. This
28 property is provided to distinguish different tools.
29 - command_line: Log all command arguments.
30 - test_references: Should be a list, we record the acloud sub-command.
31 e.g. create/delete/reconnect/..etc. We could use this property as filter
32 criteria to speed up query time.
33 - cwd: User's current working directory.
34 - os: The platform that users are working at.
35
36 Args:
37 argv: A list of system arguments.
38 """
Sam Chiue791f602019-05-03 15:18:10 +080039 try:
40 from asuite import atest_utils
41 from asuite.metrics import metrics_utils
42 atest_utils.print_data_collection_notice()
43 metrics_utils.send_start_event(tool_name=constants.TOOL_NAME,
44 command_line=' '.join(argv),
45 test_references=[argv[0]])
46 except Exception as e:
47 logger.debug("Failed to send start event:%s", str(e))
Kevin Cheng6001db32018-10-23 12:34:20 -070048
49
Sam Chiue791f602019-05-03 15:18:10 +080050# pylint: disable=broad-except
51def LogExitEvent(exit_code, stacktrace="", logs=""):
52 """Log acloud exit event.
53
54 A start event should followed by an exit event to calculate the consuming
55 time. This function will be run at the end of acloud main process or
56 at the init of the error object.
57
58 Args:
59 exit_code: Integer, the exit code of acloud main process.
60 stacktrace: A string of stacktrace.
61 logs: A string of logs.
62 """
63 try:
64 from asuite.metrics import metrics_utils
65 metrics_utils.send_exit_event(exit_code, stacktrace=stacktrace,
66 logs=logs)
67 except Exception as e:
68 logger.debug("Failed to send exit event:%s", str(e))