public static ExperimentModule forWorkerSpec(WorkerSpec spec) throws ClassNotFoundException { Class<?> benchmarkClass = Class.forName(spec.benchmarkSpec.className()); Method benchmarkMethod = findBenchmarkMethod(benchmarkClass, spec.benchmarkSpec.methodName(), spec.methodParameterClassNames); benchmarkMethod.setAccessible(true); return new ExperimentModule(benchmarkClass, benchmarkMethod, spec.benchmarkSpec.parameters()); }
@Override protected void configure() { binder().requireExplicitBindings(); bind(benchmarkClass); // TypeListener doesn't fire without this bind(Object.class).annotatedWith(Running.Benchmark.class).to(benchmarkClass); bindConstant().annotatedWith(Running.BenchmarkMethod.class).to(benchmarkMethod.getName()); bind(Method.class).annotatedWith(Running.BenchmarkMethod.class).toInstance(benchmarkMethod); bindListener(new BenchmarkTypeMatcher(), new BenchmarkParameterInjector()); }
private static Method findBenchmarkMethod(Class<?> benchmark, String methodName, ImmutableList<String> methodParameterClassNames) { // Annoyingly Class.forName doesn't work for primitives so we can't convert these classnames // back into Class objects in order to call getDeclaredMethod(String, Class<?>...classes). // Instead we just match on names which should be just as unique. Method found = null; for (Method method : benchmark.getDeclaredMethods()) { if (method.getName().equals(methodName)) { if (methodParameterClassNames.equals(toClassNames(method.getParameterTypes()))) { if (found == null) { found = method; } else { throw new AssertionError(String.format( "Found two methods named %s with the same list of parameters: %s", methodName, methodParameterClassNames)); } } } } if (found == null) { throw new AssertionError(String.format( "Could not find method %s in class %s with these parameters %s", methodName, benchmark, methodParameterClassNames)); } return found; }
public static ExperimentModule forExperiment(Experiment experiment) { Method benchmarkMethod = experiment.instrumentation().benchmarkMethod(); return new ExperimentModule(benchmarkMethod.getDeclaringClass(), benchmarkMethod, experiment.userParameters()); }
Class<?> clazz = benchmarkClass.benchmarkClass(); try { Object benchmark = injector.createChildInjector(ExperimentModule.forExperiment(experiment)) .getInstance(Key.get(clazz)); benchmarkClass.setUpBenchmark(benchmark);
ExperimentModule.forWorkerSpec(request), new BridgeModule(), new WorkerModule(request));
public static ExperimentModule forExperiment(Experiment experiment) { Method benchmarkMethod = experiment.instrumentation().benchmarkMethod(); return new ExperimentModule(benchmarkMethod.getDeclaringClass(), benchmarkMethod, experiment.userParameters()); }
Class<?> clazz = benchmarkClass.benchmarkClass(); try { Object benchmark = injector.createChildInjector(ExperimentModule.forExperiment(experiment)) .getInstance(Key.get(clazz)); benchmarkClass.setUpBenchmark(benchmark);
new BenchmarkClassModule(Class.forName(request.benchmarkSpec.className())), new BridgeModule(), ExperimentModule.forWorkerSpec(request), new WorkerModule(request)); Worker worker = workerInjector.getInstance(Worker.class);
@Override protected void configure() { binder().requireExplicitBindings(); bind(benchmarkClass); // TypeListener doesn't fire without this bind(Object.class).annotatedWith(Running.Benchmark.class).to(benchmarkClass); bindConstant().annotatedWith(Running.BenchmarkMethod.class).to(benchmarkMethod.getName()); bind(Method.class).annotatedWith(Running.BenchmarkMethod.class).toInstance(benchmarkMethod); bindListener(new BenchmarkTypeMatcher(), new BenchmarkParameterInjector()); }
public static ExperimentModule forWorkerSpec(WorkerSpec spec) throws ClassNotFoundException { Class<?> benchmarkClass = Class.forName(spec.benchmarkSpec.className()); Method benchmarkMethod = findBenchmarkMethod(benchmarkClass, spec.benchmarkSpec.methodName(), spec.methodParameterClasses); benchmarkMethod.setAccessible(true); return new ExperimentModule(benchmarkClass, benchmarkMethod, spec.benchmarkSpec.parameters()); }