JMH Benchmarking with Buck

151 views
Skip to first unread message

Nathan Fisher

unread,
Sep 15, 2017, 9:23:55 PM9/15/17
to Buck
Hi All,

Curious if anyone is using Buck with the JMH benchmark suite and what you've done to make it work.

I'm new to using JMH and it looks like they have an annotation processor that is expected to be run with javac during compilation. This in turn generates a file called "META-INF/BenchmarkList" (amongst others) which is needed by JMH.

I've placed the benchmarks in their own module and have the following BUCK build targets:

java_library(
name = 'lib',
srcs = glob(['src/**/*.java']),
deps = ['//compiler:lib','//lib:jcsp', '//lib:jmh-core',],
provided_deps = ['//lib:jmh-generator-annprocess',],
visibility = ['PUBLIC'],
)

java_binary(
name = 'main',
main_class = 'ca.junctionbox.cljbuck.lexer.benchmarks.LexerBenchmark',
deps = [':lib',],
)

Turning verbosity up to 10 I see the following line in my build:

javac -source 8 -target 8 -sourcepath  -g -verbose -d /Users/nathanfisher/workspace/cljbuck/buck-out/bin/benchmarks/lib__lib__classes -classpath /Users/nathanfisher/workspace/cljbuck/buck-out/gen/compiler/lib__lib__output/lib.jar:/Users/nathanfisher/workspace/cljbuck/buck-out/gen/lib/__jcsp__/jcsp-1.1-rc5.jar:/Users/nathanfisher/workspace/cljbuck/buck-out/gen/lib/__jmh-core__/jmh-core-1.19.jar:/Users/nathanfisher/workspace/cljbuck/buck-out/gen/lib/__jmh-generator-annprocess__/jmh-generator-annprocess-1.19.jar @buck-out/gen/benchmarks/__lib__srcs


Based on the above jmh-generator-annprocess jar is being included in the class path. However "unzip -t main.jar | grep META-INF" on the generated java binary seems to indicate that the JMH artefacts aren't included.

Running javac from the command line manually generates the expected JMH artefacts. Is there anyway to tell BUCK to include them?

I'm leaning towards a genrule + zip but was hoping for something better.

Cheerio!
Nathan

Sergey Tyurin

unread,
Nov 16, 2017, 1:17:26 AM11/16/17
to Buck
You need to register an annotation processor. Try the following:

java_annotation_processor(
    name
= 'jmh-generator-ann',
    processor_class
= 'org.openjdk.jmh.generators.BenchmarkProcessor',
    visibility
= [ "PUBLIC", ],

    deps
= ['//lib:jmh-generator-annprocess',],
)


java_library
(
 name
= 'lib',
 srcs
= glob(['src/**/*.java']),

 deps
= ['//compiler:lib','//lib:jcsp', '//lib:jmh-core',], plugins = [":jmh-generator-ann"],
Reply all
Reply to author
Forward
0 new messages