You should be able to do this with the Maven Exec Plugin. For my project, I opted to make a benchmark profile that can be run with the maven command mvn compile -P benchmarks
.
To configure something like this, you can add something along the lines of the following to your pom.xml
, specifying scope of the classpath as test using the <classpathScope>
tag:
<profiles>
<profile>
<id>benchmarks</id>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<id>caliper</id>
<phase>compile</phase>
<goals>
<goal>java</goal>
</goals>
<configuration>
<classpathScope>test</classpathScope>
<mainClass>com.google.caliper.runner.CaliperMain</mainClass>
<commandlineArgs>com.stackoverflow.BencharkClass,com.stackoverflow.AnotherBenchmark</commandlineArgs>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
Alternatively, if you'd like to specify a lot of options for caliper, it is probably easier to use the <arguments>
tags:
<executions>
<execution>
<id>caliper</id>
<phase>compile</phase>
<goals>
<goal>java</goal>
</goals>
<configuration>
<classpathScope>test</classpathScope>
<mainClass>com.google.caliper.runner.CaliperMain</mainClass>
<arguments>
<argument>com.stackoverflow.BencharkClass</argument>
<argument>--instrument</argument>
<argument>runtime</argument>
<argument>-Cinstrument.allocation.options.trackAllocations=false</argument>
</arguments>
</configuration>
</execution>
</executions>
More configuration options (like -Cinstrument.allocation.options.trackAllocations
above) can be found here and more runtime options (like --instrument
above) can be found here.
Then, if you are using the Eclipse m2 Maven plugin, you can right-click on your project folder and select Run as... -> Maven Build...
and enter something like clean install
in the Goals
input box and benchmarks
in the Profiles
input box and click Run
and you should see the output in your Eclipse console.
It's important to note that I used a local snapshot build of Caliper by checking out the source using git clone https://code.google.com/p/caliper/
, which is recommended at the time of this post in order to take advantage of the latest API.