gradle / gradle-profiler

A tool for gathering profiling and benchmarking information for Gradle builds
Apache License 2.0
1.38k stars 156 forks source link

Difficulty Running Android Studio Sync Benchmark in Headless Docker Environment #542

Open denzap opened 6 months ago

denzap commented 6 months ago

Hello,

I am currently working on implementing an automatic benchmark run in our project to compare two builds before and after making any changes. The benchmarking process takes place on our Continuous Integration (CI) platform without a display.

While regular scenarios with Gradle tasks are working fine, I encountered an issue when trying to implement the android-studio-sync scenario. Running sync requires Android Studio, and since it is a GUI application, it needs to be somehow launched in headless mode.

I have attempted to start the studio with -Djava.awt.headless=true and used Xvfb to create a virtual display, but these approaches did not resolve the issue. The benchmark run fails with the error java.lang.IllegalStateException: Timeout waiting for incoming connection from plugin.

Is there currently a way to achieve this idea in a Docker environment with a headless setup?

Thank you for your assistance.

asodja commented 6 months ago

There is a system property flag that can be used-Dstudio.tests.headless=true: https://github.com/gradle/gradle-profiler/blob/2b4653eddf5bf5e0fe0ae6198c912b64c03aa3b7/src/main/java/org/gradle/profiler/studio/launcher/StudioLauncherProvider.java#L19

This flag has to be passed to gradle-profiler Java process.

Note: It's not documented so it's considered internal. So we might change it in the future.

denzap commented 6 months ago

Thank you! That's exactly what I needed.

In case anyone else encounters a similar setup, to ensure that the gradle-profiler --benchmark ... command with the android-studio-sync scenario runs successfully, you need to:

  1. Make sure to add the path to the Android SDK in the local.properties file - sdk.dir=....
  2. To set the system property studio.tests.headless=true, I used export JAVA_TOOL_OPTIONS=-Dstudio.tests.headless=true before running gradle-profiler --benchmark ....
  3. Keep in mind that you won't be able to run the benchmark in headless mode on Android Studio Hedgehog - please use Android Studio Iguana 2023.2.1.15 or newer. https://github.com/gradle/gradle-profiler/issues/517