diff options
author | ulfjack <ulfjack@google.com> | 2018-06-14 04:46:27 -0700 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2018-06-14 04:48:00 -0700 |
commit | 1fbe72ed6045d78bab83a7ca93279b2b540ef3df (patch) | |
tree | 2834008c02023a0b0979c44233377460b0ec20ed /src/main/java/com/google/devtools/build/lib/profiler/Profiler.java | |
parent | 89123fef16c24fe6e655e3c902c72375e300703a (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/lib/profiler/Profiler.java')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/profiler/Profiler.java | 25 |
1 files changed, 25 insertions, 0 deletions
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. |