aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar jmmv <jmmv@google.com>2017-08-28 21:41:21 +0200
committerGravatar Vladimir Moskva <vladmos@google.com>2017-08-29 13:32:02 +0200
commit59787f15a83b0262ad5c3964db821bfc5c64dbd1 (patch)
tree9238f5f284b92869d78aa3b64a947ef28af610ac /src
parenta6a2b4e7b1c4f276bc256a0a341350ab33cef268 (diff)
Refactor collection of action cache statistics.
This change gets rid of the old CachesSavedEvent object (note, plural) which used to capture details about various caches. As this was now only used for a single cache, rename it to ActionCacheStatistics so that the data it contains is more cohesive. The reason for this change is to make room for the addition of other metrics for the action cache (like hits/misses), which will come later. As of now, this change is intended to be a no-op. While doing this, use AutoValue to avoid mutability of the generated objects and use better types for the contained data (e.g. Duration for timings). RELNOTES: None. PiperOrigin-RevId: 166742117
Diffstat (limited to 'src')
-rw-r--r--src/main/java/com/google/devtools/build/lib/BUILD1
-rw-r--r--src/main/java/com/google/devtools/build/lib/buildtool/ActionCacheStatistics.java44
-rw-r--r--src/main/java/com/google/devtools/build/lib/buildtool/CachesSavedEvent.java39
-rw-r--r--src/main/java/com/google/devtools/build/lib/buildtool/ExecutionTool.java23
4 files changed, 56 insertions, 51 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/BUILD b/src/main/java/com/google/devtools/build/lib/BUILD
index c3cb48c605..742b98275d 100644
--- a/src/main/java/com/google/devtools/build/lib/BUILD
+++ b/src/main/java/com/google/devtools/build/lib/BUILD
@@ -1198,6 +1198,7 @@ java_library(
"//src/main/protobuf:extra_actions_base_java_proto",
"//src/main/protobuf:invocation_policy_java_proto",
"//src/main/protobuf:test_status_java_proto",
+ "//third_party:auto_value",
"//third_party:guava",
"//third_party:joda_time",
"//third_party:jsr305",
diff --git a/src/main/java/com/google/devtools/build/lib/buildtool/ActionCacheStatistics.java b/src/main/java/com/google/devtools/build/lib/buildtool/ActionCacheStatistics.java
new file mode 100644
index 0000000000..d1ccee635c
--- /dev/null
+++ b/src/main/java/com/google/devtools/build/lib/buildtool/ActionCacheStatistics.java
@@ -0,0 +1,44 @@
+// Copyright 2014 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.buildtool;
+
+import com.google.auto.value.AutoValue;
+import java.time.Duration;
+
+/** Statistics about the action cache during a single build. */
+@AutoValue
+public abstract class ActionCacheStatistics {
+ /** Gets the time it took to save the action cache to disk. */
+ public abstract Duration saveTime();
+
+ /** Gets the size of the action cache in bytes as persisted on disk. */
+ public abstract long sizeInBytes();
+
+ /** Returns a new builder. */
+ static Builder builder() {
+ return new AutoValue_ActionCacheStatistics.Builder();
+ }
+
+ @AutoValue.Builder
+ abstract static class Builder {
+ /** Sets the time it took to save the action cache to disk. */
+ abstract Builder setSaveTime(Duration duration);
+
+ /** Sets the size of the action cache in bytes as persisted to disk. */
+ abstract Builder setSizeInBytes(long sizeInBytes);
+
+ /** Constructs and returns the {@link ActionCacheStatistics}. */
+ abstract ActionCacheStatistics build();
+ }
+}
diff --git a/src/main/java/com/google/devtools/build/lib/buildtool/CachesSavedEvent.java b/src/main/java/com/google/devtools/build/lib/buildtool/CachesSavedEvent.java
deleted file mode 100644
index 8f608921cc..0000000000
--- a/src/main/java/com/google/devtools/build/lib/buildtool/CachesSavedEvent.java
+++ /dev/null
@@ -1,39 +0,0 @@
-// Copyright 2014 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.buildtool;
-
-/**
- * Event that is raised when the action and artifact metadata caches are saved at the end of the
- * build. Contains statistics.
- */
-public class CachesSavedEvent {
- /** Cache serialization statistics. */
- private final long actionCacheSaveTimeInMillis;
- private final long actionCacheSizeInBytes;
-
- public CachesSavedEvent(
- long actionCacheSaveTimeInMillis,
- long actionCacheSizeInBytes) {
- this.actionCacheSaveTimeInMillis = actionCacheSaveTimeInMillis;
- this.actionCacheSizeInBytes = actionCacheSizeInBytes;
- }
-
- public long getActionCacheSaveTimeInMillis() {
- return actionCacheSaveTimeInMillis;
- }
-
- public long getActionCacheSizeInBytes() {
- return actionCacheSizeInBytes;
- }
-}
diff --git a/src/main/java/com/google/devtools/build/lib/buildtool/ExecutionTool.java b/src/main/java/com/google/devtools/build/lib/buildtool/ExecutionTool.java
index a5d38d4d6c..dc81d34317 100644
--- a/src/main/java/com/google/devtools/build/lib/buildtool/ExecutionTool.java
+++ b/src/main/java/com/google/devtools/build/lib/buildtool/ExecutionTool.java
@@ -14,7 +14,6 @@
package com.google.devtools.build.lib.buildtool;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
-import static java.util.concurrent.TimeUnit.NANOSECONDS;
import com.google.common.base.Joiner;
import com.google.common.base.Predicate;
@@ -97,6 +96,7 @@ import com.google.devtools.build.lib.vfs.PathFragment;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;
+import java.time.Duration;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
@@ -469,7 +469,7 @@ public class ExecutionTool {
Profiler.instance().markPhase(ProfilePhase.FINISH);
if (buildCompleted) {
- saveCaches(actionCache);
+ saveActionCache(actionCache);
}
try (AutoProfiler p = AutoProfiler.profiled("Show results", ProfilerTask.INFO)) {
@@ -716,24 +716,23 @@ public class ExecutionTool {
}
/**
- * Writes the cache files to disk, reporting any errors that occurred during
- * writing.
+ * Writes the action cache files to disk, reporting any errors that occurred during writing and
+ * capturing statistics.
*/
- private void saveCaches(ActionCache actionCache) {
- long actionCacheSizeInBytes = 0;
- long actionCacheSaveTimeInMs;
+ private void saveActionCache(ActionCache actionCache) {
+ ActionCacheStatistics.Builder builder = ActionCacheStatistics.builder();
AutoProfiler p = AutoProfiler.profiledAndLogged("Saving action cache", ProfilerTask.INFO, log);
try {
- actionCacheSizeInBytes = actionCache.save();
+ builder.setSizeInBytes(actionCache.save());
} catch (IOException e) {
+ builder.setSizeInBytes(0);
getReporter().handle(Event.error("I/O error while writing action log: " + e.getMessage()));
} finally {
- actionCacheSaveTimeInMs =
- MILLISECONDS.convert(p.completeAndGetElapsedTimeNanos(), NANOSECONDS);
+ builder.setSaveTime(Duration.ofNanos(p.completeAndGetElapsedTimeNanos()));
}
- env.getEventBus().post(new CachesSavedEvent(
- actionCacheSaveTimeInMs, actionCacheSizeInBytes));
+
+ env.getEventBus().post(builder.build());
}
private Reporter getReporter() {