1 /*
2  * Copyright (C) 2022 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 package com.android.tradefed.device.metric;
17 
18 import com.android.tradefed.device.DeviceNotAvailableException;
19 import com.android.tradefed.metrics.proto.MetricMeasurement.Metric;
20 import com.android.tradefed.result.FailureDescription;
21 import com.android.tradefed.result.TestDescription;
22 
23 import java.util.Map;
24 
25 /** Version of logcat collector but for module. */
26 public class ModuleLogcatCollector extends LogcatOnFailureCollector {
27 
28     private static final int MAX_LOGAT_SIZE_BYTES = 40 * 1024 * 1024;
29 
30     @Override
captureModuleLevel()31     public boolean captureModuleLevel() {
32         return true;
33     }
34 
35     @Override
onTestModuleStarted()36     public void onTestModuleStarted() throws DeviceNotAvailableException {
37         super.onTestRunStart(null);
38     }
39 
40     @Override
onTestModuleEnded()41     public void onTestModuleEnded() throws DeviceNotAvailableException {
42         collectAndLog("module-logcat", MAX_LOGAT_SIZE_BYTES);
43         super.onTestRunEnd(null, null);
44     }
45 
46     // Ignore all the non-module calls.
47     @Override
onTestRunStart(DeviceMetricData runData)48     public void onTestRunStart(DeviceMetricData runData) {
49         // Ignore
50     }
51 
52     @Override
onTestFail(DeviceMetricData testData, TestDescription test)53     public void onTestFail(DeviceMetricData testData, TestDescription test)
54             throws DeviceNotAvailableException {
55         // Ignore
56     }
57 
58     @Override
onTestRunEnd(DeviceMetricData runData, Map<String, Metric> currentRunMetrics)59     public void onTestRunEnd(DeviceMetricData runData, Map<String, Metric> currentRunMetrics) {
60         // Ignore
61     }
62 
63     @Override
onTestRunFailed(DeviceMetricData testData, FailureDescription failure)64     public void onTestRunFailed(DeviceMetricData testData, FailureDescription failure)
65             throws DeviceNotAvailableException {
66         // Ignore
67     }
68 }
69