@Provides static ImmutableSet<Instrument> provideInstruments( CaliperOptions options, final CaliperConfig config, Map<Class<? extends Instrument>, Provider<Instrument>> availableInstruments, Platform platform, @Stderr PrintWriter stderr) throws InvalidCommandException { ImmutableSet.Builder<Instrument> builder = ImmutableSet.builder(); ImmutableSet<String> configuredInstruments = config.getConfiguredInstruments(); for (final String instrumentName : options.instrumentNames()) { if (!configuredInstruments.contains(instrumentName)) { throw new InvalidCommandException( "%s is not a configured instrument (%s). " + "use --print-config to see the configured instruments.", instrumentName, configuredInstruments); } final InstrumentConfig instrumentConfig = config.getInstrumentConfig(instrumentName); String className = instrumentConfig.className(); try { Class<? extends Instrument> clazz = Util.lenientClassForName(className).asSubclass(Instrument.class); Provider<Instrument> instrumentProvider = availableInstruments.get(clazz); if (instrumentProvider == null) { throw new InvalidInstrumentException("Instrument %s not supported", className); } // Make sure that the instrument is supported on the platform. if (platform.supports(clazz)) { Instrument instrument = instrumentProvider.get(); InstrumentInjectorModule injectorModule = new InstrumentInjectorModule(instrumentConfig, instrumentName); InstrumentComponent instrumentComponent = DaggerInstrumentComponent.builder().instrumentInjectorModule(injectorModule).build(); instrumentComponent.injectInstrument(instrument); builder.add(instrument); } else { stderr.format( "Instrument %s not supported on %s, ignoring\n", className, platform.name()); } } catch (ClassNotFoundException e) { throw new InvalidCommandException("Cannot find instrument class '%s'", className); } } return builder.build(); }
@Provides static ImmutableSet<ResultProcessor> provideResultProcessors( CaliperConfig config, Map<Class<? extends ResultProcessor>, Provider<ResultProcessor>> availableProcessors) { ImmutableSet.Builder<ResultProcessor> builder = ImmutableSet.builder(); for (Class<? extends ResultProcessor> processorClass : config.getConfiguredResultProcessors()) { Provider<ResultProcessor> resultProcessorProvider = availableProcessors.get(processorClass); ResultProcessor resultProcessor = resultProcessorProvider == null ? ResultProcessorCreator.createResultProcessor(processorClass) : resultProcessorProvider.get(); builder.add(resultProcessor); } return builder.build(); }
@Provides static ListeningExecutorService provideExecutorService(CaliperConfig config) { int poolSize = Integer.parseInt(config.properties().get(RUNNER_MAX_PARALLELISM_OPTION)); return MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(poolSize)); }