blob: e126fb807b99a25bf01ad52e431c12bbc9e91549 [file] [log] [blame]
Fyodor Kupolovca348512018-01-10 18:05:53 -08001/*
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
17package android.os;
18
19import android.perftests.utils.BenchmarkState;
20import android.perftests.utils.PerfStatusReporter;
21import android.support.test.filters.LargeTest;
22import android.support.test.runner.AndroidJUnit4;
23
24import com.android.internal.os.BinderCallsStats;
25
26import org.junit.After;
27import org.junit.Before;
28import org.junit.Rule;
29import org.junit.Test;
30import org.junit.runner.RunWith;
31
32import static org.junit.Assert.assertNull;
33
34
35/**
36 * Performance tests for {@link BinderCallsStats}
37 */
38@RunWith(AndroidJUnit4.class)
39@LargeTest
40public class BinderCallsStatsPerfTest {
41
42 @Rule
43 public PerfStatusReporter mPerfStatusReporter = new PerfStatusReporter();
44 private BinderCallsStats mBinderCallsStats;
45
46 @Before
47 public void setUp() {
Olivier Gaillard1d7f6152018-07-03 13:57:58 +010048 mBinderCallsStats = new BinderCallsStats();
Fyodor Kupolovca348512018-01-10 18:05:53 -080049 }
50
51 @After
52 public void tearDown() {
53 }
54
55 @Test
56 public void timeCallSession() {
Olivier Gaillard1d7f6152018-07-03 13:57:58 +010057 mBinderCallsStats.setDetailedTracking(true);
Fyodor Kupolovca348512018-01-10 18:05:53 -080058 final BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
59 Binder b = new Binder();
60 int i = 0;
61 while (state.keepRunning()) {
62 BinderCallsStats.CallSession s = mBinderCallsStats.callStarted(b, i % 100);
Olivier Gaillard58b56e32018-06-01 16:18:43 +010063 mBinderCallsStats.callEnded(s, 0, 0);
Fyodor Kupolovca348512018-01-10 18:05:53 -080064 i++;
65 }
66 }
67
68 @Test
69 public void timeCallSessionTrackingDisabled() {
Olivier Gaillard1d7f6152018-07-03 13:57:58 +010070 mBinderCallsStats.setDetailedTracking(false);
Fyodor Kupolovca348512018-01-10 18:05:53 -080071 final BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
72 Binder b = new Binder();
Fyodor Kupolovca348512018-01-10 18:05:53 -080073 while (state.keepRunning()) {
74 BinderCallsStats.CallSession s = mBinderCallsStats.callStarted(b, 0);
Olivier Gaillard58b56e32018-06-01 16:18:43 +010075 mBinderCallsStats.callEnded(s, 0, 0);
Fyodor Kupolovca348512018-01-10 18:05:53 -080076 }
77 }
78
79}