Changeset View
Changeset View
Standalone View
Standalone View
tools/build/time-buildworld.sh
- This file was added.
| Property | Old Value | New Value |
|---|---|---|
| File Mode | null | 100755 |
| #!/bin/sh | |||||
| # Copyright (c) Mar 2025 Wolfram Schneider <wosch@FreeBSD.org> | |||||
| # SPDX-License-Identifier: BSD-2-Clause | |||||
| # | |||||
| # time-buildworld.sh - detailed time logging for `make buildworld' stages and steps | |||||
| # | |||||
| # This script will be called from /usr/src/Makefile.inc1. You can disable it by | |||||
| # setting the variable TIME_ENV to an empty value. | |||||
| # | |||||
| # the output will look like: | |||||
| # time: 4.54 real 7.21 user 0.29 sys start: 1742918038 end: 1742918043 exit: 0 message: sublib lib/libregex | |||||
| # time: 1842.72 real 45627.13 user 1161.79 sys start: 1742918117 end: 1742919960 exit: 0 message: libraries _generic_libs stage: 4.2.4 MACHINE_ARCH=amd64 | |||||
| # | |||||
| # You can parse the output with: make buildworld | grep '^time: ' | |||||
| # | |||||
| # The output will appears if a target is done (end timestamp in seconds). | |||||
| # the message to display | |||||
| message=${TIME_MESSAGE-"none"} | |||||
| # optional stage number (kind of grouping) | |||||
| stage=${STAGE_MESSAGE-""} | |||||
| # system time(1), not from the shell | |||||
| : ${time_cmd="/usr/bin/time"} | |||||
| trap 'rm -f $tmpfile' 0 | |||||
| # mktemp(1) is not portable | |||||
| tmpfile=$(mktemp /tmp/_time-buildworld-XXXXXXXXX) | |||||
| # we want sub directory target "all" only, and ignore others | |||||
| case $message in | |||||
| 'subdir all'*) ;; | |||||
| 'subdir '*) message="";; | |||||
| esac | |||||
| # start time in seconds of command since epoch time, we need this for parallel builds | |||||
| # note: FreeBSD date(1) does not support miliseconds | |||||
| start=$(date '+%s') | |||||
| # execute the commands, no recursive stage message | |||||
| # log the time in portable POSIX.2 format (FreeBSD, MacOS, Linux) | |||||
| $time_cmd -p -o $tmpfile env STAGE_MESSAGE="" "$@" | |||||
| exit=$? | |||||
| end=$(date '+%s') | |||||
| # CPU usage plus message / stage | |||||
| if [ -n "$message" ]; then | |||||
| m1="time: $(tr '\n' ' ' < $tmpfile)start: $start end: $end exit: $exit message: $message" | |||||
| if [ -n "$stage" ]; then | |||||
| m2=" stage: $stage" | |||||
| if [ -n "$MACHINE_ARCH" ]; then | |||||
| m3=" MACHINE_ARCH=$MACHINE_ARCH" | |||||
| fi | |||||
| fi | |||||
| echo "${m1}${m2}${m3}" | |||||
| fi | |||||
| # exit with command exit status | |||||
| exit $exit | |||||
| #EOF | |||||