• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 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 graphics stats at regular intervals. */
29 public class GraphicsStatsMetricCollector extends ScheduledDeviceMetricCollector {
GraphicsStatsMetricCollector()30     GraphicsStatsMetricCollector() {
31         setTag("jank");
32     }
33 
34     @Override
collect(ITestDevice device, DeviceMetricData runData)35     public void collect(ITestDevice device, DeviceMetricData runData) throws InterruptedException {
36         try {
37             CLog.i("Running graphicsstats...");
38             String outputFileName =
39                     String.format("%s/graphics-%s", createTempDir(), getFileSuffix());
40             File outputFile = saveProcessOutput(device, "dumpsys graphicsstats", outputFileName);
41             try (InputStreamSource source = new FileInputStreamSource(outputFile, true)) {
42                 getInvocationListener()
43                         .testLog(
44                                 Files.getNameWithoutExtension(outputFile.getName()),
45                                 LogDataType.GFX_INFO,
46                                 source);
47             }
48         } catch (DeviceNotAvailableException | IOException e) {
49             CLog.e(e);
50         }
51     }
52 }
53