aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build
diff options
context:
space:
mode:
authorGravatar ulfjack <ulfjack@google.com>2018-06-14 04:46:27 -0700
committerGravatar Copybara-Service <copybara-piper@google.com>2018-06-14 04:48:00 -0700
commit1fbe72ed6045d78bab83a7ca93279b2b540ef3df (patch)
tree2834008c02023a0b0979c44233377460b0ec20ed /src/main/java/com/google/devtools/build
parent89123fef16c24fe6e655e3c902c72375e300703a (diff)
Add a convenience method to Profiler
This reduces our reliance on ProfilerTask. PiperOrigin-RevId: 200538769
Diffstat (limited to 'src/main/java/com/google/devtools/build')
-rw-r--r--src/main/java/com/google/devtools/build/lib/buildtool/ExecutionTool.java7
-rw-r--r--src/main/java/com/google/devtools/build/lib/profiler/Profiler.java25
2 files changed, 28 insertions, 4 deletions
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 94cba7ca25..8f1e409fab 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
@@ -370,7 +370,7 @@ public class ExecutionTool {
env.getEventBus()
.post(new ExecutionPhaseCompleteEvent(timer.stop().elapsed(TimeUnit.MILLISECONDS)));
- try (SilentCloseable c = Profiler.instance().profile(ProfilerTask.INFO, "Show results")) {
+ try (SilentCloseable c = Profiler.instance().profile("Show results")) {
buildResult.setSuccessfulTargets(
determineSuccessfulTargets(configuredTargets, builtTargets));
buildResult.setSuccessfulAspects(determineSuccessfulAspects(aspects, builtAspects));
@@ -380,7 +380,7 @@ public class ExecutionTool {
analysisResult.getTargetsToSkip(), analysisResult.getAspects());
}
- try (SilentCloseable c = Profiler.instance().profile(ProfilerTask.INFO, "Show artifacts")) {
+ try (SilentCloseable c = Profiler.instance().profile("Show artifacts")) {
if (request.getBuildOptions().showArtifacts) {
BuildResultPrinter buildResultPrinter = new BuildResultPrinter(env);
buildResultPrinter.showArtifacts(
@@ -445,8 +445,7 @@ public class ExecutionTool {
* Prepare for a local output build.
*/
private void startLocalOutputBuild() throws ExecutorInitException {
- try (SilentCloseable c =
- Profiler.instance().profile(ProfilerTask.INFO, "Starting local output build")) {
+ try (SilentCloseable c = Profiler.instance().profile("Starting local output build")) {
Path outputPath = env.getDirectories().getOutputPath(env.getWorkspaceName());
Path localOutputPath = env.getDirectories().getLocalOutputPath();
diff --git a/src/main/java/com/google/devtools/build/lib/profiler/Profiler.java b/src/main/java/com/google/devtools/build/lib/profiler/Profiler.java
index 88634d4e63..9309e3b970 100644
--- a/src/main/java/com/google/devtools/build/lib/profiler/Profiler.java
+++ b/src/main/java/com/google/devtools/build/lib/profiler/Profiler.java
@@ -781,6 +781,31 @@ public final class Profiler {
}
/**
+ * Records the beginning of a task as specified, and returns a {@link SilentCloseable} instance
+ * that ends the task. This lets the system do the work of ending the task, with the compiler
+ * giving a warning if the returned instance is not closed.
+ *
+ * <p>Use of this method allows to support nested task monitoring. For tasks that are known to not
+ * have any subtasks, logSimpleTask() should be used instead.
+ *
+ * <p>This is a convenience method that uses {@link ProfilerTask#INFO}.
+ *
+ * <p>Use like this:
+ * <pre>
+ * {@code
+ * try (SilentCloseable c = Profiler.instance().profile("description")) {
+ * // Your code here.
+ * }
+ * }
+ * </pre>
+ *
+ * @param description task description. May be stored until the end of the build.
+ */
+ public SilentCloseable profile(String description) {
+ return profile(ProfilerTask.INFO, description);
+ }
+
+ /**
* Records the end of the task and moves tasks from the thread-local stack to
* the main queue. Will validate that given task type matches task at the top
* of the stack.