public CaliperConfig loadOrCreate() throws InvalidConfigurationException { File configFile = options.caliperConfigFile(); ImmutableMap<String, String> defaults; try { defaults = Util.loadProperties( Util.resourceSupplier(CaliperConfig.class, "global-config.properties")); } catch (IOException impossible) { throw new AssertionError(impossible); } // TODO(kevinb): deal with migration issue from old-style .caliperrc if (configFile.exists()) { try { ImmutableMap<String, String> user = Util.loadProperties(Files.asByteSource(configFile)); return new CaliperConfig(mergeProperties(options.configProperties(), user, defaults)); } catch (IOException keepGoing) { } } ByteSource supplier = Util.resourceSupplier(CaliperConfig.class, "default-config.properties"); tryCopyIfNeeded(supplier, configFile); ImmutableMap<String, String> user; try { user = Util.loadProperties(supplier); } catch (IOException e) { throw new AssertionError(e); // class path must be messed up } return new CaliperConfig(mergeProperties(options.configProperties(), user, defaults)); }
@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<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(); }
@Provides @BenchmarkParameters static ImmutableSetMultimap<String, String> provideBenchmarkParameters( BenchmarkClass benchmarkClass, CaliperOptions options) throws InvalidBenchmarkException { return benchmarkClass.userParameters().fillInDefaultsFor(options.userParameters()); }