diff options
author | ulfjack <ulfjack@google.com> | 2018-06-12 07:38:51 -0700 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2018-06-12 07:40:05 -0700 |
commit | 21d60de9af1770b6ef08702d5dc9e23ed928df10 (patch) | |
tree | 28b640381cdb05afbf1fce6c4d14f948e1a29837 /src/test/java/com/google/devtools/build/lib/profiler/ProfilerChartTest.java | |
parent | 71404a77556d564beddc8ec53c17ddbf6c8b8ab5 (diff) |
Refactor profiler
- move the save method to an inner class
- don't use a timer, use a blocking queue instead
- add a format enum (in anticipation of adding a json output format)
- update the test to use an in memory buffer, and avoid FoundationTestCase
Compared to the original https://github.com/bazelbuild/bazel/commit/15b8c259db111012b4642287172cb4d1d82151f3, it contains these changes:
- Make it so we don't create a queue if we are not going to write any
data! The queue is now owned by the writer, and if there is no writer, there
is no queue.
This was causing a memory regression because slowest task profiling is
enabled by default, in which case the profiler is started with no output
file. In that case, there's no thread that is emptying the queue, but the
queue was still created by default.
- add additional tests for slowest task and histogram handling; these also
provide coverage for the case where the profiler is started without an output
stream
- move all the writer thread handling into the inner class
- make writer access thread-safe
- add a bunch of documentation
PiperOrigin-RevId: 200212978
Diffstat (limited to 'src/test/java/com/google/devtools/build/lib/profiler/ProfilerChartTest.java')
-rw-r--r-- | src/test/java/com/google/devtools/build/lib/profiler/ProfilerChartTest.java | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/profiler/ProfilerChartTest.java b/src/test/java/com/google/devtools/build/lib/profiler/ProfilerChartTest.java index 105afb0535..6b3bd519ad 100644 --- a/src/test/java/com/google/devtools/build/lib/profiler/ProfilerChartTest.java +++ b/src/test/java/com/google/devtools/build/lib/profiler/ProfilerChartTest.java @@ -35,6 +35,7 @@ import com.google.devtools.build.lib.testutil.Scratch; import com.google.devtools.build.lib.testutil.Suite; import com.google.devtools.build.lib.testutil.TestSpec; import com.google.devtools.build.lib.vfs.Path; +import java.io.InputStream; import java.util.List; import java.util.Locale; import org.junit.Test; @@ -248,8 +249,14 @@ public class ProfilerChartTest extends FoundationTestCase { Path cacheDir = scratch.dir("/tmp"); Path cacheFile = cacheDir.getRelative("profile1.dat"); Profiler profiler = Profiler.instance(); - profiler.start(ProfiledTaskKinds.ALL, cacheFile.getOutputStream(), "basic test", false, - BlazeClock.instance(), BlazeClock.instance().nanoTime()); + profiler.start( + ProfiledTaskKinds.ALL, + cacheFile.getOutputStream(), + Profiler.Format.BINARY_BAZEL_FORMAT, + "basic test", + false, + BlazeClock.instance(), + BlazeClock.instance().nanoTime()); // Write from multiple threads to generate multiple rows in the chart. for (int i = 0; i < noOfRows; i++) { @@ -259,7 +266,9 @@ public class ProfilerChartTest extends FoundationTestCase { } profiler.stop(); - return ProfileInfo.loadProfile(cacheFile); + try (InputStream in = cacheFile.getInputStream()) { + return ProfileInfo.loadProfile(in); + } } private void task(final Profiler profiler, ProfilerTask task, String name) { |