Ejemplo n.º 1
0
  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));
  }
Ejemplo n.º 2
0
 public static ExperimentModule forWorkerSpec(WorkerSpec spec) throws ClassNotFoundException {
   Class<?> benchmarkClass = Util.loadClass(spec.benchmarkSpec.className());
   Method benchmarkMethod =
       findBenchmarkMethod(
           benchmarkClass, spec.benchmarkSpec.methodName(), spec.methodParameterClasses);
   benchmarkMethod.setAccessible(true);
   return new ExperimentModule(benchmarkMethod, spec.benchmarkSpec.parameters());
 }
Ejemplo n.º 3
0
  @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();
  }