Debian Codegraph @

apct-tests/perftests/core/src/android/os/TracePerfTest.java

raw symbols SCIP
1 /*
2 * Copyright (C) 2018 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 * use this file except in compliance with the License. You may obtain a copy of
6 * 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, WITHOUT
12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 * License for the specific language governing permissions and limitations under
14 * the License.
15 */
16
17
18 package android.os;
19
20 import android.perftests.utils.BenchmarkState;
21 import android.perftests.utils.PerfStatusReporter;
22 import android.perftests.utils.ShellHelper;
23
24 import androidx.test.runner.AndroidJUnit4;
25
26 import org.junit.AfterClass;
27 import org.junit.Assert;
28 import org.junit.Before;
29 import org.junit.BeforeClass;
30 import org.junit.Rule;
31 import org.junit.Test;
32 import org.junit.runner.RunWith;
33
34 @RunWith(AndroidJUnit4.class)
35 public class TracePerfTest {
36 @Rule
37 public PerfStatusReporter mPerfStatusReporter = new PerfStatusReporter();
38
39 @BeforeClass
40 public static void startTracing() {
41 ShellHelper.runShellCommandRaw("atrace -c --async_start -a *");
42 }
43
44 @AfterClass
45 public static void endTracing() {
46 ShellHelper.runShellCommandRaw("atrace --async_stop");
47 }
48
49 @Before
50 public void verifyTracingEnabled() {
51 Assert.assertTrue(Trace.isEnabled());
52 }
53
54 @Test
55 public void testEnabled() {
56 BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
57 while (state.keepRunning()) {
58 Trace.isEnabled();
59 }
60 }
61
62 @Test
63 public void testBeginEndSection() {
64 BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
65 while (state.keepRunning()) {
66 Trace.beginSection("testBeginEndSection");
67 Trace.endSection();
68 }
69 }
70
71 @Test
72 public void testAsyncBeginEnd() {
73 BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
74 while (state.keepRunning()) {
75 Trace.beginAsyncSection("testAsyncBeginEnd", 42);
76 Trace.endAsyncSection("testAsyncBeginEnd", 42);
77 }
78 }
79
80 @Test
81 public void testCounter() {
82 BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
83 while (state.keepRunning()) {
84 Trace.setCounter("testCounter", 123);
85 }
86 }
87 }