Skip to content

Commit

Permalink
sagemathgh-37840: sage-logger: Replace use of /usr/bin/time by ba…
Browse files Browse the repository at this point in the history
…sh keyword `time`

    
<!-- ^ Please provide a concise and informative title. -->
<!-- ^ Don't put issue numbers in the title, do this in the PR
description below. -->
<!-- ^ For example, instead of "Fixes sagemath#12345" use "Introduce new method
to calculate 1 + 2". -->
<!-- v Describe your changes below in detail. -->
<!-- v Why is this change required? What problem does it solve? -->
<!-- v If this PR resolves an open issue, please link to it here. For
example, "Fixes sagemath#12345". -->

Follow-up after
- sagemath#37391
- sagemath#37785

... to make the display of package build times available on Linux too.

Fixes
sagemath#37785 (comment),
closes sagemath#37832.

### 📝 Checklist

<!-- Put an `x` in all the boxes that apply. -->

- [x] The title is concise and informative.
- [x] The description explains in detail what this PR is about.
- [x] I have linked a relevant issue or discussion.
- [ ] I have created tests covering the changes.
- [ ] I have updated the documentation and checked the documentation
preview.

### ⌛ Dependencies

<!-- List all open PRs that this PR logically depends on. For example,
-->
<!-- - sagemath#12345: short description why this is a dependency -->
<!-- - sagemath#34567: ... -->
- Depends on sagemath#37785
    
URL: sagemath#37840
Reported by: Matthias Köppe
Reviewer(s): Kwankyu Lee
  • Loading branch information
Release Manager committed May 17, 2024
2 parents 3589d96 + ffa4f46 commit 31e8125
Showing 1 changed file with 12 additions and 17 deletions.
29 changes: 12 additions & 17 deletions build/bin/sage-logger
Original file line number Diff line number Diff line change
Expand Up @@ -63,21 +63,19 @@ fi

timefile="$logdir/$logname.time"
rm -f "$timefile"
if /usr/bin/time -h -o /dev/null true 2>/dev/null; then
TIME="/usr/bin/time -h -o $timefile"
else
TIME=""
fi
time_cmd() {
local max=$(($SECONDS+10))
exec 3>&1 4>&2
local out
TIME_OUTPUT=$((time 1>&3 2>&4 sh -c "$1") 2>&1)
local retstat=$?
[ "$SECONDS" -lt "$max" ] || echo "$TIME_OUTPUT" > "$timefile"
return $retstat
}
report_time ()
{
time=$(echo $(cat $timefile 2>/dev/null))
case "$time" in
*m*real*|*h*real*|*[1-9][0-9].*real*|*[1-9][0-9],*real*)
# at least 10 seconds wall time
echo "$time"
;;
esac
[ -r "$timefile" ] && echo $(< $timefile)
}
mkdir -p "$logdir"
Expand All @@ -94,8 +92,7 @@ if [ -n "$SAGE_SILENT_BUILD" -a ${use_prefix} = true ]; then
# Silent build.
# Similar to https://www.gnu.org/software/automake/manual/html_node/Automake-Silent-Rules.html#Automake-Silent-Rules
echo "[$logname] installing. Log file: $logfile"
( exec>> $logfile 2>&1 ; $TIME sh -c "$cmd"; status=$?;
[ -r $timefile ] && cat $timefile; exit $status )
( exec>> $logfile 2>&1; time_cmd "$cmd"; status=$?; report_time; exit $status )
status=$?
if [[ $status != 0 ]]; then
echo " [$logname] error installing, exit status $status. End of log file:"
Expand All @@ -115,9 +112,7 @@ else
# We trap SIGINT such that SIGINT interrupts the main process being
# run, not the logging.
( exec 2>&1;
$TIME sh -c "$cmd"; status=$?; report_time;
exit $status ) | \
( exec 2>&1; time_cmd "$cmd"; status=$?; report_time; exit $status ) | \
( trap '' SIGINT; if [ -n "$GITHUB_ACTIONS" -a -n "$prefix" ]; then echo "::group::${logname}"; fi; tee -a "$logfile" | $SED; if [ -n "$GITHUB_ACTIONS" -a -n "$prefix" ]; then echo "::endgroup::"; fi )
pipestatus=(${PIPESTATUS[*]})
Expand Down

0 comments on commit 31e8125

Please sign in to comment.