mirror of
https://chromium.googlesource.com/chromium/tools/depot_tools.git
synced 2026-01-11 18:51:29 +00:00
This reverts commit 4e2be179a1.
Reason for revert:
This caused exception
```
+ autoninja -strict_remote -d keepdepfile -d keeprsp -C out/Default chrome
siso ninja -strict_remote -d keepdepfile -d keeprsp -C out/Default chrome
ninja: Entering directory `out/Default'
4.51s init credentials by "credhelper"
https://console.cloud.google.com/logs/viewer?project=rbe-chrome-untrusted&resource=generic_task/task_id/25d8cbb8-4fa1-486d-ba78-7865d0eea5ac
use RBE instance "projects/rbe-chrome-untrusted/instances/default_instance"
2.27s loading/recompacting deps log
3.47s Regenerating ninja files
1.17s load siso config
build finished
local:3636 remote:33214 cache:3317 cache-write:0(err:0) fallback:0 retry:0 skip:40752
reapi: ops: 102977(err:33221) / r:46503(err:8) 3.13GiB / w:72424(err:0) 152.35MiB
fs: ops: 2790971(err:182693) / r:227138(err:0) 6.68GiB / w:13508(err:4) 1.87GiB
resource/capa used(err) wait-avg | s m | serv-avg | s m |
pool=action/128 2372(0) 0.00s |█ | 0.30s | █▅▂▂▂ |
rbe:sched 33214(0) 0.01s |▃█▂▂ | 6.43s | ▂█▃▂ |
rbe:worker 33214(0) 0.87s | █ | 5.56s | ▂█▃▂ |
remoteexec/10240 33214(0) 0.10s |█▂▂▂ | 15.37s | ██▂ |
1.00s shutdown cloud logging/monitoring
4m08.96s Build Succeeded: 40167 steps - 161.34/s
flag provided but not defined: -enable_cloud_monitoring
summarize siso_metrics.json
$ siso metrics summary -C <dir> \
[--step_types <types>] \
[--elapsed_time_sorting] \
[--elapsed_time=run|step] \
[--input siso_metrics.json]
summarize <dir>/.siso_metrics.json (--input)
as depot_tools/post_ninja_build_summary.py does.
-C string
ninja running directory, where siso_metrics.json exists (default ".")
-elapsed_time string
metrics to use for elapsed time. "run" or "step". "run": time to run local command or call remote execution. "step": full duration for the step, including preproc, waiting resource to run command etc. (default "run")
-elapsed_time_sorting
Sort output by elapsed time instead of weighted time
-input string
filename of siso_metrics.json to summarize (default "siso_metrics.json")
-step_types string
semicolon separated glob patterns (go filepath.Match) for build-step grouping
Traceback (most recent call last):
File "/usr/local/google/home/tikuta/depot_tools/post_build_ninja_summary.py", line 390, in <module>
sys.exit(main())
^^^^^^
File "/usr/local/google/home/tikuta/depot_tools/post_build_ninja_summary.py", line 375, in main
subprocess.run(cmd, check=True)
File "/usr/local/google/home/tikuta/depot_tools/bootstrap-2@3.11.8.chromium.35_bin/python3/lib/python3.11/subprocess.py", line 571, in run
raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['/usr/local/google/home/tikuta/depot_tools/bootstrap-2@3.11.8.chromium.35_bin/python3/bin/python3', '/usr/local/google/home/tikuta/depot_tools/siso.py', 'metrics', 'summary', '-C', 'out/Default', '--step_types', 'trict_remote']' returned non-zero exit status 2.
```
Original change's description:
> Enable telemetry flags for Google corp machines only.
>
> Bug: b/348530235
> Change-Id: I4ac32c60b806f44920bd06e31ec6c3b86a6a6964
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/7104218
> Commit-Queue: Alex Ovsienko <ovsienko@google.com>
> Reviewed-by: Junji Watanabe <jwata@google.com>
Bug: b/348530235
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Change-Id: Iff13fa73745e09d2dab4278e9571f7ed77bf3d0c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/7136522
Auto-Submit: Takuto Ikuta <tikuta@chromium.org>
Reviewed-by: Alex Ovsienko <ovsienko@google.com>
Commit-Queue: Alex Ovsienko <ovsienko@google.com>
244 lines
8.8 KiB
Python
244 lines
8.8 KiB
Python
#!/usr/bin/env python3
|
|
# Copyright 2023 The Chromium Authors. All rights reserved.
|
|
# Use of this source code is governed by a BSD-style license that can be
|
|
# found in the LICENSE file.
|
|
"""This script is a wrapper around the siso binary that is pulled to
|
|
third_party as part of gclient sync. It will automatically find the siso
|
|
binary when run inside a gclient source tree, so users can just type
|
|
"siso" on the command line."""
|
|
|
|
import itertools
|
|
import os
|
|
import platform
|
|
import signal
|
|
import shlex
|
|
import shutil
|
|
import sys
|
|
|
|
import caffeinate
|
|
import gclient_paths
|
|
|
|
|
|
def parse_args(args):
|
|
subcmd = ''
|
|
out_dir = "."
|
|
for i, arg in enumerate(args):
|
|
if not arg.startswith("-") and not subcmd:
|
|
subcmd = arg
|
|
continue
|
|
if arg == "-C":
|
|
out_dir = args[i + 1]
|
|
elif arg.startswith("-C"):
|
|
out_dir = arg[2:]
|
|
return subcmd, out_dir
|
|
|
|
|
|
def check_outdir(subcmd, out_dir):
|
|
ninja_marker = os.path.join(out_dir, ".ninja_deps")
|
|
if os.path.exists(ninja_marker):
|
|
print("depot_tools/siso.py: %s contains Ninja state file.\n"
|
|
"Use `autoninja` to use reclient,\n"
|
|
"or run `gn clean %s` to switch from ninja to siso\n" %
|
|
(out_dir, out_dir),
|
|
file=sys.stderr)
|
|
sys.exit(1)
|
|
|
|
|
|
def apply_metrics_labels(args: list[str]) -> list[str]:
|
|
if not args:
|
|
return args
|
|
# We expect ninja calls, else this algorithm is meaningless.
|
|
if args[0] != "ninja":
|
|
return args
|
|
|
|
system_dict = {"Windows": "windows", "Darwin": "mac", "Linux": "linux"}
|
|
user_system = system_dict.get(platform.system(), platform.system())
|
|
|
|
# TODO(ovsienko) - add targets to the processing. For this, the Siso needs to understand lists.
|
|
for arg in args[1:]:
|
|
# Respect user provided labels, abort.
|
|
if arg.startswith("--metrics_labels") or arg.startswith(
|
|
"-metrics_labels"):
|
|
return args
|
|
|
|
result = []
|
|
result.append("type=developer")
|
|
result.append("tool=siso")
|
|
result.append(f"host_os={user_system}")
|
|
return args + ["--metrics_labels", ",".join(result)]
|
|
|
|
|
|
def load_sisorc(rcfile):
|
|
if not os.path.exists(rcfile):
|
|
return [], {}
|
|
global_flags = []
|
|
subcmd_flags = {}
|
|
with open(rcfile) as file:
|
|
for line in file:
|
|
line = line.strip()
|
|
if line.startswith("#"):
|
|
continue
|
|
args = shlex.split(line)
|
|
if len(args) == 0:
|
|
continue
|
|
if line.startswith("-"):
|
|
global_flags.extend(args)
|
|
continue
|
|
subcmd_flags[args[0]] = args[1:]
|
|
return global_flags, subcmd_flags
|
|
|
|
|
|
def apply_sisorc(global_flags, subcmd_flags, args, subcmd):
|
|
new_args = []
|
|
for arg in args:
|
|
if not new_args:
|
|
new_args.extend(global_flags)
|
|
if arg == subcmd:
|
|
new_args.append(arg)
|
|
new_args.extend(subcmd_flags.get(arg, []))
|
|
continue
|
|
new_args.append(arg)
|
|
return new_args
|
|
|
|
|
|
def _is_google_corp_machine():
|
|
"""This assumes that corp machine has gcert binary in known location."""
|
|
return shutil.which("gcert") is not None
|
|
|
|
|
|
def main(args):
|
|
# Do not raise KeyboardInterrupt on SIGINT so as to give siso time to run
|
|
# cleanup tasks. Siso will be terminated immediately after the second
|
|
# Ctrl-C.
|
|
original_sigint_handler = signal.getsignal(signal.SIGINT)
|
|
|
|
def _ignore(signum, frame):
|
|
try:
|
|
# Call the original signal handler.
|
|
original_sigint_handler(signum, frame)
|
|
except KeyboardInterrupt:
|
|
# Do not reraise KeyboardInterrupt so as to not kill siso too early.
|
|
pass
|
|
|
|
signal.signal(signal.SIGINT, _ignore)
|
|
|
|
if not sys.platform.startswith('win'):
|
|
signal.signal(signal.SIGTERM, lambda signum, frame: None)
|
|
|
|
# On Windows the siso.bat script passes along the arguments enclosed in
|
|
# double quotes. This prevents multiple levels of parsing of the special '^'
|
|
# characters needed when compiling a single file. When this case is
|
|
# detected, we need to split the argument. This means that arguments
|
|
# containing actual spaces are not supported by siso.bat, but that is not a
|
|
# real limitation.
|
|
if sys.platform.startswith('win') and len(args) == 2:
|
|
args = args[:1] + args[1].split()
|
|
|
|
# macOS's python sets CPATH, LIBRARY_PATH, SDKROOT implicitly.
|
|
# https://openradar.appspot.com/radar?id=5608755232243712
|
|
#
|
|
# Removing those environment variables to avoid affecting clang's behaviors.
|
|
if sys.platform == 'darwin':
|
|
os.environ.pop("CPATH", None)
|
|
os.environ.pop("LIBRARY_PATH", None)
|
|
os.environ.pop("SDKROOT", None)
|
|
|
|
# if user doesn't set PYTHONPYCACHEPREFIX and PYTHONDONTWRITEBYTECODE
|
|
# set PYTHONDONTWRITEBYTECODE=1 not to create many *.pyc in workspace
|
|
# and keep workspace clean.
|
|
if not os.environ.get("PYTHONPYCACHEPREFIX"):
|
|
os.environ.setdefault("PYTHONDONTWRITEBYTECODE", "1")
|
|
|
|
environ = os.environ.copy()
|
|
|
|
subcmd, out_dir = parse_args(args[1:])
|
|
|
|
# Get gclient root + src.
|
|
primary_solution_path = gclient_paths.GetPrimarySolutionPath(out_dir)
|
|
gclient_root_path = gclient_paths.FindGclientRoot(out_dir)
|
|
gclient_src_root_path = None
|
|
if gclient_root_path:
|
|
gclient_src_root_path = os.path.join(gclient_root_path, 'src')
|
|
|
|
siso_override_path = os.environ.get('SISO_PATH')
|
|
if siso_override_path:
|
|
print('depot_tools/siso.py: Using Siso binary from SISO_PATH: %s.' %
|
|
siso_override_path,
|
|
file=sys.stderr)
|
|
if not os.path.isfile(siso_override_path):
|
|
print(
|
|
'depot_tools/siso.py: Could not find Siso at provided '
|
|
'SISO_PATH.',
|
|
file=sys.stderr)
|
|
return 1
|
|
|
|
for base_path in set(
|
|
[primary_solution_path, gclient_root_path, gclient_src_root_path]):
|
|
if not base_path:
|
|
continue
|
|
env = environ.copy()
|
|
sisoenv_path = os.path.join(base_path, 'build', 'config', 'siso',
|
|
'.sisoenv')
|
|
if not os.path.exists(sisoenv_path):
|
|
continue
|
|
with open(sisoenv_path) as f:
|
|
for line in f.readlines():
|
|
k, v = line.rstrip().split('=', 1)
|
|
env[k] = v
|
|
backend_config_dir = os.path.join(base_path, 'build', 'config', 'siso',
|
|
'backend_config')
|
|
if os.path.exists(backend_config_dir) and not os.path.exists(
|
|
os.path.join(backend_config_dir, 'backend.star')):
|
|
if _is_google_corp_machine():
|
|
print(
|
|
'build/config/siso/backend_config/backend.star does not '
|
|
'exist.\n'
|
|
'backend.star is configured by gclient hook '
|
|
'build/config/siso/configure_siso.py.\n'
|
|
'Make sure `rbe_instance` gclient custom vars is correct.\n'
|
|
'Did you run `gclient runhooks` ?',
|
|
file=sys.stderr)
|
|
else:
|
|
print(
|
|
'build/config/siso/backend_config/backend.star does not '
|
|
'exist.\n'
|
|
'See build/config/siso/backend_config/README.md',
|
|
file=sys.stderr)
|
|
return 1
|
|
global_flags, subcmd_flags = load_sisorc(
|
|
os.path.join(base_path, 'build', 'config', 'siso', '.sisorc'))
|
|
siso_paths = [
|
|
siso_override_path,
|
|
os.path.join(base_path, 'third_party', 'siso', 'cipd',
|
|
'siso' + gclient_paths.GetExeSuffix()),
|
|
os.path.join(base_path, 'third_party', 'siso',
|
|
'siso' + gclient_paths.GetExeSuffix()),
|
|
]
|
|
for siso_path in siso_paths:
|
|
if siso_path and os.path.isfile(siso_path):
|
|
check_outdir(subcmd, out_dir)
|
|
new_args = apply_sisorc(global_flags, subcmd_flags, args[1:],
|
|
subcmd)
|
|
if args[1:] != new_args:
|
|
print('depot_tools/siso.py: %s' % shlex.join(new_args),
|
|
file=sys.stderr)
|
|
new_args = apply_metrics_labels(new_args)
|
|
return caffeinate.run([siso_path] + new_args, env=env)
|
|
print(
|
|
'depot_tools/siso.py: Could not find siso in third_party/siso '
|
|
'of the current project. Did you run gclient sync?',
|
|
file=sys.stderr)
|
|
return 1
|
|
if siso_override_path:
|
|
return caffeinate.run([siso_override_path] + args[1:])
|
|
|
|
print(
|
|
'depot_tools/siso.py: Could not find .sisoenv under build/config/siso '
|
|
'of the current project. Did you run gclient sync?',
|
|
file=sys.stderr)
|
|
return 1
|
|
|
|
|
|
if __name__ == '__main__':
|
|
sys.exit(main(sys.argv))
|