@Inject void setOptions(@InstrumentOptions ImmutableMap<String, String> options) { this.options = ImmutableMap.copyOf( Maps.filterKeys(options, Predicates.in(instrumentOptions()))); }
@Override public String apply(Instrument instrument) { return instrument.name(); } }));
.addAll(super.getExtraCommandLineArgs())
final InstrumentSpec getSpec() { return new InstrumentSpec.Builder() .instrumentClass(getClass()) .addAllOptions(options()) .build(); }
@Provides ImmutableSet<Instrumentation> provideInstrumentations(CaliperOptions options, BenchmarkClass benchmarkClass, ImmutableSet<Instrument> instruments) throws InvalidBenchmarkException { ImmutableSet.Builder<Instrumentation> builder = ImmutableSet.builder(); ImmutableSet<String> benchmarkMethodNames = options.benchmarkMethodNames(); for (Instrument instrument : instruments) { for (Method method : findAllBenchmarkMethods(benchmarkClass.benchmarkClass(), instrument)) { if (benchmarkMethodNames.isEmpty() || benchmarkMethodNames.contains(method.getName())) { builder.add(instrument.createInstrumentation(method)); } } } return builder.build(); }
@Override public Trial newTrial(VmDataCollectingVisitor dataCollectingVisitor, MeasurementCollectingVisitor measurementCollectingVisitor) { checkState(measurementCollectingVisitor.isDoneCollecting()); return new Trial.Builder(trialId) .run(run) .instrumentSpec(experiment.instrumentation().instrument().getSpec()) .scenario(new Scenario.Builder() .host(host) .vmSpec(dataCollectingVisitor.vmSpec()) .benchmarkSpec(benchmarkSpec)) .addAllMeasurements(measurementCollectingVisitor.getMeasurements()) .build(); } };
private static ImmutableSortedSet<Method> findAllBenchmarkMethods(Class<?> benchmarkClass, Instrument instrument) throws InvalidBenchmarkException { ImmutableSortedSet.Builder<Method> result = ImmutableSortedSet.orderedBy( Ordering.natural().onResultOf(new Function<Method, String>() { @Override public String apply(Method method) { return method.getName(); } })); Set<String> benchmarkMethodNames = new HashSet<String>(); Set<String> overloadedMethodNames = new TreeSet<String>(); for (Method method : benchmarkClass.getDeclaredMethods()) { if (instrument.isBenchmarkMethod(method)) { method.setAccessible(true); result.add(method); if (!benchmarkMethodNames.add(method.getName())) { overloadedMethodNames.add(method.getName()); } } } if (!overloadedMethodNames.isEmpty()) { throw new InvalidBenchmarkException( "Overloads are disallowed for benchmark methods, found overloads of %s in benchmark %s", overloadedMethodNames, benchmarkClass); } return result.build(); } }
@Provides @TrialScoped TrialSchedulingPolicy provideTrialSchedulingPolicy(Experiment experiment) { return experiment.instrumentation().instrument().schedulingPolicy(); }
.addAll(super.getExtraCommandLineArgs())
final InstrumentSpec getSpec() { return new InstrumentSpec.Builder() .instrumentClass(getClass()) .addAllOptions(options()) .build(); }
@Provides ImmutableSet<Instrumentation> provideInstrumentations(CaliperOptions options, BenchmarkClass benchmarkClass, ImmutableSet<Instrument> instruments) throws InvalidBenchmarkException { ImmutableSet.Builder<Instrumentation> builder = ImmutableSet.builder(); ImmutableSet<String> benchmarkMethodNames = options.benchmarkMethodNames(); Set<String> unusedBenchmarkNames = new HashSet<String>(benchmarkMethodNames); for (Instrument instrument : instruments) { for (Method method : findAllBenchmarkMethods(benchmarkClass.benchmarkClass(), instrument)) { if (benchmarkMethodNames.isEmpty() || benchmarkMethodNames.contains(method.getName())) { builder.add(instrument.createInstrumentation(method)); unusedBenchmarkNames.remove(method.getName()); } } } if (!unusedBenchmarkNames.isEmpty()) { throw new InvalidBenchmarkException( "Invalid benchmark method(s) specified in options: " + unusedBenchmarkNames); } return builder.build(); }
@Override public TrialResult newTrialResult( VmDataCollectingVisitor dataCollectingVisitor, MeasurementCollectingVisitor measurementCollectingVisitor) { checkState(measurementCollectingVisitor.isDoneCollecting()); // TODO(lukes): should the trial messages be part of the Trial datastructure? It seems like // the web UI could make use of them. return new TrialResult( new Trial.Builder(trialId) .run(run) .instrumentSpec(experiment.instrumentation().instrument().getSpec()) .scenario(new Scenario.Builder() .host(host) .vmSpec(dataCollectingVisitor.vmSpec()) .benchmarkSpec(benchmarkSpec)) .addAllMeasurements(measurementCollectingVisitor.getMeasurements()) .build(), experiment, measurementCollectingVisitor.getMessages()); } };
private static ImmutableSortedSet<Method> findAllBenchmarkMethods(Class<?> benchmarkClass, Instrument instrument) throws InvalidBenchmarkException { ImmutableSortedSet.Builder<Method> result = ImmutableSortedSet.orderedBy( Ordering.natural().onResultOf(new Function<Method, String>() { @Override public String apply(Method method) { return method.getName(); } })); // use a TreeMultiset so iteration order is consistent no matter what order methods are added. Multiset<String> benchmarkMethodNames = TreeMultiset.create(); for (Method method : benchmarkClass.getDeclaredMethods()) { if (instrument.isBenchmarkMethod(method)) { method.setAccessible(true); result.add(method); benchmarkMethodNames.add(method.getName()); } } // remove all benchmark methods with unique names (i.e. counts of 1) Multisets.removeOccurrences(benchmarkMethodNames, HashMultiset.create(benchmarkMethodNames.elementSet())); if (!benchmarkMethodNames.isEmpty()) { throw new InvalidBenchmarkException( "Overloads are disallowed for benchmark methods, found overloads of %s in benchmark %s", benchmarkMethodNames.elementSet(), benchmarkClass); } return result.build(); } }
@Override public String apply(Instrument instrument) { return instrument.name(); } }));
Iterable<String> instrumentJvmOptions = instrument.getExtraCommandLineArgs(); Iterables.addAll(args, instrumentJvmOptions); logger.fine(String.format("Instrument(%s) Java args: %s", instrument.getClass().getName(),
@Inject void setOptions(@InstrumentOptions ImmutableMap<String, String> options) { this.options = ImmutableMap.copyOf( Maps.filterKeys(options, Predicates.in(instrumentOptions()))); }
@Override public String toString() { return name(); }
Iterable<String> instrumentJvmOptions = instrument.getExtraCommandLineArgs(); Iterables.addAll(args, instrumentJvmOptions); logger.fine(String.format("Instrument(%s) Java args: %s", instrument.getClass().getName(),
@Override public String toString() { return name(); }