Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate compose compiler metrics and reports #1576

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,11 @@ Then copy the resulting baseline profile from the emulator to [`app/src/main/bas
Run the following command to get and analyse compose compiler metrics:

```bash
./gradlew assembleRelease -PenableComposeCompilerMetrics=true -PenableComposeCompilerReports=true
./gradlew assembleRelease -PenableComposeCompilerReportsAndMetrics=true --rerun-tasks
```

The reports files will be added to [build/compose-reports](build/compose-reports). The metrics files will also be
added to [build/compose-metrics](build/compose-metrics).
The reports files will be added to ***build/module-name/compose-reports***. The metrics files will also be
added to ***build/module-name/compose-metrics***.

For more information on Compose compiler metrics, see [this blog post](https://medium.com/androiddevelopers/jetpack-compose-stability-explained-79c10db270c8).

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package com.google.samples.apps.nowinandroid

import com.android.build.api.dsl.CommonExtension
import org.gradle.api.Project
import org.gradle.api.provider.Provider
import org.gradle.kotlin.dsl.assign
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.dependencies
Expand Down Expand Up @@ -52,21 +51,14 @@ internal fun Project.configureAndroidCompose(
}

extensions.configure<ComposeCompilerGradlePluginExtension> {
fun Provider<String>.onlyIfTrue() = flatMap { provider { it.takeIf(String::toBoolean) } }
fun Provider<*>.relativeToRootProject(dir: String) = flatMap {
rootProject.layout.buildDirectory.dir(projectDir.toRelativeString(rootDir))
}.map { it.dir(dir) }

project.providers.gradleProperty("enableComposeCompilerMetrics").onlyIfTrue()
.relativeToRootProject("compose-metrics")
.let(metricsDestination::set)
if (isPropertyValueIsTrue("enableComposeCompilerReportsAndMetrics")) {
metricsDestination = relativeToRootProject("compose-metrics")
reportsDestination = relativeToRootProject("compose-reports")
}

project.providers.gradleProperty("enableComposeCompilerReports").onlyIfTrue()
.relativeToRootProject("compose-reports")
.let(reportsDestination::set)
stabilityConfigurationFile =
rootProject.layout.projectDirectory.file("compose_compiler_config.conf")

stabilityConfigurationFile = rootProject.layout.projectDirectory.file("compose_compiler_config.conf")

enableStrongSkippingMode = true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,22 @@ package com.google.samples.apps.nowinandroid
import org.gradle.api.Project
import org.gradle.api.artifacts.VersionCatalog
import org.gradle.api.artifacts.VersionCatalogsExtension
import org.gradle.api.file.Directory
import org.gradle.api.provider.Provider
import org.gradle.kotlin.dsl.getByType

val Project.libs
get(): VersionCatalog = extensions.getByType<VersionCatalogsExtension>().named("libs")

/**
* Create new Directory by [dir] name in the root build directory.
*/
internal fun Project.relativeToRootProject(dir: String): Provider<Directory> =
rootProject.layout.buildDirectory.dir(projectDir.toRelativeString(rootDir))
.map { it.dir(dir) }

/**
* Check a [propertyName]'s property value is true.
*/
internal fun Project.isPropertyValueIsTrue(propertyName: String): Boolean =
properties[propertyName].toString().toBoolean()