Skip to content

Commit

Permalink
Add Android profiling build type
Browse files Browse the repository at this point in the history
  • Loading branch information
hjanetzek committed Jan 15, 2019
1 parent caa1b9a commit 486e10a
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 2 deletions.
3 changes: 2 additions & 1 deletion platforms/android/demo/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
apply plugin: 'com.android.application'

apply from: 'profiling.gradle'

android {
compileSdkVersion 27

Expand All @@ -26,7 +28,6 @@ android {
minifyEnabled true
}
}

}

dependencies {
Expand Down
57 changes: 57 additions & 0 deletions platforms/android/demo/profiling.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@

// Set when building only part of the abis in the apk.
def abiFiltersForWrapScript = []

android {
buildTypes {
profiling {
initWith debug
externalNativeBuild {
cmake {
// cmake Debug build type uses -O0, which makes the code slow.
arguments "-DCMAKE_BUILD_TYPE=Release"
}
}
packagingOptions {
// Exclude wrap.sh for architectures not built.
if (abiFiltersForWrapScript) {
def exclude_abis = ["armeabi", "armeabi-v7a", "arm64-v8a",
"x86", "x86_64", "mips", "mips64"]
.findAll{ !(it in abiFiltersForWrapScript) }
.collect{ "**/" + it + "/wrap.sh" }
excludes += exclude_abis
}
}

// Add lib/xxx/wrap.sh in the apk. This is to enable java profiling on Android O
// devices.
sourceSets {
profiling {
resources {
srcDir {
"profiling_apk_add_dir"
}
}
}
}
}
}
}

def writeWrapScriptToFullyCompileJavaApp(wrapFile) {
wrapFile.withWriter { writer ->
writer.write('#!/system/bin/sh\n')
writer.write('\$@\n')
}
}

task createProfilingApkAddDir {
for (String abi : ["armeabi", "armeabi-v7a", "arm64-v8a", "x86", "x86_64", "mips", "mips64"]) {
def dir = new File("app/profiling_apk_add_dir/lib/" + abi)
dir.mkdirs()
def wrapFile = new File(dir, "wrap.sh")
writeWrapScriptToFullyCompileJavaApp(wrapFile)
println "write file " + wrapFile.path
}
}

12 changes: 12 additions & 0 deletions platforms/android/profiling.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Android

- https://android.googlesource.com/platform/system/extras/+/master/simpleperf/doc/
- https://android.googlesource.com/platform/system/extras/+/master/simpleperf/demo/README.md#profiling-javac-application

## Studio

- Run 'Profile selected configuration'
- Click CPU row
- Select 'Sampled (Native)'
- Click 'Record a method trace', right next to it
- Select thread of interest to show Call-/Flame-chart
4 changes: 3 additions & 1 deletion platforms/android/tangram/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ group = GROUP
version = VERSION_NAME

apply from: 'versioning.gradle'
apply from: 'profiling.gradle'

android {
compileSdkVersion 27
Expand All @@ -27,7 +28,8 @@ android {
cmake {
targets 'tangram'
arguments '-DTANGRAM_PLATFORM=android',
'-DANDROID_STL=c++_shared'
'-DANDROID_STL=c++_shared',
'-DCMAKE_BUILD_TYPE=Release'
cppFlags '-std=c++14',
'-pedantic',
'-fPIC',
Expand Down
58 changes: 58 additions & 0 deletions platforms/android/tangram/profiling.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@

// Set when building only part of the abis in the apk.
def abiFiltersForWrapScript = []

android {
buildTypes {
profiling {
initWith debug
externalNativeBuild {
cmake {
// cmake Debug build type uses -O0, which makes the code slow.
arguments "-DCMAKE_BUILD_TYPE=Release"
cppFlags '-fno-omit-frame-pointer'
}
}
packagingOptions {
// Exclude wrap.sh for architectures not built.
if (abiFiltersForWrapScript) {
def exclude_abis = ["armeabi", "armeabi-v7a", "arm64-v8a",
"x86", "x86_64", "mips", "mips64"]
.findAll{ !(it in abiFiltersForWrapScript) }
.collect{ "**/" + it + "/wrap.sh" }
excludes += exclude_abis
}
}

// Add lib/xxx/wrap.sh in the apk. This is to enable java profiling on Android O
// devices.
sourceSets {
profiling {
resources {
srcDir {
"profiling_apk_add_dir"
}
}
}
}
}
}
}

def writeWrapScriptToFullyCompileJavaApp(wrapFile) {
wrapFile.withWriter { writer ->
writer.write('#!/system/bin/sh\n')
writer.write('\$@\n')
}
}

task createProfilingApkAddDir {
for (String abi : ["armeabi", "armeabi-v7a", "arm64-v8a", "x86", "x86_64", "mips", "mips64"]) {
def dir = new File("app/profiling_apk_add_dir/lib/" + abi)
dir.mkdirs()
def wrapFile = new File(dir, "wrap.sh")
writeWrapScriptToFullyCompileJavaApp(wrapFile)
println "write file " + wrapFile.path
}
}

0 comments on commit 486e10a

Please sign in to comment.