mirror of
https://chromium.googlesource.com/chromium/tools/depot_tools.git
synced 2026-01-11 18:51:29 +00:00
autoninja: Add exit code and build duration to ninjalog metadata
- exit code will be useful to distinguish between successful builds and others. - build duration will cover the overhead outside of ninja invocation e.g. Reclient and Siso's startup/shutdown. Bug: 348527311 Change-Id: Ibebdf3d64597fb0e57914a84d33e46bca66671da Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5804201 Auto-Submit: Junji Watanabe <jwata@google.com> Reviewed-by: Fumitoshi Ukai <ukai@google.com> Reviewed-by: Takuto Ikuta <tikuta@chromium.org> Commit-Queue: Junji Watanabe <jwata@google.com>
This commit is contained in:
17
autoninja.py
17
autoninja.py
@@ -405,14 +405,23 @@ def _main_inner(input_args, build_id, should_collect_logs=False):
|
|||||||
return ninja.main(ninja_args)
|
return ninja.main(ninja_args)
|
||||||
|
|
||||||
|
|
||||||
def _upload_ninjalog(args):
|
def _upload_ninjalog(args, exit_code, build_duration):
|
||||||
warnings.simplefilter("ignore", ResourceWarning)
|
warnings.simplefilter("ignore", ResourceWarning)
|
||||||
# Run upload script without wait.
|
# Run upload script without wait.
|
||||||
creationflags = 0
|
creationflags = 0
|
||||||
if platform.system() == "Windows":
|
if platform.system() == "Windows":
|
||||||
creationflags = subprocess.CREATE_NEW_PROCESS_GROUP
|
creationflags = subprocess.CREATE_NEW_PROCESS_GROUP
|
||||||
|
cmd = [
|
||||||
|
sys.executable,
|
||||||
|
_NINJALOG_UPLOADER,
|
||||||
|
"--exit_code",
|
||||||
|
str(exit_code),
|
||||||
|
"--build_duration",
|
||||||
|
str(int(build_duration)),
|
||||||
|
"--cmdline",
|
||||||
|
] + args[1:]
|
||||||
subprocess.Popen(
|
subprocess.Popen(
|
||||||
[sys.executable, _NINJALOG_UPLOADER, "--cmdline"] + args[1:],
|
cmd,
|
||||||
stdout=subprocess.DEVNULL,
|
stdout=subprocess.DEVNULL,
|
||||||
stderr=subprocess.DEVNULL,
|
stderr=subprocess.DEVNULL,
|
||||||
creationflags=creationflags,
|
creationflags=creationflags,
|
||||||
@@ -420,6 +429,7 @@ def _upload_ninjalog(args):
|
|||||||
|
|
||||||
|
|
||||||
def main(args):
|
def main(args):
|
||||||
|
start = time.time()
|
||||||
# Generate Build ID randomly.
|
# Generate Build ID randomly.
|
||||||
# This ID is expected to be used consistently in all build tools.
|
# This ID is expected to be used consistently in all build tools.
|
||||||
build_id = os.environ.get("AUTONINJA_BUILD_ID")
|
build_id = os.environ.get("AUTONINJA_BUILD_ID")
|
||||||
@@ -445,7 +455,8 @@ def main(args):
|
|||||||
exit_code = 1
|
exit_code = 1
|
||||||
finally:
|
finally:
|
||||||
if should_collect_logs:
|
if should_collect_logs:
|
||||||
_upload_ninjalog(input_args)
|
elapsed = time.time() - start
|
||||||
|
_upload_ninjalog(input_args, exit_code, elapsed)
|
||||||
return exit_code
|
return exit_code
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -123,7 +123,7 @@ def GetJflag(cmdline):
|
|||||||
return int(cmdline[i][len("-j"):])
|
return int(cmdline[i][len("-j"):])
|
||||||
|
|
||||||
|
|
||||||
def GetMetadata(cmdline, ninjalog):
|
def GetMetadata(cmdline, ninjalog, exit_code, build_duration):
|
||||||
"""Get metadata for uploaded ninjalog.
|
"""Get metadata for uploaded ninjalog.
|
||||||
|
|
||||||
Returned metadata has schema defined in
|
Returned metadata has schema defined in
|
||||||
@@ -151,6 +151,8 @@ def GetMetadata(cmdline, ninjalog):
|
|||||||
build_configs[k] = str(build_configs[k])
|
build_configs[k] = str(build_configs[k])
|
||||||
|
|
||||||
metadata = {
|
metadata = {
|
||||||
|
"exit_code": exit_code,
|
||||||
|
"build_duration_sec": build_duration,
|
||||||
"platform": platform.system(),
|
"platform": platform.system(),
|
||||||
"cpu_core": multiprocessing.cpu_count(),
|
"cpu_core": multiprocessing.cpu_count(),
|
||||||
"build_configs": build_configs,
|
"build_configs": build_configs,
|
||||||
@@ -160,7 +162,6 @@ def GetMetadata(cmdline, ninjalog):
|
|||||||
invocation_id = os.environ.get("AUTONINJA_BUILD_ID")
|
invocation_id = os.environ.get("AUTONINJA_BUILD_ID")
|
||||||
if invocation_id:
|
if invocation_id:
|
||||||
metadata['invocation_id'] = invocation_id
|
metadata['invocation_id'] = invocation_id
|
||||||
|
|
||||||
jflag = GetJflag(cmdline)
|
jflag = GetJflag(cmdline)
|
||||||
if jflag is not None:
|
if jflag is not None:
|
||||||
metadata["jobs"] = jflag
|
metadata["jobs"] = jflag
|
||||||
@@ -188,15 +189,13 @@ def GetNinjalog(cmdline):
|
|||||||
return os.path.join(ninjalog_dir, ".ninja_log")
|
return os.path.join(ninjalog_dir, ".ninja_log")
|
||||||
|
|
||||||
|
|
||||||
def UploadNinjaLog(ninjalog, server, cmdline):
|
def UploadNinjaLog(server, ninjalog, metadata):
|
||||||
output = io.BytesIO()
|
output = io.BytesIO()
|
||||||
|
|
||||||
with open(ninjalog) as f:
|
with open(ninjalog) as f:
|
||||||
with gzip.GzipFile(fileobj=output, mode="wb") as g:
|
with gzip.GzipFile(fileobj=output, mode="wb") as g:
|
||||||
g.write(f.read().encode())
|
g.write(f.read().encode())
|
||||||
g.write(b"# end of ninja log\n")
|
g.write(b"# end of ninja log\n")
|
||||||
|
|
||||||
metadata = GetMetadata(cmdline, ninjalog)
|
|
||||||
logging.info("send metadata: %s", json.dumps(metadata))
|
logging.info("send metadata: %s", json.dumps(metadata))
|
||||||
g.write(json.dumps(metadata).encode())
|
g.write(json.dumps(metadata).encode())
|
||||||
|
|
||||||
@@ -236,6 +235,12 @@ def main():
|
|||||||
parser.add_argument("--verbose",
|
parser.add_argument("--verbose",
|
||||||
action="store_true",
|
action="store_true",
|
||||||
help="Enable verbose logging.")
|
help="Enable verbose logging.")
|
||||||
|
parser.add_argument("--exit_code",
|
||||||
|
type=int,
|
||||||
|
help="exit code of the ninja command.")
|
||||||
|
parser.add_argument("--build_duration",
|
||||||
|
type=int,
|
||||||
|
help="total duration spent on autoninja (secounds)")
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--cmdline",
|
"--cmdline",
|
||||||
required=True,
|
required=True,
|
||||||
@@ -272,7 +277,9 @@ def main():
|
|||||||
logging.info("ninjalog is already uploaded.")
|
logging.info("ninjalog is already uploaded.")
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
exit_code = UploadNinjaLog(ninjalog, args.server, args.cmdline)
|
metadata = GetMetadata(args.cmdline, ninjalog, args.exit_code,
|
||||||
|
args.build_duration)
|
||||||
|
exit_code = UploadNinjaLog(args.server, ninjalog, metadata)
|
||||||
if exit_code == 0:
|
if exit_code == 0:
|
||||||
last_upload_file.touch()
|
last_upload_file.touch()
|
||||||
return exit_code
|
return exit_code
|
||||||
|
|||||||
Reference in New Issue
Block a user