-
Notifications
You must be signed in to change notification settings - Fork 31
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
Commits on Jul 13, 2020
-
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.
Configuration menu - View commit details
-
Copy full SHA for 7f520c9 - Browse repository at this point
Copy the full SHA 7f520c9View commit details -
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.
Configuration menu - View commit details
-
Copy full SHA for e74f18f - Browse repository at this point
Copy the full SHA e74f18fView commit details -
Configuration menu - View commit details
-
Copy full SHA for 5169153 - Browse repository at this point
Copy the full SHA 5169153View commit details -
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.
Configuration menu - View commit details
-
Copy full SHA for 07121af - Browse repository at this point
Copy the full SHA 07121afView commit details -
Configuration menu - View commit details
-
Copy full SHA for d4ad9dd - Browse repository at this point
Copy the full SHA d4ad9ddView commit details -
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.
Configuration menu - View commit details
-
Copy full SHA for 7f0d569 - Browse repository at this point
Copy the full SHA 7f0d569View commit details -
Configuration menu - View commit details
-
Copy full SHA for bbd5e62 - Browse repository at this point
Copy the full SHA bbd5e62View commit details
Commits on Jul 14, 2020
-
Configuration menu - View commit details
-
Copy full SHA for ae52af3 - Browse repository at this point
Copy the full SHA ae52af3View commit details -
Configuration menu - View commit details
-
Copy full SHA for f9653ab - Browse repository at this point
Copy the full SHA f9653abView commit details
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.