Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the max precision of the 'time' keyword #72

Merged
merged 9 commits into from
Jul 14, 2020

Commits on Jul 13, 2020

  1. Fix the max precision of the 'time' keyword

    This commit backports the required fixes from ksh2020 for using
    millisecond precision with the 'time' keyword. The bugfix
    refactors a decent amount of code to rely on the BSD 'timeradd'
    and 'timersub' macros for calculating the total amount of time
    elapsed (as these aren't standard, they are selectively
    implemented in an iffe feature test for platforms without them).
    getrusage(3) is now preferred since it usually has higher precision
    than times(3) (the latter is used as a fallback).
    
    This patch can be extended with support for microsecond precision,
    although that is better left for a separate feature branch.
    There are three other fixes as well:
    
    src/lib/libast/features/time:
    - Test for getrusage with an iffe feature test rather than
      assume _sys_times == _lib_getrusage.
    
    src/cmd/ksh93/sh/xec.c:
    - A single percent at the end of a format specifier is now
      treated as a literal '%' (like in Bash).
    - Zero-pad seconds if seconds < 10. This was already done for
      the times builtin in commit 5c677a4, although it wasn't
      applied to the time keyword.
    - Backport the ksh2020 bugfix for the time keyword by using
      timeradd and timersub with gettimeofday (which is used with
      a timeofday macro). Prefer getrusage when it is available.
    
    src/cmd/ksh93/features/time:
    - Implement feature tests for the 'timeradd' and 'timersub'
      macros.
    - Do a feature test for getrusage like in the libast time test.
    
    src/cmd/ksh93/tests/basic.sh:
    - Add two tests for millisecond precision and the handling of
      '%' at the end of a format specifier.
    JohnoKing committed Jul 13, 2020
    Configuration menu
    Copy the full SHA
    7f520c9 View commit details
    Browse the repository at this point in the history
  2. Add fallback for systems without gettimeofday and getrusage

    src/cmd/ksh93/sh/xec.c:
    - Allow compiling without the 'timeofday' ifdef for better portability.
      This is the order of priority for getting the elapsed time:
      1) getrusage (most precise)
      2) times + gettimeofday (best fallback)
      3) only times (doesn't support millisecond precision)
      This was tested by using debug '#undef' statements in xec.c.
    JohnoKing committed Jul 13, 2020
    Configuration menu
    Copy the full SHA
    e74f18f View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    5169153 View commit details
    Browse the repository at this point in the history
  4. Fix a bus error on FreeBSD in fallback code

    src/cmd/ksh93/sh/xec.c:
    - Restore some old code for the fallback when _lib_getrusage
      and timeofday aren't defined to fix a bus error.
    JohnoKing committed Jul 13, 2020
    Configuration menu
    Copy the full SHA
    07121af View commit details
    Browse the repository at this point in the history
  5. Configuration menu
    Copy the full SHA
    d4ad9dd View commit details
    Browse the repository at this point in the history
  6. Fix a bug in subshells

    src/cmd/ksh93/sh/xec.c:
    - In subshells, getrusage must be run after forking. If it isn't,
      'time' can return negative user and system times.
    
    src/cmd/ksh93/tests/basic.sh:
    - Modify the radix regression test to check for negative numbers
      as well.
    JohnoKing committed Jul 13, 2020
    Configuration menu
    Copy the full SHA
    7f0d569 View commit details
    Browse the repository at this point in the history
  7. Configuration menu
    Copy the full SHA
    bbd5e62 View commit details
    Browse the repository at this point in the history

Commits on Jul 14, 2020

  1. Configuration menu
    Copy the full SHA
    ae52af3 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    f9653ab View commit details
    Browse the repository at this point in the history