Use AutoProfiler in the Bazel codebase.
--
MOS_MIGRATED_REVID=102584924
diff --git a/src/main/java/com/google/devtools/build/lib/runtime/BlazeRuntime.java b/src/main/java/com/google/devtools/build/lib/runtime/BlazeRuntime.java
index edd1b92..7e4e41c 100644
--- a/src/main/java/com/google/devtools/build/lib/runtime/BlazeRuntime.java
+++ b/src/main/java/com/google/devtools/build/lib/runtime/BlazeRuntime.java
@@ -14,6 +14,8 @@
package com.google.devtools.build.lib.runtime;
+import static com.google.devtools.build.lib.profiler.AutoProfiler.profiled;
+import static com.google.devtools.build.lib.profiler.AutoProfiler.profiledAndLogged;
import static java.nio.charset.StandardCharsets.ISO_8859_1;
import com.google.common.annotations.VisibleForTesting;
@@ -64,6 +66,7 @@
import com.google.devtools.build.lib.pkgcache.PackageCacheOptions;
import com.google.devtools.build.lib.pkgcache.PackageManager;
import com.google.devtools.build.lib.pkgcache.TargetPatternEvaluator;
+import com.google.devtools.build.lib.profiler.AutoProfiler;
import com.google.devtools.build.lib.profiler.MemoryProfiler;
import com.google.devtools.build.lib.profiler.ProfilePhase;
import com.google.devtools.build.lib.profiler.Profiler;
@@ -299,10 +302,9 @@
if (getOutputService() != null) {
return getOutputService().getFilesSystemName();
}
- long startTime = Profiler.nanoTimeMaybe();
- String fileSystem = FileSystemUtils.getFileSystem(getOutputBase());
- Profiler.instance().logSimpleTask(startTime, ProfilerTask.INFO, "Finding output file system");
- return fileSystem;
+ try (AutoProfiler p = profiled("Finding output file system", ProfilerTask.INFO)) {
+ return FileSystemUtils.getFileSystem(getOutputBase());
+ }
}
public String getOutputFileSystem() {
@@ -632,25 +634,19 @@
actionCache = new NullActionCache();
return actionCache;
}
- long startTime = Profiler.nanoTimeMaybe();
- try {
- actionCache = new CompactPersistentActionCache(getCacheDirectory(), clock);
- } catch (IOException e) {
- LOG.log(Level.WARNING, "Failed to load action cache: " + e.getMessage(), e);
- LoggingUtil.logToRemote(Level.WARNING, "Failed to load action cache: "
- + e.getMessage(), e);
- getReporter().handle(
- Event.error("Error during action cache initialization: " + e.getMessage()
- + ". Corrupted files were renamed to '" + getCacheDirectory() + "/*.bad'. "
- + "Blaze will now reset action cache data, causing a full rebuild"));
- actionCache = new CompactPersistentActionCache(getCacheDirectory(), clock);
- } finally {
- long stopTime = Profiler.nanoTimeMaybe();
- long duration = stopTime - startTime;
- if (duration > 0) {
- LOG.info("Spent " + (duration / (1000 * 1000)) + " ms loading persistent action cache");
+ try (AutoProfiler p = profiledAndLogged("Loading action cache", ProfilerTask.INFO, LOG)) {
+ try {
+ actionCache = new CompactPersistentActionCache(getCacheDirectory(), clock);
+ } catch (IOException e) {
+ LOG.log(Level.WARNING, "Failed to load action cache: " + e.getMessage(), e);
+ LoggingUtil.logToRemote(Level.WARNING, "Failed to load action cache: "
+ + e.getMessage(), e);
+ getReporter().handle(
+ Event.error("Error during action cache initialization: " + e.getMessage()
+ + ". Corrupted files were renamed to '" + getCacheDirectory() + "/*.bad'. "
+ + "Blaze will now reset action cache data, causing a full rebuild"));
+ actionCache = new CompactPersistentActionCache(getCacheDirectory(), clock);
}
- Profiler.instance().logSimpleTask(startTime, ProfilerTask.INFO, "Loading action cache");
}
}
return actionCache;
@@ -1506,6 +1502,7 @@
}
BlazeRuntime runtime = runtimeBuilder.build();
+ AutoProfiler.setClock(runtime.getClock());
BugReport.setRuntime(runtime);
return runtime;
}