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
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 a5d38d4..dc81d34 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 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 @@
       Profiler.instance().markPhase(ProfilePhase.FINISH);
 
       if (buildCompleted) {
-        saveCaches(actionCache);
+        saveActionCache(actionCache);
       }
 
       try (AutoProfiler p = AutoProfiler.profiled("Show results", ProfilerTask.INFO)) {
@@ -716,24 +716,23 @@
   }
 
   /**
-   * 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() {