-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
profiling.gradle
96 lines (85 loc) · 2.8 KB
/
profiling.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
android {
buildTypes {
debug {
externalNativeBuild {
cmake {
// cmake Debug build type uses -O0, which makes the code slow.
arguments "-DCMAKE_BUILD_TYPE=Release", "-DUSE_SAN=ON"
}
}
// Add lib/xxx/wrap.sh in the apk. This is to enable java profiling on Android O
// devices.
sourceSets {
debug {
resources {
srcDir {
"profiling_apk_add_dir"
}
}
jniLibs.srcDirs += "profiling_apk_add_dir/libs"
}
}
}
}
}
tasks.whenTaskAdded { task ->
if (task.name.startsWith('generate')) {
task.dependsOn createProfilingApkAddDir
}
}
tasks.whenTaskAdded { task ->
if (task.name.startsWith('clean')) {
task.dependsOn deleteSan
}
}
task deleteSan(type: Delete) {
delete 'profiling_apk_add_dir'
}
clean.dependsOn(deleteSan)
def supportedAbis = ["armeabi-v7a", "arm64-v8a", "x86", "x86_64"]
static def archFromAbi(abi) {
def arch = "undef"
switch (abi) {
case "armeabi-v7a": arch = "arm"; break
case "arm64-v8a": arch = "aarch64"; break
case "x86": arch = "i686"; break
case "x86_64": arch = "x86_64"; break
}
arch
}
static def writeWrapScript(wrapFile, abi) {
def arch = archFromAbi(abi)
wrapFile.withWriter { writer ->
writer.write('#!/system/bin/sh\n')
writer.write('HERE="$(cd "$(dirname "$0")" && pwd)"\n')
writer.write('export ASAN_OPTIONS=log_to_syslog=false,allow_user_segv_handler=1\n')
writer.write("export LD_PRELOAD=\$HERE/libclang_rt.asan-${arch}-android.so\n")
writer.write('\$@\n')
}
}
//todo understand lib arch mixup with multiarch config
task copySanLibs(type: Copy) {
for (String abi : supportedAbis) {
def arch = archFromAbi(abi)
def dir = file("profiling_apk_add_dir/libs/${abi}/")
dir.mkdirs()
def sanPath = "/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/9.0.8/lib/linux/"
println android.ndkDirectory.path + sanPath + "libclang_rt.asan-${arch}-android.so"
copy {
from(android.ndkDirectory.path + sanPath) {
include "libclang_rt.asan-${arch}-android.so"
}
into dir
}
println "copy *san for arch ${arch} files in abi ${abi} dir " + dir
}
}
task createProfilingApkAddDir(dependsOn: copySanLibs) {
for (String abi : supportedAbis) {
def dir = file("profiling_apk_add_dir/lib/${abi}")
dir.mkdirs()
def wrapFile = new File(dir, "wrap.sh")
writeWrapScript(wrapFile, abi)
println "write file " + wrapFile.path
}
}