• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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 
17 package com.android.performance.tests;
18 
19 import com.android.tradefed.device.metric.EmulatorMemoryCpuCapturer;
20 import com.android.tradefed.invoker.TestInformation;
21 import com.android.tradefed.result.ITestInvocationListener;
22 import com.android.tradefed.targetprep.BaseEmulatorPreparer;
23 import com.android.tradefed.testtype.AndroidJUnitTest;
24 
25 import java.nio.file.Path;
26 
27 /**
28  * A performance test that does repeated emulator launch + run instrumentation test.
29  *
30  * <p>Intended to be paired with a metrics collector like EmulatorMemoryCpuCollector to measure
31  */
32 public class EmulatorInstrumentationPerfTest extends BaseEmulatorPerfTest {
33     @Override
performIteration( TestInformation testInfo, BaseEmulatorPreparer emulatorLauncher, AndroidJUnitTest delegateTest, Path apkPath, DataRecorder dataRecorder, ITestInvocationListener listener)34     protected void performIteration(
35             TestInformation testInfo,
36             BaseEmulatorPreparer emulatorLauncher,
37             AndroidJUnitTest delegateTest,
38             Path apkPath,
39             DataRecorder dataRecorder,
40             ITestInvocationListener listener)
41             throws Exception {
42         emulatorLauncher.setUp(testInfo);
43 
44         EmulatorMemoryCpuCapturer capturer = new EmulatorMemoryCpuCapturer(testInfo.getDevice());
45         dataRecorder.recordMetric("initial_memory_pss", capturer.getPssMemory());
46         dataRecorder.recordMetric("initial_cpu_usage", capturer.getCpuUsage());
47 
48         delegateTest.setDevice(testInfo.getDevice());
49         testInfo.getDevice().installPackage(apkPath.toFile(), true);
50         delegateTest.run(testInfo, listener);
51 
52         dataRecorder.recordMetric("end_memory_pss", capturer.getPssMemory());
53         dataRecorder.recordMetric("overall_cpu_usage", capturer.getCpuUsage());
54     }
55 }
56