Allow command execution under `/usr/bin/time` for stats collections (#909)

This should help further troubleshoot
https://github.com/flutter/flutter/issues/154437
diff --git a/build/compiled_action.gni b/build/compiled_action.gni
index e07c990..734fbc3 100644
--- a/build/compiled_action.gni
+++ b/build/compiled_action.gni
@@ -28,6 +28,11 @@
 #       of these change. If inputs is empty, the step will run only when the
 #       binary itself changes.
 #
+#   prefix_with_time_cmd (optional)
+#       [bool] If true, the command will be prefixed with "time" to measure the
+#       time, CPU and memory usage of the tool, i.e. "time <command>" with
+#       appropriate arguments for the current platform.
+#
 #   visibility
 #   deps
 #   args   (all optional)
@@ -127,9 +132,15 @@
       depfile = invoker.depfile
     }
 
+    args = []
+    if (defined(invoker.prefix_with_time_cmd) && invoker.prefix_with_time_cmd) {
+      args += ["--time"]
+    }
+
     # The script takes as arguments the binary to run, and then the arguments
     # to pass it.
-    args = [ rebase_path(host_executable, root_build_dir) ] + invoker.args
+    args += [ rebase_path(host_executable, root_build_dir) ]
+    args += invoker.args
   }
 }
 
diff --git a/build/gn_run_binary.py b/build/gn_run_binary.py
index 3d682eb..ac88405 100644
--- a/build/gn_run_binary.py
+++ b/build/gn_run_binary.py
@@ -8,16 +8,27 @@
   python gn_run_binary.py <binary_name> [args ...]
 """
 
+import platform
 import sys
 import subprocess
 
+
+args = []
+basearg = 1
+if sys.argv[1] == "--time":
+  basearg = 2
+  if (platform.system() == "Linux"):
+    args += ["/usr/bin/time", "-v"]
+  elif (platform.system() == "Darwin"):
+    args += ["/usr/bin/time", "-l"]
+
 # This script is designed to run binaries produced by the current build. We
 # always prefix it with "./" to avoid picking up system versions that might
 # also be on the path.
-path = './' + sys.argv[1]
+path = './' + sys.argv[basearg]
 
 # The rest of the arguements are passed directly to the executable.
-args = [path] + sys.argv[2:]
+args += [path] + sys.argv[basearg + 1:]
 
 try:
   subprocess.check_output(args, stderr=subprocess.STDOUT)