1# 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. 14 15""" 16Metrics class. 17""" 18 19import constants 20 21from . import metrics_base 22 23class AtestStartEvent(metrics_base.MetricsBase): 24 """ 25 Create Atest start event and send to clearcut. 26 27 Usage: 28 metrics.AtestStartEvent( 29 command_line='example_atest_command', 30 test_references=['example_test_reference'], 31 cwd='example/working/dir', 32 os='example_os') 33 """ 34 _EVENT_NAME = 'atest_start_event' 35 command_line = constants.INTERNAL 36 test_references = constants.INTERNAL 37 cwd = constants.INTERNAL 38 os = constants.INTERNAL 39 40class AtestExitEvent(metrics_base.MetricsBase): 41 """ 42 Create Atest exit event and send to clearcut. 43 44 Usage: 45 metrics.AtestExitEvent( 46 duration=metrics_utils.convert_duration(end-start), 47 exit_code=0, 48 stacktrace='some_trace', 49 logs='some_logs') 50 """ 51 _EVENT_NAME = 'atest_exit_event' 52 duration = constants.EXTERNAL 53 exit_code = constants.EXTERNAL 54 stacktrace = constants.INTERNAL 55 logs = constants.INTERNAL 56 57class FindTestFinishEvent(metrics_base.MetricsBase): 58 """ 59 Create find test finish event and send to clearcut. 60 61 Occurs after a SINGLE test reference has been resolved to a test or 62 not found. 63 64 Usage: 65 metrics.FindTestFinishEvent( 66 duration=metrics_utils.convert_duration(end-start), 67 success=true, 68 test_reference='hello_world_test', 69 test_finders=['example_test_reference', 'ref2'], 70 test_info="test_name: hello_world_test - 71 test_runner:AtestTradefedTestRunner - 72 build_targets: 73 set(['MODULES-IN-platform_testing-tests-example-native']) - 74 data:{'rel_config': 75 'platform_testing/tests/example/native/AndroidTest.xml', 76 'filter': frozenset([])} - 77 suite:None - module_class: ['NATIVE_TESTS'] - 78 install_locations:set(['device', 'host'])") 79 """ 80 _EVENT_NAME = 'find_test_finish_event' 81 duration = constants.EXTERNAL 82 success = constants.EXTERNAL 83 test_reference = constants.INTERNAL 84 test_finders = constants.INTERNAL 85 test_info = constants.INTERNAL 86 87class BuildFinishEvent(metrics_base.MetricsBase): 88 """ 89 Create build finish event and send to clearcut. 90 91 Occurs after the build finishes, either successfully or not. 92 93 Usage: 94 metrics.BuildFinishEvent( 95 duration=metrics_utils.convert_duration(end-start), 96 success=true, 97 targets=['target1', 'target2']) 98 """ 99 _EVENT_NAME = 'build_finish_event' 100 duration = constants.EXTERNAL 101 success = constants.EXTERNAL 102 targets = constants.INTERNAL 103 104class RunnerFinishEvent(metrics_base.MetricsBase): 105 """ 106 Create run finish event and send to clearcut. 107 108 Occurs when a single test runner has completed. 109 110 Usage: 111 metrics.RunnerFinishEvent( 112 duration=metrics_utils.convert_duration(end-start), 113 success=true, 114 runner_name='AtestTradefedTestRunner' 115 test=[{name:'hello_world_test', result:0, stacktrace:''}, 116 {name:'test2', result:1, stacktrace:'xxx'}]) 117 """ 118 _EVENT_NAME = 'runner_finish_event' 119 duration = constants.EXTERNAL 120 success = constants.EXTERNAL 121 runner_name = constants.EXTERNAL 122 test = constants.INTERNAL 123 124class RunTestsFinishEvent(metrics_base.MetricsBase): 125 """ 126 Create run tests finish event and send to clearcut. 127 128 Occurs after all test runners and tests have finished. 129 130 Usage: 131 metrics.RunTestsFinishEvent( 132 duration=metrics_utils.convert_duration(end-start)) 133 """ 134 _EVENT_NAME = 'run_tests_finish_event' 135 duration = constants.EXTERNAL 136 137class LocalDetectEvent(metrics_base.MetricsBase): 138 """ 139 Create local detection event and send it to clearcut. 140 141 Usage: 142 metrics.LocalDetectEvent( 143 detect_type=0, 144 result=0) 145 """ 146 _EVENT_NAME = 'local_detect_event' 147 detect_type = constants.EXTERNAL 148 result = constants.EXTERNAL 149