Skip to content

Commit 7736521

Browse files
authored
Allow command execution under /usr/bin/time for stats collections (#909)
This should help further troubleshoot flutter/flutter#154437
1 parent 08a82c0 commit 7736521

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

build/compiled_action.gni

+12-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@
2828
# of these change. If inputs is empty, the step will run only when the
2929
# binary itself changes.
3030
#
31+
# prefix_with_time_cmd (optional)
32+
# [bool] If true, the command will be prefixed with "time" to measure the
33+
# time, CPU and memory usage of the tool, i.e. "time <command>" with
34+
# appropriate arguments for the current platform.
35+
#
3136
# visibility
3237
# deps
3338
# args (all optional)
@@ -127,9 +132,15 @@ template("compiled_action") {
127132
depfile = invoker.depfile
128133
}
129134

135+
args = []
136+
if (defined(invoker.prefix_with_time_cmd) && invoker.prefix_with_time_cmd) {
137+
args += ["--time"]
138+
}
139+
130140
# The script takes as arguments the binary to run, and then the arguments
131141
# to pass it.
132-
args = [ rebase_path(host_executable, root_build_dir) ] + invoker.args
142+
args += [ rebase_path(host_executable, root_build_dir) ]
143+
args += invoker.args
133144
}
134145
}
135146

build/gn_run_binary.py

+13-2
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,27 @@
88
python gn_run_binary.py <binary_name> [args ...]
99
"""
1010

11+
import platform
1112
import sys
1213
import subprocess
1314

15+
16+
args = []
17+
basearg = 1
18+
if sys.argv[1] == "--time":
19+
basearg = 2
20+
if (platform.system() == "Linux"):
21+
args += ["/usr/bin/time", "-v"]
22+
elif (platform.system() == "Darwin"):
23+
args += ["/usr/bin/time", "-l"]
24+
1425
# This script is designed to run binaries produced by the current build. We
1526
# always prefix it with "./" to avoid picking up system versions that might
1627
# also be on the path.
17-
path = './' + sys.argv[1]
28+
path = './' + sys.argv[basearg]
1829

1930
# The rest of the arguements are passed directly to the executable.
20-
args = [path] + sys.argv[2:]
31+
args += [path] + sys.argv[basearg + 1:]
2132

2233
try:
2334
subprocess.check_output(args, stderr=subprocess.STDOUT)

0 commit comments

Comments
 (0)