This project is designed to help developers learn how to analyze the performance of their Android projects. It demonstrates how to use tools like Build Scan, Gradle Profiler, and VisualVM with the VisualGC plugin to identify performance bottlenecks and improve build times.
- How to generate a complex multi-module Android project.
- How to use Build Scan to understand your build process.
- How to use Gradle Profiler to run performance tests.
- How to use VisualVM and VisualGC to monitor memory usage. (in-progress)
This project uses a script to create a set of modules. You can customize the number of modules and their complexity.
- Open the Project in Android Studio:
- Open Android Studio and select "Open" to open this project.
- Find the Script:
- Go to the
scripts/src/main/kotlin/com/example/oom/scripts/Main.kt
file.
- Go to the
- Run the
main
Function:- In the
Main.kt
file, you'll see amain
function. - Click the green "play" icon next to the
fun main(args: Array<String>)
line. - Select "Run 'MainKt'" from the menu.
- This will run the script and create the modules.
- In the
- Check the
modules
Directory:- After running the script, a new
modules
directory will be created in the root of your project. This directory will contain all the generated modules.
- After running the script, a new
- Open
Main.kt
:- Go to the
scripts/src/main/kotlin/com/example/oom/scripts/Main.kt
file.
- Go to the
- Find the Settings:
- At the top of the file, you'll see some settings:
MODULES_COUNT
: This controls how many modules will be created.MODULES_COMPLEXITY
: This controls how complex the dependencies between modules will be.MODELS_COUNT
: This controls how many models will be created in each module.DAGGER_MODULES_COUNT
: This controls how many Dagger modules will be created in each module.DAGGER_COMPONENTS_COUNT
: This controls how many Dagger components will be created in each module.UNIT_TESTS_COUNT
: This controls how many unit tests will be created in each module.ANDROID_TESTS_COUNT
: This controls how many android tests will be created in each module.ANDROID_RESOURCES_STRINGS_COUNT
: This controls how many strings will be created in each module.ANDROID_RESOURCES_COLORS_COUNT
: This controls how many colors will be created in each module.
- At the top of the file, you'll see some settings:
- Change the Values:
- Change the values of these settings to create more or fewer modules, models, tests, etc.
- For example, to create 8 modules, change
const val MODULES_COUNT = 4
toconst val MODULES_COUNT = 8
.
- Run the Script Again:
- After changing the settings, run the
main
function again to generate the modules with the new settings.
- After changing the settings, run the
Gradle Profiler helps you test how fast your project builds. This project includes some pre-made scenarios.
- Find the Scenarios File:
- Go to the
profiler/performance.scenarios
file. This file contains the scenarios that Gradle Profiler will run.
- Go to the
- Open a Terminal:
- Open a terminal in Android Studio (View -> Tool Windows -> Terminal).
- Run Gradle Profiler:
- Run the following command:
gradle-profiler --benchmark --scenario-file profiler/performance.scenarios
- This will start Gradle Profiler and run the scenarios.
- Run the following command:
- View the Results:
- Gradle Profiler will show you the results in the terminal. It will also create a report in the
profile-out
directory.
- Gradle Profiler will show you the results in the terminal. It will also create a report in the
Build Scan gives you a detailed look at your build process.
- Run a Gradle Build:
- Run any Gradle build task in Android Studio (e.g., "Build Project" or "Make Module").
- Find the Build Scan Link:
- After the build finishes, look at the output in the "Build" window.
- You'll see a message like this:
Publishing build scan... https://gradle.com/s/xxxxxxxxxxxxxx
- The link (
https://gradle.com/s/xxxxxxxxxxxxxx
) is your Build Scan link.
- Open the Link:
- Click on the link to open the Build Scan in your web browser.
- Explore the Build Scan:
- You can explore the build scan to see how long each task took, what dependencies were downloaded, and more.
- Build Scan: A tool to analyze and optimize your Gradle builds.
- Gradle Profiler: A tool to run performance tests on your Gradle builds.
- VisualVM: A tool to monitor the performance of Java applications.
- VisualGC: A VisualVM plugin to monitor garbage collection.
If you have any ideas for improving this project, feel free to open an issue or submit a pull request.
This project is licensed under the MIT License.