1*c2e18aaaSAndroid Build Coastguard Worker# Copyright 2018, The Android Open Source Project 2*c2e18aaaSAndroid Build Coastguard Worker# 3*c2e18aaaSAndroid Build Coastguard Worker# Licensed under the Apache License, Version 2.0 (the "License"); 4*c2e18aaaSAndroid Build Coastguard Worker# you may not use this file except in compliance with the License. 5*c2e18aaaSAndroid Build Coastguard Worker# You may obtain a copy of the License at 6*c2e18aaaSAndroid Build Coastguard Worker# 7*c2e18aaaSAndroid Build Coastguard Worker# http://www.apache.org/licenses/LICENSE-2.0 8*c2e18aaaSAndroid Build Coastguard Worker# 9*c2e18aaaSAndroid Build Coastguard Worker# Unless required by applicable law or agreed to in writing, software 10*c2e18aaaSAndroid Build Coastguard Worker# distributed under the License is distributed on an "AS IS" BASIS, 11*c2e18aaaSAndroid Build Coastguard Worker# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12*c2e18aaaSAndroid Build Coastguard Worker# See the License for the specific language governing permissions and 13*c2e18aaaSAndroid Build Coastguard Worker# limitations under the License. 14*c2e18aaaSAndroid Build Coastguard Worker 15*c2e18aaaSAndroid Build Coastguard Worker"""Metrics class.""" 16*c2e18aaaSAndroid Build Coastguard Workerfrom atest import constants 17*c2e18aaaSAndroid Build Coastguard Workerfrom atest.metrics import metrics_base 18*c2e18aaaSAndroid Build Coastguard Worker 19*c2e18aaaSAndroid Build Coastguard Worker 20*c2e18aaaSAndroid Build Coastguard Workerclass AtestStartEvent(metrics_base.MetricsBase): 21*c2e18aaaSAndroid Build Coastguard Worker """Create Atest start event and send to clearcut. 22*c2e18aaaSAndroid Build Coastguard Worker 23*c2e18aaaSAndroid Build Coastguard Worker Usage: 24*c2e18aaaSAndroid Build Coastguard Worker metrics.AtestStartEvent( 25*c2e18aaaSAndroid Build Coastguard Worker command_line='example_atest_command', 26*c2e18aaaSAndroid Build Coastguard Worker test_references=['example_test_reference'], 27*c2e18aaaSAndroid Build Coastguard Worker cwd='example/working/dir', 28*c2e18aaaSAndroid Build Coastguard Worker os='example_os') 29*c2e18aaaSAndroid Build Coastguard Worker """ 30*c2e18aaaSAndroid Build Coastguard Worker 31*c2e18aaaSAndroid Build Coastguard Worker _EVENT_NAME = 'atest_start_event' 32*c2e18aaaSAndroid Build Coastguard Worker command_line = constants.INTERNAL 33*c2e18aaaSAndroid Build Coastguard Worker test_references = constants.INTERNAL 34*c2e18aaaSAndroid Build Coastguard Worker cwd = constants.INTERNAL 35*c2e18aaaSAndroid Build Coastguard Worker os = constants.INTERNAL 36*c2e18aaaSAndroid Build Coastguard Worker source_root = constants.INTERNAL 37*c2e18aaaSAndroid Build Coastguard Worker hostname = constants.INTERNAL 38*c2e18aaaSAndroid Build Coastguard Worker 39*c2e18aaaSAndroid Build Coastguard Worker 40*c2e18aaaSAndroid Build Coastguard Workerclass AtestExitEvent(metrics_base.MetricsBase): 41*c2e18aaaSAndroid Build Coastguard Worker """Create Atest exit event and send to clearcut. 42*c2e18aaaSAndroid Build Coastguard Worker 43*c2e18aaaSAndroid Build Coastguard Worker Usage: 44*c2e18aaaSAndroid Build Coastguard Worker metrics.AtestExitEvent( 45*c2e18aaaSAndroid Build Coastguard Worker duration=metrics_utils.convert_duration(end-start), 46*c2e18aaaSAndroid Build Coastguard Worker exit_code=0, 47*c2e18aaaSAndroid Build Coastguard Worker stacktrace='some_trace', 48*c2e18aaaSAndroid Build Coastguard Worker logs='some_logs') 49*c2e18aaaSAndroid Build Coastguard Worker """ 50*c2e18aaaSAndroid Build Coastguard Worker 51*c2e18aaaSAndroid Build Coastguard Worker _EVENT_NAME = 'atest_exit_event' 52*c2e18aaaSAndroid Build Coastguard Worker duration = constants.EXTERNAL 53*c2e18aaaSAndroid Build Coastguard Worker exit_code = constants.EXTERNAL 54*c2e18aaaSAndroid Build Coastguard Worker stacktrace = constants.INTERNAL 55*c2e18aaaSAndroid Build Coastguard Worker logs = constants.INTERNAL 56*c2e18aaaSAndroid Build Coastguard Worker 57*c2e18aaaSAndroid Build Coastguard Worker 58*c2e18aaaSAndroid Build Coastguard Workerclass FindTestFinishEvent(metrics_base.MetricsBase): 59*c2e18aaaSAndroid Build Coastguard Worker """Create find test finish event and send to clearcut. 60*c2e18aaaSAndroid Build Coastguard Worker 61*c2e18aaaSAndroid Build Coastguard Worker Occurs after a SINGLE test reference has been resolved to a test or 62*c2e18aaaSAndroid Build Coastguard Worker not found. 63*c2e18aaaSAndroid Build Coastguard Worker 64*c2e18aaaSAndroid Build Coastguard Worker Usage: 65*c2e18aaaSAndroid Build Coastguard Worker metrics.FindTestFinishEvent( 66*c2e18aaaSAndroid Build Coastguard Worker duration=metrics_utils.convert_duration(end-start), 67*c2e18aaaSAndroid Build Coastguard Worker success=true, 68*c2e18aaaSAndroid Build Coastguard Worker test_reference='hello_world_test', 69*c2e18aaaSAndroid Build Coastguard Worker test_finders=['example_test_reference', 'ref2'], 70*c2e18aaaSAndroid Build Coastguard Worker test_info="test_name: hello_world_test - 71*c2e18aaaSAndroid Build Coastguard Worker test_runner:AtestTradefedTestRunner - 72*c2e18aaaSAndroid Build Coastguard Worker build_targets: 73*c2e18aaaSAndroid Build Coastguard Worker set(['MODULES-IN-platform_testing-tests-example-native']) - 74*c2e18aaaSAndroid Build Coastguard Worker data:{'rel_config': 75*c2e18aaaSAndroid Build Coastguard Worker 'platform_testing/tests/example/native/AndroidTest.xml', 76*c2e18aaaSAndroid Build Coastguard Worker 'filter': frozenset([])} - 77*c2e18aaaSAndroid Build Coastguard Worker suite:None - module_class: ['NATIVE_TESTS'] - 78*c2e18aaaSAndroid Build Coastguard Worker install_locations:set(['device', 'host'])") 79*c2e18aaaSAndroid Build Coastguard Worker """ 80*c2e18aaaSAndroid Build Coastguard Worker 81*c2e18aaaSAndroid Build Coastguard Worker _EVENT_NAME = 'find_test_finish_event' 82*c2e18aaaSAndroid Build Coastguard Worker duration = constants.EXTERNAL 83*c2e18aaaSAndroid Build Coastguard Worker success = constants.EXTERNAL 84*c2e18aaaSAndroid Build Coastguard Worker test_reference = constants.INTERNAL 85*c2e18aaaSAndroid Build Coastguard Worker test_finders = constants.INTERNAL 86*c2e18aaaSAndroid Build Coastguard Worker test_info = constants.INTERNAL 87*c2e18aaaSAndroid Build Coastguard Worker 88*c2e18aaaSAndroid Build Coastguard Worker 89*c2e18aaaSAndroid Build Coastguard Workerclass BuildFinishEvent(metrics_base.MetricsBase): 90*c2e18aaaSAndroid Build Coastguard Worker """Create build finish event and send to clearcut. 91*c2e18aaaSAndroid Build Coastguard Worker 92*c2e18aaaSAndroid Build Coastguard Worker Occurs after the build finishes, either successfully or not. 93*c2e18aaaSAndroid Build Coastguard Worker 94*c2e18aaaSAndroid Build Coastguard Worker Usage: 95*c2e18aaaSAndroid Build Coastguard Worker metrics.BuildFinishEvent( 96*c2e18aaaSAndroid Build Coastguard Worker duration=metrics_utils.convert_duration(end-start), 97*c2e18aaaSAndroid Build Coastguard Worker success=true, 98*c2e18aaaSAndroid Build Coastguard Worker targets=['target1', 'target2']) 99*c2e18aaaSAndroid Build Coastguard Worker """ 100*c2e18aaaSAndroid Build Coastguard Worker 101*c2e18aaaSAndroid Build Coastguard Worker _EVENT_NAME = 'build_finish_event' 102*c2e18aaaSAndroid Build Coastguard Worker duration = constants.EXTERNAL 103*c2e18aaaSAndroid Build Coastguard Worker success = constants.EXTERNAL 104*c2e18aaaSAndroid Build Coastguard Worker targets = constants.INTERNAL 105*c2e18aaaSAndroid Build Coastguard Worker 106*c2e18aaaSAndroid Build Coastguard Worker 107*c2e18aaaSAndroid Build Coastguard Workerclass RunnerFinishEvent(metrics_base.MetricsBase): 108*c2e18aaaSAndroid Build Coastguard Worker """Create run finish event and send to clearcut. 109*c2e18aaaSAndroid Build Coastguard Worker 110*c2e18aaaSAndroid Build Coastguard Worker Occurs when a single test runner has completed. 111*c2e18aaaSAndroid Build Coastguard Worker 112*c2e18aaaSAndroid Build Coastguard Worker Usage: 113*c2e18aaaSAndroid Build Coastguard Worker metrics.RunnerFinishEvent( 114*c2e18aaaSAndroid Build Coastguard Worker duration=metrics_utils.convert_duration(end-start), 115*c2e18aaaSAndroid Build Coastguard Worker success=true, 116*c2e18aaaSAndroid Build Coastguard Worker runner_name='AtestTradefedTestRunner' 117*c2e18aaaSAndroid Build Coastguard Worker test=[{name:'hello_world_test', result:0, stacktrace:''}, 118*c2e18aaaSAndroid Build Coastguard Worker {name:'test2', result:1, stacktrace:'xxx'}]) 119*c2e18aaaSAndroid Build Coastguard Worker """ 120*c2e18aaaSAndroid Build Coastguard Worker 121*c2e18aaaSAndroid Build Coastguard Worker _EVENT_NAME = 'runner_finish_event' 122*c2e18aaaSAndroid Build Coastguard Worker duration = constants.EXTERNAL 123*c2e18aaaSAndroid Build Coastguard Worker success = constants.EXTERNAL 124*c2e18aaaSAndroid Build Coastguard Worker runner_name = constants.EXTERNAL 125*c2e18aaaSAndroid Build Coastguard Worker test = constants.INTERNAL 126*c2e18aaaSAndroid Build Coastguard Worker 127*c2e18aaaSAndroid Build Coastguard Worker 128*c2e18aaaSAndroid Build Coastguard Workerclass RunTestsFinishEvent(metrics_base.MetricsBase): 129*c2e18aaaSAndroid Build Coastguard Worker """Create run tests finish event and send to clearcut. 130*c2e18aaaSAndroid Build Coastguard Worker 131*c2e18aaaSAndroid Build Coastguard Worker Occurs after all test runners and tests have finished. 132*c2e18aaaSAndroid Build Coastguard Worker 133*c2e18aaaSAndroid Build Coastguard Worker Usage: 134*c2e18aaaSAndroid Build Coastguard Worker metrics.RunTestsFinishEvent( 135*c2e18aaaSAndroid Build Coastguard Worker duration=metrics_utils.convert_duration(end-start)) 136*c2e18aaaSAndroid Build Coastguard Worker """ 137*c2e18aaaSAndroid Build Coastguard Worker 138*c2e18aaaSAndroid Build Coastguard Worker _EVENT_NAME = 'run_tests_finish_event' 139*c2e18aaaSAndroid Build Coastguard Worker duration = constants.EXTERNAL 140*c2e18aaaSAndroid Build Coastguard Worker 141*c2e18aaaSAndroid Build Coastguard Worker 142*c2e18aaaSAndroid Build Coastguard Workerclass LocalDetectEvent(metrics_base.MetricsBase): 143*c2e18aaaSAndroid Build Coastguard Worker """Create local detection event and send it to clearcut. 144*c2e18aaaSAndroid Build Coastguard Worker 145*c2e18aaaSAndroid Build Coastguard Worker Usage: 146*c2e18aaaSAndroid Build Coastguard Worker metrics.LocalDetectEvent( 147*c2e18aaaSAndroid Build Coastguard Worker detect_type=0, 148*c2e18aaaSAndroid Build Coastguard Worker result=0) 149*c2e18aaaSAndroid Build Coastguard Worker detect_type: a value from atest_enum.DetectType. 150*c2e18aaaSAndroid Build Coastguard Worker result: the value corresponding to the result of the detected event. 151*c2e18aaaSAndroid Build Coastguard Worker """ 152*c2e18aaaSAndroid Build Coastguard Worker 153*c2e18aaaSAndroid Build Coastguard Worker _EVENT_NAME = 'local_detect_event' 154*c2e18aaaSAndroid Build Coastguard Worker detect_type = constants.EXTERNAL 155*c2e18aaaSAndroid Build Coastguard Worker result = constants.EXTERNAL 156*c2e18aaaSAndroid Build Coastguard Worker 157*c2e18aaaSAndroid Build Coastguard Worker 158*c2e18aaaSAndroid Build Coastguard Workerdef get_run_id() -> str: 159*c2e18aaaSAndroid Build Coastguard Worker """Returns the unique run id set for the current invocation.""" 160*c2e18aaaSAndroid Build Coastguard Worker return metrics_base.MetricsBase.get_run_id() 161*c2e18aaaSAndroid Build Coastguard Worker 162*c2e18aaaSAndroid Build Coastguard Worker 163*c2e18aaaSAndroid Build Coastguard Workerdef is_internal_user() -> bool: 164*c2e18aaaSAndroid Build Coastguard Worker """Returns whether the user is a google internal user.""" 165*c2e18aaaSAndroid Build Coastguard Worker return metrics_base.get_user_type() == metrics_base.INTERNAL_USER 166