1#!/usr/bin/env python3 2# Copyright 2018 - The Android Open Source Project 3# 4# Licensed under the Apache License, Version 2.0 (the "License"); 5# you may not use this file except in compliance with the License. 6# You may obtain a copy of the License at 7# 8# http://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, 12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13# See the License for the specific language governing permissions and 14# limitations under the License. 15 16"""AIDEgen metrics functions.""" 17 18import logging 19import os 20import platform 21import sys 22 23from aidegen import constant 24from atest import atest_utils 25 26try: 27 from asuite.metrics import metrics 28 from asuite.metrics import metrics_base 29 from asuite.metrics import metrics_utils 30except ImportError: 31 logging.debug('Import metrics fail, can\'t send metrics') 32 metrics = None 33 metrics_base = None 34 metrics_utils = None 35 36 37def starts_asuite_metrics(references=None): 38 """Starts to record metrics data. 39 40 Send a metrics data to log server at the same time. 41 42 Args: 43 references: a list of reference data, when importing whole Android 44 it contains 'is_android_tree'. 45 """ 46 if not metrics: 47 return 48 atest_utils.print_data_collection_notice() 49 metrics_base.MetricsBase.tool_name = constant.AIDEGEN_TOOL_NAME 50 metrics_utils.get_start_time() 51 command = ' '.join(sys.argv) 52 metrics.AtestStartEvent( 53 command_line=command, 54 test_references=references, 55 cwd=os.getcwd(), 56 os=platform.platform()) 57 58 59def ends_asuite_metrics(exit_code, stacktrace='', logs=''): 60 """Send the end event to log server. 61 62 Args: 63 exit_code: An integer of exit code. 64 stacktrace: A string of stacktrace. 65 logs: A string of logs. 66 """ 67 if not metrics_utils: 68 return 69 metrics_utils.send_exit_event( 70 exit_code, 71 stacktrace=stacktrace, 72 logs=logs) 73