Skip to content
This repository has been archived by the owner on Dec 10, 2020. It is now read-only.

Commit

Permalink
Ensure caliper is shaded in bench, add bench desc, use RUN so that ou…
Browse files Browse the repository at this point in the history
…tput is printed

caliper depends on guava 11 which is incompatible with guavas above 15 due to deprecated method removals, adding main to the jvm tool registration causes it to be shaded, which means the older guava won't interfer with code under test that depends on newer guava versions.

I also added a description and set the WorkUnit.RUN label so that the caliper output will be printed to the console by default.

Testing Done:
tested against a target with a dependency on guava 16, which failed to run without shading. CI in PR

Bugs closed: 1674

Reviewed at https://rbcommons.com/s/twitter/r/2353/
  • Loading branch information
baroquebobcat committed Jun 16, 2015
1 parent 1cf240b commit cb0cc7a
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
6 changes: 3 additions & 3 deletions BUILD.tools
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ jar_library(name = 'cobertura-report',

jar_library(name = 'benchmark-caliper-0.5',
jars = [
# TODO(Eric Ayers) Caliper is old and breaks with guava 16. Add jmh support?
jar(org = 'com.google.caliper', name = 'caliper', rev = '0.5-rc1')
.exclude(org='com.google.guava', name='guava')
# TODO (Eric Ayers) Caliper is old. Add jmh support?
# The caliper tool is shaded, and so shouldn't interfere with Guava 16.
jar(org = 'com.google.caliper', name = 'caliper', rev = '0.5-rc1'),
])

jar_library(name = 'benchmark-java-allocation-instrumenter-2.1',
Expand Down
2 changes: 1 addition & 1 deletion src/python/pants/backend/jvm/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def register_goals():

# Testing.
task(name='junit', action=JUnitRun).install('test').with_description('Test compiled code.')
task(name='bench', action=BenchmarkRun).install('bench')
task(name='bench', action=BenchmarkRun).install('bench').with_description('Run benchmark tests.')

# Running.
task(name='jvm', action=JvmRun, serialize=False).install('run').with_description(
Expand Down
1 change: 1 addition & 0 deletions src/python/pants/backend/jvm/tasks/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ python_library(
':jvm_task',
':jvm_tool_task_mixin',
'src/python/pants/backend/core/tasks:task',
'src/python/pants/base:workunit',
'src/python/pants/java:util',
],
)
Expand Down
13 changes: 8 additions & 5 deletions src/python/pants/backend/jvm/tasks/benchmark_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,19 @@
from pants.backend.jvm.tasks.jvm_task import JvmTask
from pants.backend.jvm.tasks.jvm_tool_task_mixin import JvmToolTaskMixin
from pants.base.exceptions import TaskError
from pants.base.workunit import WorkUnit
from pants.java.util import execute_java


class BenchmarkRun(JvmTask, JvmToolTaskMixin):
_CALIPER_MAIN = 'com.google.caliper.Runner'

@classmethod
def register_options(cls, register):
super(BenchmarkRun, cls).register_options(register)
register('--target', help='Name of the benchmark class. This is a mandatory argument.')
register('--memory', default=False, action='store_true', help='Enable memory profiling.')
cls.register_jvm_tool(register, 'benchmark-tool', default=['//:benchmark-caliper-0.5'])
cls.register_jvm_tool(register, 'benchmark-tool', main=cls._CALIPER_MAIN, default=['//:benchmark-caliper-0.5'])
cls.register_jvm_tool(register, 'benchmark-agent',
default=['//:benchmark-java-allocation-instrumenter-2.1'])

Expand Down Expand Up @@ -65,12 +68,12 @@ def execute(self):

classpath = self.classpath(self.context.targets(), benchmark_tools_classpath)

caliper_main = 'com.google.caliper.Runner'
exit_code = execute_java(classpath=classpath,
main=caliper_main,
main=self._CALIPER_MAIN,
jvm_options=self.jvm_options,
args=self.args,
workunit_factory=self.context.new_workunit,
workunit_name='caliper')
workunit_name='caliper',
workunit_labels=[WorkUnit.RUN])
if exit_code != 0:
raise TaskError('java {} ... exited non-zero ({})'.format(caliper_main, exit_code))
raise TaskError('java {} ... exited non-zero ({})'.format(self._CALIPER_MAIN, exit_code))

0 comments on commit cb0cc7a

Please sign in to comment.