summaryrefslogtreecommitdiff
path: root/simpleperf/demo/SimpleperfExamplePureJava/app/profiling.gradle
blob: aa23c8d2412605eecb0cd1fcd166bbf068896958 (plain)
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

// 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
    }
}