| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 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 |
} |