| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.os; |
| 18 |
|
| 19 |
import android.perftests.utils.BenchmarkState; |
| 20 |
import android.perftests.utils.PerfStatusReporter; |
| 21 |
|
| 22 |
import androidx.test.filters.LargeTest; |
| 23 |
import androidx.test.runner.AndroidJUnit4; |
| 24 |
|
| 25 |
import org.junit.Rule; |
| 26 |
import org.junit.Test; |
| 27 |
import org.junit.runner.RunWith; |
| 28 |
|
| 29 |
import java.nio.file.Files; |
| 30 |
import java.nio.file.Paths; |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
@RunWith(AndroidJUnit4.class) |
| 36 |
@LargeTest |
| 37 |
public class CpuUsageTrackingPerfTest { |
| 38 |
@Rule |
| 39 |
public PerfStatusReporter mPerfStatusReporter = new PerfStatusReporter(); |
| 40 |
|
| 41 |
@Test |
| 42 |
public void timeSystemThread() { |
| 43 |
final BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); |
| 44 |
Binder b = new Binder(); |
| 45 |
while (state.keepRunning()) { |
| 46 |
SystemClock.currentThreadTimeMicro(); |
| 47 |
} |
| 48 |
} |
| 49 |
|
| 50 |
@Test |
| 51 |
public void timeReadStatFileDirectly() throws Exception { |
| 52 |
final BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); |
| 53 |
|
| 54 |
final String procFile = "/proc/self/stat"; |
| 55 |
while (state.keepRunning()) { |
| 56 |
byte[] data = Files.readAllBytes(Paths.get(procFile)); |
| 57 |
} |
| 58 |
} |
| 59 |
|
| 60 |
@Test |
| 61 |
public void timeReadPidProcDirectly() throws Exception { |
| 62 |
final BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); |
| 63 |
|
| 64 |
final String procFile = "/proc/self/time_in_state"; |
| 65 |
while (state.keepRunning()) { |
| 66 |
byte[] data = Files.readAllBytes(Paths.get(procFile)); |
| 67 |
} |
| 68 |
} |
| 69 |
|
| 70 |
@Test |
| 71 |
public void timeReadThreadProcDirectly() throws Exception { |
| 72 |
final BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); |
| 73 |
|
| 74 |
final String procFile = "/proc/self/task/" + android.os.Process.myTid() |
| 75 |
+ "/time_in_state"; |
| 76 |
while (state.keepRunning()) { |
| 77 |
byte[] data = Files.readAllBytes(Paths.get(procFile)); |
| 78 |
} |
| 79 |
} |
| 80 |
} |