22 Mai 2016

Recently we where running into strange OutOfMemoryErrors while Gradle was executing our integration tests. In order to get a better insight on whats going wrong we decided let Java Flightrecorder profile the test execution.

All you need to do is to but the following snippet into your build.gradle. This will enable Flightrecorder and it will record the whole test execution and writes the result to a file called build/dumponexit.jfr.

test {
      maxHeapSize = "2g"
      jvmArgs += ["-XX:+UnlockCommercialFeatures", "-XX:+FlightRecorder"]

      def jfrOptions = [
              defaultrecording: true,
              dumponexit      : true,
              dumponexitpath  : "${project.buildDir}/dumponexit.jfr",
              globalbuffersize: '10M',
              disk            : true,
              settings        : "${System.getProperty("java.home")}/lib/jfr/profile.jfc".toString()
      ]
      jvmArgs += ["-XX:FlightRecorderOptions=${jfrOptions.collect { k, v -> "$k=$v".toString() }.join(',')}"]
  }

Hope that blog post helps.


Tags: java, gradle, flightrecorder