0

I'm trying to get Caliper working with maven, I haven't successfully ran a caliper benchmark test as of yet.

Caliper version: 1.0-beta-1

My benchmark:

public class MyXercesSAXHandlerBenchmark extends Benchmark{

    @Param({"10", "100", "1000", "10000"}) private int length;


    public void timeNanoTime(int reps) {
        for (int i = 0; i < reps; i++) {
            System.nanoTime();
        }
    }

    public static void main(String[] args) {
        CaliperMain.main(MyXercesSAXHandlerBenchmark.class, args);
    }
}

My maven pom.xml has:

<profiles>
    <profile>
        <id>benchmarks</id>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>exec-maven-plugin</artifactId>
                    <version>1.1</version>
                    <executions>
                        <execution>
                            <id>caliper</id>
                            <phase>compile</phase>
                            <goals>
                                <goal>java</goal>
                            </goals>
                            <configuration>
                                <classpathScope>test</classpathScope>
                                <mainClass>my.path.to.benchmark.MyXercesSAXHandlerBenchmark</mainClass>
                                <arguments>


                                </arguments>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </profile>
</profiles>

I ran:

mvn clean install mvn compile -P benchmarks -e -X

Caused by: org.apache.maven.plugin.MojoExecutionException: An exception occured while executing the Java class. The specified mainClass doesn't contain a main method with appropriate signature.
    at org.codehaus.mojo.exec.ExecJavaMojo.execute(ExecJavaMojo.java:345)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
    ... 19 more
Caused by: java.lang.Exception: The specified mainClass doesn't contain a main method with appropriate signature.
    at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:294)
    at java.lang.Thread.run(Thread.java:680)
Caused by: java.lang.NoSuchMethodException: com.google.caliper.runner.CaliperMain.main([Ljava.lang.String;)
    at java.lang.Class.getMethod(Class.java:1632)
    at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:283)
    ... 1 more
Blankman
  • 259,732
  • 324
  • 769
  • 1,199
  • You've defined `com.google.caliper.runner.CaliperMain` in Maven but post the main method inside `MyXercesSAXHandlerBenchmark`?! – Roman Vottner Jan 12 '14 at 02:12
  • I changed the main class to my main class and now I get: `Caused by: java.lang.ClassNotFoundException:` – Blankman Jan 12 '14 at 02:41
  • can you update your post accordingly? – Roman Vottner Jan 12 '14 at 02:43
  • I have updated my question with the change in my pom. – Blankman Jan 12 '14 at 02:46
  • and the exception? which class was maven not able to find? `MyXercesSAXHandlerBenchmark`? or Caliper? – Roman Vottner Jan 12 '14 at 02:52
  • `caused by: java.lang.ClassNotFoundException: path.to.my.MyXercesSAXHandlerBenchmark` It seems it just can't find the class, why would it not be visible? – Blankman Jan 12 '14 at 02:56
  • My benchmark code is inside of /src/test/java/... could that be the reason it can't see it? Does the compile phase include the test? – Blankman Jan 12 '14 at 03:04
  • and `path.to.my....` is the fully qualified class name? (= the package name + class name (each separated by a `.`)). As you are compiling the code via maven, it should be able to find the .class files of your main class. Maybe the phase compile could be problematic? Try setting it to test. Moreover, [SO offers a few examples](http://stackoverflow.com/questions/2472376/how-do-i-execute-a-program-using-maven) on how it can be configured. From what I know `test` should take the classes generated from `src/test/java` – Roman Vottner Jan 12 '14 at 03:12
  • Ok looks like that was one issue, now it can't find a jar `ava.lang.IllegalStateException: Can't find required allocationinstrumenter agent jar` I added the artifact `java-allocation-instrumenter` with test scope but still dont' work. – Blankman Jan 12 '14 at 03:50

1 Answers1

0

The maven-exec-plugin doesn't work with 1.0-beta-1. You need to build caliper from a revision later than 6d05814727e8b119651247952dedf4ab321d890a - HEAD, of course, works.

gk5885
  • 3,742
  • 21
  • 16
  • So I build and referenced the revision 6d058, but I still see the error `java.lang.IllegalStateException: Can't find required allocationinstrumenter agent jar`. – Blankman Jan 13 '14 at 01:31
  • That happens when Caliper can't find https://code.google.com/p/java-allocation-instrumenter/ on the classpath. It is a transitive dependency of Caliper, so you should have it automatically. I'm not sure what's happening with your classpath management to have it go missing. You can set it manually using the flag -Cinstrument.allocation.options.allocationAgentJar=/path/to/the.jar if you can't resolve the dependency management issues. – gk5885 Jan 17 '14 at 21:33