• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 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 package com.android.tradefed.device.metric;
17 
18 import com.android.tradefed.device.DeviceNotAvailableException;
19 import com.android.tradefed.device.ITestDevice;
20 import com.android.tradefed.log.LogUtil.CLog;
21 import com.android.tradefed.result.FileInputStreamSource;
22 import com.android.tradefed.result.InputStreamSource;
23 import com.android.tradefed.result.LogDataType;
24 import com.google.common.io.Files;
25 import java.io.File;
26 import java.io.IOException;
27 
28 /** A {@link ScheduledDeviceMetricCollector} to collect fragmentation at regular intervals. */
29 public class BuddyInfoMetricCollector extends ScheduledDeviceMetricCollector {
BuddyInfoMetricCollector()30     public BuddyInfoMetricCollector() {
31         setTag("fragmentation");
32     }
33 
34     @Override
collect(ITestDevice device, DeviceMetricData runData)35     void collect(ITestDevice device, DeviceMetricData runData) throws InterruptedException {
36         try {
37             CLog.i("Running unusable-index collector...");
38             String outputFileName =
39                     String.format("%s/unusable-index-%s", createTempDir(), getFileSuffix());
40             File outputFile =
41                     saveProcessOutput(device, "cat /d/extfrag/unusable_index", outputFileName);
42             try (InputStreamSource source = new FileInputStreamSource(outputFile, true)) {
43                 getInvocationListener()
44                         .testLog(
45                                 Files.getNameWithoutExtension(outputFile.getName()),
46                                 LogDataType.TEXT,
47                                 source);
48             }
49 
50         } catch (DeviceNotAvailableException | IOException e) {
51             CLog.e(e);
52         }
53     }
54 }
55