Fyodor Kupolov | ca34851 | 2018-01-10 18:05:53 -0800 | [diff] [blame] | 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 | |
| 17 | package android.os; |
| 18 | |
| 19 | import android.perftests.utils.BenchmarkState; |
| 20 | import android.perftests.utils.PerfStatusReporter; |
| 21 | import android.support.test.filters.LargeTest; |
| 22 | import android.support.test.runner.AndroidJUnit4; |
| 23 | |
| 24 | import com.android.internal.os.BinderCallsStats; |
| 25 | |
| 26 | import org.junit.After; |
| 27 | import org.junit.Before; |
| 28 | import org.junit.Rule; |
| 29 | import org.junit.Test; |
| 30 | import org.junit.runner.RunWith; |
| 31 | |
| 32 | import static org.junit.Assert.assertNull; |
| 33 | |
| 34 | |
| 35 | /** |
| 36 | * Performance tests for {@link BinderCallsStats} |
| 37 | */ |
| 38 | @RunWith(AndroidJUnit4.class) |
| 39 | @LargeTest |
| 40 | public class BinderCallsStatsPerfTest { |
| 41 | |
| 42 | @Rule |
| 43 | public PerfStatusReporter mPerfStatusReporter = new PerfStatusReporter(); |
| 44 | private BinderCallsStats mBinderCallsStats; |
| 45 | |
| 46 | @Before |
| 47 | public void setUp() { |
Olivier Gaillard | 1d7f615 | 2018-07-03 13:57:58 +0100 | [diff] [blame] | 48 | mBinderCallsStats = new BinderCallsStats(); |
Fyodor Kupolov | ca34851 | 2018-01-10 18:05:53 -0800 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | @After |
| 52 | public void tearDown() { |
| 53 | } |
| 54 | |
| 55 | @Test |
| 56 | public void timeCallSession() { |
Olivier Gaillard | 1d7f615 | 2018-07-03 13:57:58 +0100 | [diff] [blame] | 57 | mBinderCallsStats.setDetailedTracking(true); |
Fyodor Kupolov | ca34851 | 2018-01-10 18:05:53 -0800 | [diff] [blame] | 58 | 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 Gaillard | 58b56e3 | 2018-06-01 16:18:43 +0100 | [diff] [blame] | 63 | mBinderCallsStats.callEnded(s, 0, 0); |
Fyodor Kupolov | ca34851 | 2018-01-10 18:05:53 -0800 | [diff] [blame] | 64 | i++; |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | @Test |
| 69 | public void timeCallSessionTrackingDisabled() { |
Olivier Gaillard | 1d7f615 | 2018-07-03 13:57:58 +0100 | [diff] [blame] | 70 | mBinderCallsStats.setDetailedTracking(false); |
Fyodor Kupolov | ca34851 | 2018-01-10 18:05:53 -0800 | [diff] [blame] | 71 | final BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); |
| 72 | Binder b = new Binder(); |
Fyodor Kupolov | ca34851 | 2018-01-10 18:05:53 -0800 | [diff] [blame] | 73 | while (state.keepRunning()) { |
| 74 | BinderCallsStats.CallSession s = mBinderCallsStats.callStarted(b, 0); |
Olivier Gaillard | 58b56e3 | 2018-06-01 16:18:43 +0100 | [diff] [blame] | 75 | mBinderCallsStats.callEnded(s, 0, 0); |
Fyodor Kupolov | ca34851 | 2018-01-10 18:05:53 -0800 | [diff] [blame] | 76 | } |
| 77 | } |
| 78 | |
| 79 | } |