Buffer profile output to amortize heavy cost of Blaze server-->client output.

PiperOrigin-RevId: 244066077
diff --git a/src/main/java/com/google/devtools/build/lib/runtime/commands/ProfileCommand.java b/src/main/java/com/google/devtools/build/lib/runtime/commands/ProfileCommand.java
index 3b49c1a..6a4e034 100644
--- a/src/main/java/com/google/devtools/build/lib/runtime/commands/ProfileCommand.java
+++ b/src/main/java/com/google/devtools/build/lib/runtime/commands/ProfileCommand.java
@@ -222,7 +222,7 @@
       opts.vfsStatsLimit = 0;
     }
 
-    try (PrintStream out = new PrintStream(env.getReporter().getOutErr().getOutputStream())) {
+    try (PrintStream out = getOutputStream(env)) {
       env.getReporter()
           .handle(
               Event.warn(
@@ -339,6 +339,11 @@
     return BlazeCommandResult.exitCode(ExitCode.SUCCESS);
   }
 
+  private static PrintStream getOutputStream(CommandEnvironment env) {
+    return new PrintStream(
+        new BufferedOutputStream(env.getReporter().getOutErr().getOutputStream()), false);
+  }
+
   /**
    * Prints trees rooted at tasks with a description matching a pattern.
    * @see Task#printTaskTree(PrintStream, long)