aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build
diff options
context:
space:
mode:
authorGravatar Klaus Aehlig <aehlig@google.com>2016-04-07 10:35:03 +0000
committerGravatar Lukacs Berki <lberki@google.com>2016-04-07 11:51:52 +0000
commitec3dd7c6aa3ec1dee345ce1d1b60acacdb67acad (patch)
tree61fd8a854cb1e21f6a47c1c0618f3ebe74782962 /src/main/java/com/google/devtools/build
parentc644c4178cdd45f7ce01d2d657b41b5e0ec23cc9 (diff)
Add a LoadingProgressReceiver class
Instances of this class keep track of the packages already loaded and those currently being loaded. This information can be useful for UIs. -- Change-Id: Ifd380dd2129d11181ad4a31ecbb71d142825df61 Reviewed-on: https://bazel-review.googlesource.com/#/c/3267 MOS_MIGRATED_REVID=119252784
Diffstat (limited to 'src/main/java/com/google/devtools/build')
-rw-r--r--src/main/java/com/google/devtools/build/lib/skyframe/LoadingProgressReceiver.java76
1 files changed, 76 insertions, 0 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/LoadingProgressReceiver.java b/src/main/java/com/google/devtools/build/lib/skyframe/LoadingProgressReceiver.java
new file mode 100644
index 0000000000..4a828b3cb3
--- /dev/null
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/LoadingProgressReceiver.java
@@ -0,0 +1,76 @@
+// Copyright 2016 The Bazel Authors. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+package com.google.devtools.build.lib.skyframe;
+
+import com.google.common.base.Supplier;
+import com.google.common.collect.Sets;
+import com.google.devtools.build.skyframe.EvaluationProgressReceiver;
+import com.google.devtools.build.skyframe.SkyKey;
+import com.google.devtools.build.skyframe.SkyValue;
+
+import java.util.ArrayDeque;
+import java.util.Deque;
+import java.util.Set;
+
+/**
+ * An {@link EvaluationProgressReceiver} used during loading phase
+ *
+ * It receives updates about progress in the loading phase via the
+ * {@link EvaluationProgressReceiver} interface. These updates get aggregated
+ * and a summary of the current state of the loading phase can be obtained via
+ * and provides a summary about the current state via the {@link #progressState}
+ * method.
+ */
+public class LoadingProgressReceiver implements EvaluationProgressReceiver {
+
+ private final Set<SkyKey> enqueuedPackages = Sets.newConcurrentHashSet();
+ private final Set<SkyKey> completedPackages = Sets.newConcurrentHashSet();
+ private final Deque<SkyKey> pending = new ArrayDeque<>();
+
+ @Override
+ public void invalidated(SkyKey skyKey, InvalidationState state) {}
+
+ @Override
+ public synchronized void enqueueing(SkyKey skyKey) {
+ if (skyKey.functionName().equals(SkyFunctions.PACKAGE)) {
+ enqueuedPackages.add(skyKey);
+ pending.addLast(skyKey);
+ }
+ }
+
+ @Override
+ public void computed(SkyKey skyKey, long elapsedTimeNanos) {}
+
+ @Override
+ public synchronized void evaluated(
+ SkyKey skyKey, Supplier<SkyValue> valueSupplier, EvaluationState state) {
+ if (skyKey.functionName().equals(SkyFunctions.PACKAGE)) {
+ completedPackages.add(skyKey);
+ pending.remove(skyKey);
+ }
+ }
+
+ public synchronized String progressState() {
+ long completed = completedPackages.size();
+ long enqueued = enqueuedPackages.size();
+ String answer = "" + completed + " / " + enqueued;
+ if (enqueued > completed) {
+ answer += " " + pending.peekFirst().toString();
+ if (enqueued > completed + 1) {
+ answer += " ...";
+ }
+ }
+ return answer;
+ }
+}