Skip to content

Commit

Permalink
Add class reference analysis for booster-task-analyser
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsonlee committed Jun 7, 2022
1 parent 77ddff0 commit 1d21e4c
Show file tree
Hide file tree
Showing 15 changed files with 752 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.didiglobal.booster.task.analyser
package com.didiglobal.booster.task.analyser.performance

import org.xml.sax.Attributes
import org.xml.sax.helpers.DefaultHandler
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.didiglobal.booster.task.analyser
package com.didiglobal.booster.task.analyser.performance

import com.didiglobal.booster.aapt2.metadata
import com.didiglobal.booster.cha.ClassHierarchy
Expand All @@ -17,6 +17,8 @@ import com.didiglobal.booster.kotlinx.red
import com.didiglobal.booster.kotlinx.search
import com.didiglobal.booster.kotlinx.separatorsToSystem
import com.didiglobal.booster.kotlinx.yellow
import com.didiglobal.booster.task.analyser.Build
import com.didiglobal.booster.task.analyser.AsmClassFileParser
import com.didiglobal.booster.transform.ArtifactManager
import com.didiglobal.booster.transform.asm.args
import com.didiglobal.booster.transform.asm.className
Expand Down Expand Up @@ -44,12 +46,15 @@ import java.util.concurrent.Future
import java.util.concurrent.TimeUnit
import java.util.concurrent.atomic.AtomicInteger
import javax.xml.parsers.SAXParserFactory
import kotlin.collections.component1
import kotlin.collections.component2
import kotlin.collections.set
import kotlin.streams.toList

/**
* @author johnsonlee
*/
class Analyser(
class PerformanceAnalyser(
private val providedClasspath: Collection<File>,
private val compileClasspath: Collection<File>,
private val artifacts: ArtifactManager,
Expand Down Expand Up @@ -439,7 +444,7 @@ private val PROPERTY_BLACKLIST = "$PROPERTY_PREFIX.blacklist"

private val PROPERTY_WHITELIST = "$PROPERTY_PREFIX.whitelist"

internal val VALUE_BLACKLIST = Analyser::class.java.classLoader.getResource("blacklist.txt")!!.toString()
internal val VALUE_BLACKLIST = PerformanceAnalyser::class.java.classLoader.getResource("blacklist.txt")!!.toString()

internal val VALUE_WHITELIST = Analyser::class.java.classLoader.getResource("whitelist.txt")!!.toString()
internal val VALUE_WHITELIST = PerformanceAnalyser::class.java.classLoader.getResource("whitelist.txt")!!.toString()

Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package com.didiglobal.booster.task.analyser
package com.didiglobal.booster.task.analyser.performance

import com.android.build.gradle.api.BaseVariant
import com.didiglobal.booster.gradle.extension
import com.didiglobal.booster.kotlinx.file
import com.didiglobal.booster.task.analyser.Build
import com.didiglobal.booster.transform.artifacts
import org.gradle.api.DefaultTask
import org.gradle.api.tasks.Input
Expand All @@ -11,11 +12,11 @@ import org.gradle.api.tasks.TaskAction
import java.io.File

/**
* Represents a task for performance profiling
* Represents a task for performance analysing
*
* @author johnsonlee
*/
open class AnalyserTask : DefaultTask() {
open class PerformanceAnalysisTask : DefaultTask() {

@get:Internal
lateinit var variant: BaseVariant
Expand All @@ -28,7 +29,7 @@ open class AnalyserTask : DefaultTask() {
get() = variant.name

@TaskAction
fun profile() {
fun analyse() {
val classpath = supplier().let {
if (it.isDirectory) {
it.listFiles()?.toList() ?: emptyList()
Expand All @@ -43,7 +44,7 @@ open class AnalyserTask : DefaultTask() {

val output = project.projectDir.file("build", "reports", Build.ARTIFACT, variant.dirName)

Analyser(variant.extension.bootClasspath, classpath, variant.artifacts, project.properties).analyse(output)
PerformanceAnalyser(variant.extension.bootClasspath, classpath, variant.artifacts, project.properties).analyse(output)
}

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.didiglobal.booster.task.analyser
package com.didiglobal.booster.task.analyser.performance

import com.android.build.api.transform.QualifiedContent
import com.android.build.gradle.api.BaseVariant
Expand All @@ -14,7 +14,7 @@ import org.gradle.api.GradleException
* @author johnsonlee
*/
@AutoService(VariantProcessor::class)
class AnalyserVariantProcessor : VariantProcessor {
class PerformanceAnalysisVariantProcessor : VariantProcessor {

override fun process(variant: BaseVariant) {
val project = variant.project
Expand All @@ -28,7 +28,7 @@ class AnalyserVariantProcessor : VariantProcessor {
project.tasks.withType(TransformTask::class.java).find {
it.name.endsWith(variantName) && it.transform == transform
}?.let { transformTask ->
val profile = project.tasks.create("analyse${variantName}", AnalyserTask::class.java) {
val profile = project.tasks.create("analyse${variantName}", PerformanceAnalysisTask::class.java) {
it.variant = variant
it.supplier = {
transformTask.outputs.files.single()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.didiglobal.booster.task.analyser
package com.didiglobal.booster.task.analyser.performance

import com.didiglobal.booster.cha.graph.CallNode

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.didiglobal.booster.task.analyser.reference

internal const val DEFAULT_VARIANT = ""

internal const val TASK_ANALYSE_REFERENCE = "analyseReference"

internal const val TASK_CREATE_FULL_JAR = "createFullJar"
Loading

0 comments on commit 1d21e4c

Please sign in to comment.