Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Defining a gradle task to run caliper microbenchmark

This is probably more a Gradle question than a Caliper question, but I am still rather new to Gradle. I am interested in providing a task in my build that can run some benchmarks using Caliper. I have already added Caliper to my testCompile dependencies, and that works and pulls everything down. I would like to know how to provide a task that will actually run the benchmarks.

Btw, I already know about caliper-ci. I do have a Jenkins build, but it's on a cloud service that doesn't yet allow me to configure usage of caliper-ci, and besides, I want to be able to run locally before committing changes to the cloud.

like image 936
Kevin Welker Avatar asked Apr 11 '12 04:04

Kevin Welker


People also ask

What does Gradle use to determine the order in which task can be run?

Gradle determines the subset of the tasks, created and configured during the configuration phase, to be executed. The subset is determined by the task name arguments passed to the gradle command and the current directory. Gradle then executes each of the selected tasks.

Does Gradle build run tests?

By default, Gradle will run all tests that it detects, which it does by inspecting the compiled test classes. This detection uses different criteria depending on the test framework used. For JUnit, Gradle scans for both JUnit 3 and 4 test classes.


1 Answers

It turns out it was a simple case of using JavaExec (I was new to that anyway):

task runBenchmark(type: JavaExec, dependsOn: test) {
    def vmVer = System.getProperty('java.version')
    def osName = System.getProperty('os.name').replaceAll('\\s','')
    def osArch = System.getProperty('os.arch')
    def fnameBase = "ver${version}_${osName}-${osArch}_jvm${vmVer}"
    def benchMarksDir = "${project.buildDir}/benchmarks"
    ant.mkdir(dir: benchMarksDir)
    def outStream = new FileOutputStream("${benchMarksDir}/${fnameBase}-out.txt")
    standardOutput = outStream
    main = 'org.funcito.benchmarks.MyBenchmark'
    classpath = sourceSets.test.runtimeClasspath
    args = ['--saveResults', "${benchMarksDir}/${fnameBase}.json", '-Jmode=-server,-client']
}
like image 77
Kevin Welker Avatar answered Sep 23 '22 15:09

Kevin Welker