Create isolated output directory when creating the output file.

Currently isolated output directory is created in flags_compatibility.py script.
This doesn't work for android swarming tasks because this script isn't called.

Bug: webrtc:11895
Change-Id: I8b8f01850d6e5970292b524d104314eef7ab17be
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/185883
Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org>
Reviewed-by: Artem Titov <titovartem@webrtc.org>
Commit-Queue: Jeremy Leconte <jleconte@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#32236}
diff --git a/test/BUILD.gn b/test/BUILD.gn
index 8e27bc4..58d3dab 100644
--- a/test/BUILD.gn
+++ b/test/BUILD.gn
@@ -253,6 +253,7 @@
     "../rtc_base:logging",
     "../rtc_base:rtc_numerics",
     "../rtc_base/synchronization:mutex",
+    "../test:fileutils",
   ]
   absl_deps = [ "//third_party/abseil-cpp/absl/types:optional" ]
   if (rtc_enable_protobuf) {
diff --git a/test/testsupport/perf_test.cc b/test/testsupport/perf_test.cc
index 3a43674..b68eaa4 100644
--- a/test/testsupport/perf_test.cc
+++ b/test/testsupport/perf_test.cc
@@ -19,6 +19,7 @@
 
 #include "rtc_base/checks.h"
 #include "rtc_base/synchronization/mutex.h"
+#include "test/testsupport/file_utils.h"
 #include "test/testsupport/perf_test_histogram_writer.h"
 
 namespace webrtc {
@@ -221,6 +222,7 @@
 
 bool WritePerfResults(const std::string& output_path) {
   std::string results = GetPerfResults();
+  CreateDir(DirName(output_path));
   FILE* output = fopen(output_path.c_str(), "wb");
   if (output == NULL) {
     printf("Failed to write to %s.\n", output_path.c_str());
diff --git a/tools_webrtc/flags_compatibility.py b/tools_webrtc/flags_compatibility.py
old mode 100644
new mode 100755
index 63e3f1f..d3570a5
--- a/tools_webrtc/flags_compatibility.py
+++ b/tools_webrtc/flags_compatibility.py
@@ -10,7 +10,6 @@
 
 import argparse
 import logging
-import os
 import subprocess
 import sys
 
@@ -22,11 +21,6 @@
 
   test_command = _ForcePythonInterpreter(unrecognized_args)
   if args.isolated_script_test_perf_output:
-    # TODO(bugs.webrtc.org/11895): Move this code somewhere else because
-    # flags_compatibility.py shouldn't create output directories.
-    output_dirname = os.path.dirname(args.isolated_script_test_perf_output)
-    if not os.path.exists(output_dirname):
-      os.makedirs(output_dirname)
     test_command += ['--isolated_script_test_perf_output=' +
                      args.isolated_script_test_perf_output]
   logging.info('Running %r', test_command)