• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2012 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.google.caliper.runner;
18 
19 import com.google.caliper.config.CaliperConfig;
20 import com.google.caliper.config.InvalidConfigurationException;
21 import com.google.caliper.config.VmConfig;
22 import com.google.caliper.model.Run;
23 import com.google.caliper.options.CaliperOptions;
24 import com.google.caliper.platform.Platform;
25 import com.google.common.collect.ImmutableSet;
26 
27 import dagger.Module;
28 import dagger.Provides;
29 
30 import org.joda.time.Instant;
31 
32 import java.util.UUID;
33 
34 import javax.inject.Singleton;
35 
36 /**
37  * A Dagger module that configures bindings common to all {@link CaliperRun} implementations.
38  */
39 // TODO(gak): throwing providers for all of the things that throw
40 @Module
41 final class RunnerModule {
42   @Provides
provideVirtualMachines( CaliperOptions options, CaliperConfig config, Platform platform)43   static ImmutableSet<VirtualMachine> provideVirtualMachines(
44       CaliperOptions options,
45       CaliperConfig config,
46       Platform platform)
47       throws InvalidConfigurationException {
48     ImmutableSet<String> vmNames = options.vmNames();
49     ImmutableSet.Builder<VirtualMachine> builder = ImmutableSet.builder();
50     if (vmNames.isEmpty()) {
51       builder.add(new VirtualMachine("default", config.getDefaultVmConfig(platform)));
52     } else {
53       for (String vmName : vmNames) {
54         VmConfig vmConfig = config.getVmConfig(platform, vmName);
55         builder.add(new VirtualMachine(vmName, vmConfig));
56       }
57     }
58     return builder.build();
59   }
60 
61   @Provides
provideInstant()62   static Instant provideInstant() {
63     return Instant.now();
64   }
65 
provideCaliperRun(ExperimentingCaliperRun experimentingCaliperRun)66   @Provides static CaliperRun provideCaliperRun(ExperimentingCaliperRun experimentingCaliperRun) {
67     return experimentingCaliperRun;
68   }
69 
70   @Provides @Singleton
provideRun(UUID uuid, CaliperOptions caliperOptions, Instant startTime)71   static Run provideRun(UUID uuid, CaliperOptions caliperOptions, Instant startTime) {
72     return new Run.Builder(uuid).label(caliperOptions.runName()).startTime(startTime).build();
73   }
74 }
75