blob: a55fb037ccc43a85669e1940ba4c883543c01bf4 [file] [log] [blame]
Paul Duffine2363012015-11-30 16:20:41 +00001/*
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
17package com.google.caliper.runner;
18
19import com.google.caliper.config.CaliperConfig;
20import com.google.caliper.config.InvalidConfigurationException;
21import com.google.caliper.config.VmConfig;
22import com.google.caliper.model.Run;
23import com.google.caliper.options.CaliperOptions;
24import com.google.caliper.platform.Platform;
25import com.google.common.collect.ImmutableSet;
26
27import dagger.Module;
28import dagger.Provides;
29
30import org.joda.time.Instant;
31
32import java.util.UUID;
33
34import 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
41final class RunnerModule {
42 @Provides
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
62 static Instant provideInstant() {
63 return Instant.now();
64 }
65
66 @Provides static CaliperRun provideCaliperRun(ExperimentingCaliperRun experimentingCaliperRun) {
67 return experimentingCaliperRun;
68 }
69
70 @Provides @Singleton
71 static Run provideRun(UUID uuid, CaliperOptions caliperOptions, Instant startTime) {
72 return new Run.Builder(uuid).label(caliperOptions.runName()).startTime(startTime).build();
73 }
74}