summaryrefslogtreecommitdiff
path: root/simpleperf/demo
diff options
context:
space:
mode:
authorYabin Cui <yabinc@google.com>2017-07-26 12:29:44 -0700
committerYabin Cui <yabinc@google.com>2017-07-28 15:07:41 -0700
commitd97a532cb291aa8c5b5b1f000052c581faa50f29 (patch)
tree9bed67bd4a1a9602313d1784512d65b955f6aee8 /simpleperf/demo
parent6fd3f9b50db7f3c5896e06488d0fe17878599ec0 (diff)
downloadextras-d97a532cb291aa8c5b5b1f000052c581faa50f29.tar.gz
simpleperf add more script tests.
Add tests for Trace offcpu. Add test for jni call. Build testdata when running test.py. Bug: http://b/63006886 Test: run test.py. Change-Id: I5a87b8d2a8f59ead858c1b78a78c7e78847854f4
Diffstat (limited to 'simpleperf/demo')
-rw-r--r--simpleperf/demo/README.md2
-rw-r--r--simpleperf/demo/SimpleperfExampleOfKotlin/app/build.gradle2
-rw-r--r--simpleperf/demo/SimpleperfExampleOfKotlin/app/build/outputs/apk/profiling/app-profiling.apkbin0 -> 1976544 bytes
-rw-r--r--simpleperf/demo/SimpleperfExampleOfKotlin/app/src/main/AndroidManifest.xml4
-rw-r--r--simpleperf/demo/SimpleperfExampleOfKotlin/app/src/main/java/com/example/simpleperf/simpleperfexampleofkotlin/SleepActivity.kt50
-rw-r--r--simpleperf/demo/SimpleperfExampleOfKotlin/app/src/main/res/layout/activity_sleep.xml9
-rw-r--r--simpleperf/demo/SimpleperfExampleOfKotlin/build.gradle2
-rw-r--r--simpleperf/demo/SimpleperfExampleOfKotlin/gradle/wrapper/gradle-wrapper.properties4
-rw-r--r--simpleperf/demo/SimpleperfExamplePureJava/.idea/misc.xml15
-rw-r--r--simpleperf/demo/SimpleperfExamplePureJava/app/build/outputs/apk/app-profiling.apkbin0 -> 1576599 bytes
-rw-r--r--simpleperf/demo/SimpleperfExamplePureJava/app/src/main/AndroidManifest.xml4
-rw-r--r--simpleperf/demo/SimpleperfExamplePureJava/app/src/main/java/com/example/simpleperf/simpleperfexamplepurejava/MainActivity.java3
-rw-r--r--simpleperf/demo/SimpleperfExamplePureJava/app/src/main/java/com/example/simpleperf/simpleperfexamplepurejava/SleepActivity.java55
-rw-r--r--simpleperf/demo/SimpleperfExamplePureJava/app/src/main/res/layout/activity_sleep.xml9
-rw-r--r--simpleperf/demo/SimpleperfExampleWithNative/.idea/misc.xml15
-rw-r--r--simpleperf/demo/SimpleperfExampleWithNative/app/build.gradle1
-rwxr-xr-xsimpleperf/demo/SimpleperfExampleWithNative/app/build/intermediates/cmake/profiling/obj/arm64-v8a/libnative-lib.sobin0 -> 1334536 bytes
-rwxr-xr-xsimpleperf/demo/SimpleperfExampleWithNative/app/build/intermediates/cmake/profiling/obj/armeabi-v7a/libnative-lib.sobin0 -> 976252 bytes
-rwxr-xr-xsimpleperf/demo/SimpleperfExampleWithNative/app/build/intermediates/cmake/profiling/obj/armeabi/libnative-lib.sobin0 -> 1021064 bytes
-rwxr-xr-xsimpleperf/demo/SimpleperfExampleWithNative/app/build/intermediates/cmake/profiling/obj/mips/libnative-lib.sobin0 -> 1178452 bytes
-rwxr-xr-xsimpleperf/demo/SimpleperfExampleWithNative/app/build/intermediates/cmake/profiling/obj/mips64/libnative-lib.sobin0 -> 1519256 bytes
-rwxr-xr-xsimpleperf/demo/SimpleperfExampleWithNative/app/build/intermediates/cmake/profiling/obj/x86/libnative-lib.sobin0 -> 1057000 bytes
-rwxr-xr-xsimpleperf/demo/SimpleperfExampleWithNative/app/build/intermediates/cmake/profiling/obj/x86_64/libnative-lib.sobin0 -> 1264944 bytes
-rw-r--r--simpleperf/demo/SimpleperfExampleWithNative/app/build/outputs/apk/profiling/app-profiling.apkbin0 -> 4569248 bytes
-rw-r--r--simpleperf/demo/SimpleperfExampleWithNative/app/src/main/AndroidManifest.xml7
-rw-r--r--simpleperf/demo/SimpleperfExampleWithNative/app/src/main/cpp/native-lib.cpp61
-rw-r--r--simpleperf/demo/SimpleperfExampleWithNative/app/src/main/java/com/example/simpleperf/simpleperfexamplewithnative/MixActivity.java34
-rw-r--r--simpleperf/demo/SimpleperfExampleWithNative/app/src/main/java/com/example/simpleperf/simpleperfexamplewithnative/SleepActivity.java20
-rw-r--r--simpleperf/demo/SimpleperfExampleWithNative/app/src/main/res/layout/activity_mix.xml9
-rw-r--r--simpleperf/demo/SimpleperfExampleWithNative/app/src/main/res/layout/activity_sleep.xml9
-rw-r--r--simpleperf/demo/SimpleperfExampleWithNative/build.gradle3
-rw-r--r--simpleperf/demo/SimpleperfExampleWithNative/gradle/wrapper/gradle-wrapper.properties4
32 files changed, 282 insertions, 40 deletions
diff --git a/simpleperf/demo/README.md b/simpleperf/demo/README.md
index b8c38869..2bba0434 100644
--- a/simpleperf/demo/README.md
+++ b/simpleperf/demo/README.md
@@ -76,7 +76,7 @@ $ cd SimpleperfExampleWithNative
# On windows, use "gradlew" instead.
$ ./gradlew clean assemble
-$ adb install -r app/build/outputs/apk/app-profiling.apk
+$ adb install -r app/build/outputs/apk/profiling/app-profiling.apk
```
2. Record profiling data:
diff --git a/simpleperf/demo/SimpleperfExampleOfKotlin/app/build.gradle b/simpleperf/demo/SimpleperfExampleOfKotlin/app/build.gradle
index e7110fb7..f9178042 100644
--- a/simpleperf/demo/SimpleperfExampleOfKotlin/app/build.gradle
+++ b/simpleperf/demo/SimpleperfExampleOfKotlin/app/build.gradle
@@ -30,7 +30,7 @@ dependencies {
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
- implementation"org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
+ implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:25.4.0'
testImplementation 'junit:junit:4.12'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
diff --git a/simpleperf/demo/SimpleperfExampleOfKotlin/app/build/outputs/apk/profiling/app-profiling.apk b/simpleperf/demo/SimpleperfExampleOfKotlin/app/build/outputs/apk/profiling/app-profiling.apk
new file mode 100644
index 00000000..fde5086e
--- /dev/null
+++ b/simpleperf/demo/SimpleperfExampleOfKotlin/app/build/outputs/apk/profiling/app-profiling.apk
Binary files differ
diff --git a/simpleperf/demo/SimpleperfExampleOfKotlin/app/src/main/AndroidManifest.xml b/simpleperf/demo/SimpleperfExampleOfKotlin/app/src/main/AndroidManifest.xml
index 05eb9ee4..33e820ea 100644
--- a/simpleperf/demo/SimpleperfExampleOfKotlin/app/src/main/AndroidManifest.xml
+++ b/simpleperf/demo/SimpleperfExampleOfKotlin/app/src/main/AndroidManifest.xml
@@ -16,6 +16,10 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
+ <activity android:name=".SleepActivity"
+ android:exported="true">
+
+ </activity>
</application>
</manifest> \ No newline at end of file
diff --git a/simpleperf/demo/SimpleperfExampleOfKotlin/app/src/main/java/com/example/simpleperf/simpleperfexampleofkotlin/SleepActivity.kt b/simpleperf/demo/SimpleperfExampleOfKotlin/app/src/main/java/com/example/simpleperf/simpleperfexampleofkotlin/SleepActivity.kt
new file mode 100644
index 00000000..2ed5afe5
--- /dev/null
+++ b/simpleperf/demo/SimpleperfExampleOfKotlin/app/src/main/java/com/example/simpleperf/simpleperfexampleofkotlin/SleepActivity.kt
@@ -0,0 +1,50 @@
+package com.example.simpleperf.simpleperfexampleofkotlin
+
+import android.support.v7.app.AppCompatActivity
+import android.os.Bundle
+
+class SleepActivity : AppCompatActivity() {
+
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ setContentView(R.layout.activity_sleep)
+ createRunSleepThread();
+ }
+
+ fun createRunSleepThread() {
+ object : Thread() {
+ var counter = 0
+ var totalRunTimeInNs: Long = 0
+ var totalSleepTimeInNs: Long = 0
+
+ fun RunFunction(): Long {
+ var startTimeInNs = System.nanoTime()
+ var i = 0
+ while (i < 10000000) {
+ counter = callFunction(counter)
+ i++
+ }
+ return System.nanoTime() - startTimeInNs
+ }
+
+ fun SleepFunction(sleepTimeInNs: Long): Long {
+ var startTimeInNs = System.nanoTime()
+ Thread.sleep(sleepTimeInNs / 1000000, (sleepTimeInNs % 1000000).toInt())
+ return System.nanoTime() - startTimeInNs
+ }
+
+ override fun run() {
+ while (true) {
+ totalRunTimeInNs += RunFunction()
+ if (totalSleepTimeInNs < totalRunTimeInNs) {
+ totalSleepTimeInNs += SleepFunction(totalRunTimeInNs - totalSleepTimeInNs)
+ }
+ }
+ }
+
+ fun callFunction(i: Int): Int {
+ return i + 1
+ }
+ }.start()
+ }
+}
diff --git a/simpleperf/demo/SimpleperfExampleOfKotlin/app/src/main/res/layout/activity_sleep.xml b/simpleperf/demo/SimpleperfExampleOfKotlin/app/src/main/res/layout/activity_sleep.xml
new file mode 100644
index 00000000..7043eb11
--- /dev/null
+++ b/simpleperf/demo/SimpleperfExampleOfKotlin/app/src/main/res/layout/activity_sleep.xml
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="utf-8"?>
+<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:app="http://schemas.android.com/apk/res-auto"
+ xmlns:tools="http://schemas.android.com/tools"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ tools:context="com.example.simpleperf.simpleperfexampleofkotlin.SleepActivity">
+
+</android.support.constraint.ConstraintLayout>
diff --git a/simpleperf/demo/SimpleperfExampleOfKotlin/build.gradle b/simpleperf/demo/SimpleperfExampleOfKotlin/build.gradle
index 2e0233ba..f54592ff 100644
--- a/simpleperf/demo/SimpleperfExampleOfKotlin/build.gradle
+++ b/simpleperf/demo/SimpleperfExampleOfKotlin/build.gradle
@@ -7,7 +7,7 @@ buildscript {
jcenter()
}
dependencies {
- classpath 'com.android.tools.build:gradle:3.0.0-alpha4'
+ classpath 'com.android.tools.build:gradle:3.0.0-alpha8'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
diff --git a/simpleperf/demo/SimpleperfExampleOfKotlin/gradle/wrapper/gradle-wrapper.properties b/simpleperf/demo/SimpleperfExampleOfKotlin/gradle/wrapper/gradle-wrapper.properties
index 96b0280b..8295c9f6 100644
--- a/simpleperf/demo/SimpleperfExampleOfKotlin/gradle/wrapper/gradle-wrapper.properties
+++ b/simpleperf/demo/SimpleperfExampleOfKotlin/gradle/wrapper/gradle-wrapper.properties
@@ -1,6 +1,6 @@
-#Mon Jun 26 18:23:25 PDT 2017
+#Wed Jul 26 16:12:43 PDT 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-4.0-rc-1-all.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-milestone-1-all.zip
diff --git a/simpleperf/demo/SimpleperfExamplePureJava/.idea/misc.xml b/simpleperf/demo/SimpleperfExamplePureJava/.idea/misc.xml
index fbb68289..53a3fb16 100644
--- a/simpleperf/demo/SimpleperfExamplePureJava/.idea/misc.xml
+++ b/simpleperf/demo/SimpleperfExamplePureJava/.idea/misc.xml
@@ -1,8 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
- <component name="EntryPointsManager">
- <entry_points version="2.0" />
- </component>
<component name="NullableNotNullManager">
<option name="myDefaultNullable" value="android.support.annotation.Nullable" />
<option name="myDefaultNotNull" value="android.support.annotation.NonNull" />
@@ -27,17 +24,7 @@
</value>
</option>
</component>
- <component name="ProjectLevelVcsManager" settingsEditedManually="false">
- <OptionsSetting value="true" id="Add" />
- <OptionsSetting value="true" id="Remove" />
- <OptionsSetting value="true" id="Checkout" />
- <OptionsSetting value="true" id="Update" />
- <OptionsSetting value="true" id="Status" />
- <OptionsSetting value="true" id="Edit" />
- <ConfirmationsSetting value="0" id="Add" />
- <ConfirmationsSetting value="0" id="Remove" />
- </component>
- <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
+ <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="JDK" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">
diff --git a/simpleperf/demo/SimpleperfExamplePureJava/app/build/outputs/apk/app-profiling.apk b/simpleperf/demo/SimpleperfExamplePureJava/app/build/outputs/apk/app-profiling.apk
new file mode 100644
index 00000000..0254bc06
--- /dev/null
+++ b/simpleperf/demo/SimpleperfExamplePureJava/app/build/outputs/apk/app-profiling.apk
Binary files differ
diff --git a/simpleperf/demo/SimpleperfExamplePureJava/app/src/main/AndroidManifest.xml b/simpleperf/demo/SimpleperfExamplePureJava/app/src/main/AndroidManifest.xml
index 9a079584..c6111027 100644
--- a/simpleperf/demo/SimpleperfExamplePureJava/app/src/main/AndroidManifest.xml
+++ b/simpleperf/demo/SimpleperfExamplePureJava/app/src/main/AndroidManifest.xml
@@ -16,6 +16,10 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
+ <activity android:name=".SleepActivity"
+ android:exported="true">
+
+ </activity>
</application>
</manifest> \ No newline at end of file
diff --git a/simpleperf/demo/SimpleperfExamplePureJava/app/src/main/java/com/example/simpleperf/simpleperfexamplepurejava/MainActivity.java b/simpleperf/demo/SimpleperfExamplePureJava/app/src/main/java/com/example/simpleperf/simpleperfexamplepurejava/MainActivity.java
index 18ff5245..2d6196b7 100644
--- a/simpleperf/demo/SimpleperfExamplePureJava/app/src/main/java/com/example/simpleperf/simpleperfexamplepurejava/MainActivity.java
+++ b/simpleperf/demo/SimpleperfExamplePureJava/app/src/main/java/com/example/simpleperf/simpleperfexamplepurejava/MainActivity.java
@@ -15,7 +15,6 @@ public class MainActivity extends AppCompatActivity {
void createBusyThread() {
new Thread(new Runnable() {
-
volatile int i = 0;
@Override
@@ -28,6 +27,6 @@ public class MainActivity extends AppCompatActivity {
private int callFunction(int a) {
return a+1;
}
- }).start();
+ }, "BusyThread").start();
}
}
diff --git a/simpleperf/demo/SimpleperfExamplePureJava/app/src/main/java/com/example/simpleperf/simpleperfexamplepurejava/SleepActivity.java b/simpleperf/demo/SimpleperfExamplePureJava/app/src/main/java/com/example/simpleperf/simpleperfexamplepurejava/SleepActivity.java
new file mode 100644
index 00000000..25dc7e3e
--- /dev/null
+++ b/simpleperf/demo/SimpleperfExamplePureJava/app/src/main/java/com/example/simpleperf/simpleperfexamplepurejava/SleepActivity.java
@@ -0,0 +1,55 @@
+package com.example.simpleperf.simpleperfexamplepurejava;
+
+import android.support.v7.app.AppCompatActivity;
+import android.os.Bundle;
+
+public class SleepActivity extends AppCompatActivity {
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_sleep);
+ createRunSleepThread();
+ }
+
+ void createRunSleepThread() {
+ new Thread(new Runnable() {
+ volatile int counter = 0;
+ long totalRunTimeInNs = 0;
+ long totalSleepTimeInNs = 0;
+
+ private long RunFunction() {
+ long startTimeInNs = System.nanoTime();
+ for (int i = 0; i < 10000000; ++i) {
+ counter = callFunction(counter);
+ }
+ return System.nanoTime() - startTimeInNs;
+ }
+
+ private long SleepFunction(long sleepTimeInNs) {
+ long startTimeInNs = System.nanoTime();
+ try {
+ Thread.sleep(sleepTimeInNs / 1000000, (int) (sleepTimeInNs % 1000000));
+ } catch (Exception e) {
+ }
+ return System.nanoTime() - startTimeInNs;
+ }
+
+ @Override
+ public void run() {
+ while (true) {
+ totalRunTimeInNs += RunFunction();
+ if (totalSleepTimeInNs < totalRunTimeInNs) {
+ totalSleepTimeInNs += SleepFunction(
+ totalRunTimeInNs - totalSleepTimeInNs);
+ }
+ }
+ }
+
+ private int callFunction(int a) {
+ return a+1;
+ }
+ }, "RunSleepThread").start();
+ }
+
+}
diff --git a/simpleperf/demo/SimpleperfExamplePureJava/app/src/main/res/layout/activity_sleep.xml b/simpleperf/demo/SimpleperfExamplePureJava/app/src/main/res/layout/activity_sleep.xml
new file mode 100644
index 00000000..e2274ca8
--- /dev/null
+++ b/simpleperf/demo/SimpleperfExamplePureJava/app/src/main/res/layout/activity_sleep.xml
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="utf-8"?>
+<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:app="http://schemas.android.com/apk/res-auto"
+ xmlns:tools="http://schemas.android.com/tools"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ tools:context="com.example.simpleperf.simpleperfexamplepurejava.SleepActivity">
+
+</android.support.constraint.ConstraintLayout>
diff --git a/simpleperf/demo/SimpleperfExampleWithNative/.idea/misc.xml b/simpleperf/demo/SimpleperfExampleWithNative/.idea/misc.xml
index fbb68289..4a04528f 100644
--- a/simpleperf/demo/SimpleperfExampleWithNative/.idea/misc.xml
+++ b/simpleperf/demo/SimpleperfExampleWithNative/.idea/misc.xml
@@ -1,8 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
- <component name="EntryPointsManager">
- <entry_points version="2.0" />
- </component>
<component name="NullableNotNullManager">
<option name="myDefaultNullable" value="android.support.annotation.Nullable" />
<option name="myDefaultNotNull" value="android.support.annotation.NonNull" />
@@ -27,17 +24,7 @@
</value>
</option>
</component>
- <component name="ProjectLevelVcsManager" settingsEditedManually="false">
- <OptionsSetting value="true" id="Add" />
- <OptionsSetting value="true" id="Remove" />
- <OptionsSetting value="true" id="Checkout" />
- <OptionsSetting value="true" id="Update" />
- <OptionsSetting value="true" id="Status" />
- <OptionsSetting value="true" id="Edit" />
- <ConfirmationsSetting value="0" id="Add" />
- <ConfirmationsSetting value="0" id="Remove" />
- </component>
- <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
+ <component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" project-jdk-name="JDK" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">
diff --git a/simpleperf/demo/SimpleperfExampleWithNative/app/build.gradle b/simpleperf/demo/SimpleperfExampleWithNative/app/build.gradle
index efa47c20..d69d6a12 100644
--- a/simpleperf/demo/SimpleperfExampleWithNative/app/build.gradle
+++ b/simpleperf/demo/SimpleperfExampleWithNative/app/build.gradle
@@ -32,6 +32,7 @@ android {
}
dependencies {
+ implementation 'com.android.support.constraint:constraint-layout:1.0.2'
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
diff --git a/simpleperf/demo/SimpleperfExampleWithNative/app/build/intermediates/cmake/profiling/obj/arm64-v8a/libnative-lib.so b/simpleperf/demo/SimpleperfExampleWithNative/app/build/intermediates/cmake/profiling/obj/arm64-v8a/libnative-lib.so
new file mode 100755
index 00000000..7cffe5d2
--- /dev/null
+++ b/simpleperf/demo/SimpleperfExampleWithNative/app/build/intermediates/cmake/profiling/obj/arm64-v8a/libnative-lib.so
Binary files differ
diff --git a/simpleperf/demo/SimpleperfExampleWithNative/app/build/intermediates/cmake/profiling/obj/armeabi-v7a/libnative-lib.so b/simpleperf/demo/SimpleperfExampleWithNative/app/build/intermediates/cmake/profiling/obj/armeabi-v7a/libnative-lib.so
new file mode 100755
index 00000000..9ad87aa7
--- /dev/null
+++ b/simpleperf/demo/SimpleperfExampleWithNative/app/build/intermediates/cmake/profiling/obj/armeabi-v7a/libnative-lib.so
Binary files differ
diff --git a/simpleperf/demo/SimpleperfExampleWithNative/app/build/intermediates/cmake/profiling/obj/armeabi/libnative-lib.so b/simpleperf/demo/SimpleperfExampleWithNative/app/build/intermediates/cmake/profiling/obj/armeabi/libnative-lib.so
new file mode 100755
index 00000000..b95bf948
--- /dev/null
+++ b/simpleperf/demo/SimpleperfExampleWithNative/app/build/intermediates/cmake/profiling/obj/armeabi/libnative-lib.so
Binary files differ
diff --git a/simpleperf/demo/SimpleperfExampleWithNative/app/build/intermediates/cmake/profiling/obj/mips/libnative-lib.so b/simpleperf/demo/SimpleperfExampleWithNative/app/build/intermediates/cmake/profiling/obj/mips/libnative-lib.so
new file mode 100755
index 00000000..9580a705
--- /dev/null
+++ b/simpleperf/demo/SimpleperfExampleWithNative/app/build/intermediates/cmake/profiling/obj/mips/libnative-lib.so
Binary files differ
diff --git a/simpleperf/demo/SimpleperfExampleWithNative/app/build/intermediates/cmake/profiling/obj/mips64/libnative-lib.so b/simpleperf/demo/SimpleperfExampleWithNative/app/build/intermediates/cmake/profiling/obj/mips64/libnative-lib.so
new file mode 100755
index 00000000..d1f12ee9
--- /dev/null
+++ b/simpleperf/demo/SimpleperfExampleWithNative/app/build/intermediates/cmake/profiling/obj/mips64/libnative-lib.so
Binary files differ
diff --git a/simpleperf/demo/SimpleperfExampleWithNative/app/build/intermediates/cmake/profiling/obj/x86/libnative-lib.so b/simpleperf/demo/SimpleperfExampleWithNative/app/build/intermediates/cmake/profiling/obj/x86/libnative-lib.so
new file mode 100755
index 00000000..7279b715
--- /dev/null
+++ b/simpleperf/demo/SimpleperfExampleWithNative/app/build/intermediates/cmake/profiling/obj/x86/libnative-lib.so
Binary files differ
diff --git a/simpleperf/demo/SimpleperfExampleWithNative/app/build/intermediates/cmake/profiling/obj/x86_64/libnative-lib.so b/simpleperf/demo/SimpleperfExampleWithNative/app/build/intermediates/cmake/profiling/obj/x86_64/libnative-lib.so
new file mode 100755
index 00000000..652ba2e8
--- /dev/null
+++ b/simpleperf/demo/SimpleperfExampleWithNative/app/build/intermediates/cmake/profiling/obj/x86_64/libnative-lib.so
Binary files differ
diff --git a/simpleperf/demo/SimpleperfExampleWithNative/app/build/outputs/apk/profiling/app-profiling.apk b/simpleperf/demo/SimpleperfExampleWithNative/app/build/outputs/apk/profiling/app-profiling.apk
new file mode 100644
index 00000000..c15d2ea9
--- /dev/null
+++ b/simpleperf/demo/SimpleperfExampleWithNative/app/build/outputs/apk/profiling/app-profiling.apk
Binary files differ
diff --git a/simpleperf/demo/SimpleperfExampleWithNative/app/src/main/AndroidManifest.xml b/simpleperf/demo/SimpleperfExampleWithNative/app/src/main/AndroidManifest.xml
index 94078ff3..de778e5e 100644
--- a/simpleperf/demo/SimpleperfExampleWithNative/app/src/main/AndroidManifest.xml
+++ b/simpleperf/demo/SimpleperfExampleWithNative/app/src/main/AndroidManifest.xml
@@ -16,6 +16,13 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
+ <activity
+ android:name=".SleepActivity"
+ android:exported="true"></activity>
+ <activity android:name=".MixActivity"
+ android:exported="true">
+
+ </activity>
</application>
</manifest> \ No newline at end of file
diff --git a/simpleperf/demo/SimpleperfExampleWithNative/app/src/main/cpp/native-lib.cpp b/simpleperf/demo/SimpleperfExampleWithNative/app/src/main/cpp/native-lib.cpp
index 5cd0607b..bd66bcde 100644
--- a/simpleperf/demo/SimpleperfExampleWithNative/app/src/main/cpp/native-lib.cpp
+++ b/simpleperf/demo/SimpleperfExampleWithNative/app/src/main/cpp/native-lib.cpp
@@ -2,10 +2,10 @@
#include <pthread.h>
#include <stdlib.h>
-
+#include <time.h>
#include <string>
-
+#define noinline __attribute__((__noinline__))
extern "C"
JNIEXPORT jstring JNICALL
@@ -60,3 +60,60 @@ Java_com_example_simpleperf_simpleperfexamplewithnative_MainActivity_createBusyT
return;
}
}
+
+static inline uint64_t GetSystemClock() {
+ timespec ts;
+ clock_gettime(CLOCK_MONOTONIC, &ts);
+ return ts.tv_sec * 1000000000ULL + ts.tv_nsec;
+}
+
+constexpr int LOOP_COUNT = 100000000;
+static uint64_t noinline RunFunction() {
+ uint64_t start_time_in_ns = GetSystemClock();
+ for (volatile int i = 0; i < LOOP_COUNT; ++i) {
+ }
+ return GetSystemClock() - start_time_in_ns;
+}
+
+static uint64_t noinline SleepFunction(unsigned long long sleep_time_in_ns) {
+ uint64_t start_time_in_ns = GetSystemClock();
+ struct timespec req;
+ req.tv_sec = sleep_time_in_ns / 1000000000;
+ req.tv_nsec = sleep_time_in_ns % 1000000000;
+ nanosleep(&req, nullptr);
+ return GetSystemClock() - start_time_in_ns;
+}
+
+static void* SleepThread(void*) {
+ pthread_setname_np(pthread_self(), "SleepThread");
+ uint64_t total_sleep_time_in_ns = 0;
+ uint64_t total_run_time_in_ns = 0;
+ while (true) {
+ total_run_time_in_ns += RunFunction();
+ if (total_sleep_time_in_ns < total_run_time_in_ns) {
+ total_sleep_time_in_ns += SleepFunction(total_run_time_in_ns - total_sleep_time_in_ns);
+ }
+ }
+}
+
+extern "C"
+JNIEXPORT void JNICALL
+Java_com_example_simpleperf_simpleperfexamplewithnative_SleepActivity_createSleepThreadFromJNI(
+ JNIEnv *env,
+ jobject /* this */) {
+ pthread_t thread;
+ int ret = pthread_create(&thread, nullptr, SleepThread, nullptr);
+ if (ret) {
+ ThrowErrnoException(env, "pthread_create", ret);
+ return;
+ }
+}
+
+extern "C"
+JNIEXPORT int JNICALL
+Java_com_example_simpleperf_simpleperfexamplewithnative_MixActivity_callFunction(
+ JNIEnv *env,
+ jobject /* this */,
+ int a) {
+ return CallFunction(a);
+} \ No newline at end of file
diff --git a/simpleperf/demo/SimpleperfExampleWithNative/app/src/main/java/com/example/simpleperf/simpleperfexamplewithnative/MixActivity.java b/simpleperf/demo/SimpleperfExampleWithNative/app/src/main/java/com/example/simpleperf/simpleperfexamplewithnative/MixActivity.java
new file mode 100644
index 00000000..a50f3bd8
--- /dev/null
+++ b/simpleperf/demo/SimpleperfExampleWithNative/app/src/main/java/com/example/simpleperf/simpleperfexamplewithnative/MixActivity.java
@@ -0,0 +1,34 @@
+package com.example.simpleperf.simpleperfexamplewithnative;
+
+import android.support.v7.app.AppCompatActivity;
+import android.os.Bundle;
+
+public class MixActivity extends AppCompatActivity {
+
+ static {
+ System.loadLibrary("native-lib");
+ }
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_mix);
+ createBusyThread();
+ }
+
+ void createBusyThread() {
+ new Thread(new Runnable() {
+ volatile int i = 0;
+
+ @Override
+ public void run() {
+ while (true) {
+ i = callFunction(i);
+ }
+ }
+
+ }, "BusyThread").start();
+ }
+
+ private native int callFunction(int a);
+}
diff --git a/simpleperf/demo/SimpleperfExampleWithNative/app/src/main/java/com/example/simpleperf/simpleperfexamplewithnative/SleepActivity.java b/simpleperf/demo/SimpleperfExampleWithNative/app/src/main/java/com/example/simpleperf/simpleperfexamplewithnative/SleepActivity.java
new file mode 100644
index 00000000..e33dd222
--- /dev/null
+++ b/simpleperf/demo/SimpleperfExampleWithNative/app/src/main/java/com/example/simpleperf/simpleperfexamplewithnative/SleepActivity.java
@@ -0,0 +1,20 @@
+package com.example.simpleperf.simpleperfexamplewithnative;
+
+import android.support.v7.app.AppCompatActivity;
+import android.os.Bundle;
+
+public class SleepActivity extends AppCompatActivity {
+
+ static {
+ System.loadLibrary("native-lib");
+ }
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_sleep);
+ createSleepThreadFromJNI();
+ }
+
+ private native void createSleepThreadFromJNI();
+}
diff --git a/simpleperf/demo/SimpleperfExampleWithNative/app/src/main/res/layout/activity_mix.xml b/simpleperf/demo/SimpleperfExampleWithNative/app/src/main/res/layout/activity_mix.xml
new file mode 100644
index 00000000..467dd77f
--- /dev/null
+++ b/simpleperf/demo/SimpleperfExampleWithNative/app/src/main/res/layout/activity_mix.xml
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="utf-8"?>
+<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:app="http://schemas.android.com/apk/res-auto"
+ xmlns:tools="http://schemas.android.com/tools"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ tools:context="com.example.simpleperf.simpleperfexamplewithnative.MixActivity">
+
+</android.support.constraint.ConstraintLayout>
diff --git a/simpleperf/demo/SimpleperfExampleWithNative/app/src/main/res/layout/activity_sleep.xml b/simpleperf/demo/SimpleperfExampleWithNative/app/src/main/res/layout/activity_sleep.xml
new file mode 100644
index 00000000..8eeab2e4
--- /dev/null
+++ b/simpleperf/demo/SimpleperfExampleWithNative/app/src/main/res/layout/activity_sleep.xml
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="utf-8"?>
+<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:app="http://schemas.android.com/apk/res-auto"
+ xmlns:tools="http://schemas.android.com/tools"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ tools:context="com.example.simpleperf.simpleperfexamplewithnative.SleepActivity">
+
+</android.support.constraint.ConstraintLayout>
diff --git a/simpleperf/demo/SimpleperfExampleWithNative/build.gradle b/simpleperf/demo/SimpleperfExampleWithNative/build.gradle
index b78a0b86..fab54fb9 100644
--- a/simpleperf/demo/SimpleperfExampleWithNative/build.gradle
+++ b/simpleperf/demo/SimpleperfExampleWithNative/build.gradle
@@ -3,9 +3,10 @@
buildscript {
repositories {
jcenter()
+ maven { url 'https://maven.google.com' }
}
dependencies {
- classpath 'com.android.tools.build:gradle:2.3.1'
+ classpath 'com.android.tools.build:gradle:3.0.0-alpha8'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
diff --git a/simpleperf/demo/SimpleperfExampleWithNative/gradle/wrapper/gradle-wrapper.properties b/simpleperf/demo/SimpleperfExampleWithNative/gradle/wrapper/gradle-wrapper.properties
index 4a462f03..dbeed603 100644
--- a/simpleperf/demo/SimpleperfExampleWithNative/gradle/wrapper/gradle-wrapper.properties
+++ b/simpleperf/demo/SimpleperfExampleWithNative/gradle/wrapper/gradle-wrapper.properties
@@ -1,6 +1,6 @@
-#Wed Apr 26 20:39:16 PDT 2017
+#Wed Jul 26 15:32:48 PDT 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-milestone-1-all.zip