Damien Martin-Guillerez | f88f4d8 | 2015-09-25 13:56:55 +0000 | [diff] [blame] | 1 | // Copyright 2014 The Bazel Authors. All rights reserved. |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | package com.google.devtools.build.lib.pkgcache; |
| 15 | |
Ulf Adams | de3e9d5 | 2016-02-10 12:07:44 +0000 | [diff] [blame] | 16 | import com.google.common.base.Preconditions; |
| 17 | import com.google.common.collect.ImmutableSet; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 18 | import com.google.common.collect.Iterables; |
Lukacs Berki | 6e91eb9 | 2015-09-21 09:12:37 +0000 | [diff] [blame] | 19 | import com.google.devtools.build.lib.cmdline.Label; |
Klaus Aehlig | 949b7b5 | 2017-02-27 13:56:15 +0000 | [diff] [blame] | 20 | import com.google.devtools.build.lib.events.ExtendedEventHandler; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 21 | import com.google.devtools.build.lib.packages.Target; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 22 | |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 23 | /** |
| 24 | * This event is fired after the loading phase is complete. |
| 25 | */ |
Klaus Aehlig | 949b7b5 | 2017-02-27 13:56:15 +0000 | [diff] [blame] | 26 | public final class LoadingPhaseCompleteEvent implements ExtendedEventHandler.Postable { |
Ulf Adams | de3e9d5 | 2016-02-10 12:07:44 +0000 | [diff] [blame] | 27 | private final ImmutableSet<Target> targets; |
| 28 | private final ImmutableSet<Target> filteredTargets; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 29 | private final PackageManager.PackageManagerStatistics pkgManagerStats; |
| 30 | private final long timeInMs; |
| 31 | |
| 32 | /** |
| 33 | * Construct the event. |
| 34 | * |
| 35 | * @param targets the set of active targets that remain |
| 36 | * @param pkgManagerStats statistics about the package cache |
| 37 | */ |
Ulf Adams | de3e9d5 | 2016-02-10 12:07:44 +0000 | [diff] [blame] | 38 | public LoadingPhaseCompleteEvent(ImmutableSet<Target> targets, |
| 39 | ImmutableSet<Target> filteredTargets, PackageManager.PackageManagerStatistics pkgManagerStats, |
| 40 | long timeInMs) { |
| 41 | this.targets = Preconditions.checkNotNull(targets); |
| 42 | this.filteredTargets = Preconditions.checkNotNull(filteredTargets); |
| 43 | this.pkgManagerStats = Preconditions.checkNotNull(pkgManagerStats); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 44 | this.timeInMs = timeInMs; |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * @return The set of active targets remaining, which is a subset of the |
| 49 | * targets we attempted to load. |
| 50 | */ |
Ulf Adams | de3e9d5 | 2016-02-10 12:07:44 +0000 | [diff] [blame] | 51 | public ImmutableSet<Target> getTargets() { |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 52 | return targets; |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * @return The set of filtered targets. |
| 57 | */ |
Ulf Adams | de3e9d5 | 2016-02-10 12:07:44 +0000 | [diff] [blame] | 58 | public ImmutableSet<Target> getFilteredTargets() { |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 59 | return filteredTargets; |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * @return The set of active target labels remaining, which is a subset of the |
| 64 | * targets we attempted to load. |
| 65 | */ |
| 66 | public Iterable<Label> getLabels() { |
laurentlb | 3d2a68c | 2017-06-30 00:32:04 +0200 | [diff] [blame] | 67 | return Iterables.transform(targets, Target::getLabel); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | public long getTimeInMs() { |
| 71 | return timeInMs; |
| 72 | } |
| 73 | |
| 74 | /** |
nharmata | c4335cf | 2017-07-18 21:39:13 +0200 | [diff] [blame] | 75 | * Returns package manager statistics. |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 76 | */ |
| 77 | public PackageManager.PackageManagerStatistics getPkgManagerStats() { |
| 78 | return pkgManagerStats; |
| 79 | } |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 80 | } |