This commit is contained in:
Petr Písař 2018-03-13 09:58:01 +01:00
parent f103d57e24
commit 29dde2560b
7 changed files with 21 additions and 402 deletions

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
time-1.7.tar.gz
/time-1.8.tar.gz
/time-1.9.tar.gz

View File

@ -1 +1 @@
SHA512 (time-1.8.tar.gz) = 6337021407af1774cb6cd0b98d18531af3e393095776e86d1c6b192e6eca98ee8bd820fb27fc7c6355300654cfad61bb1385fa2212670a09ba4d54bb921c8abb
SHA512 (time-1.9.tar.gz) = 5c6dabbbe71e9103a47b892b86bb914c1704122d4fe7dff1e2cbd28503297163118d295077d8e062b035d673a1f91c36f8a45c7383f374fd766942b32bde4406

View File

@ -1,78 +0,0 @@
From 84648ef7951047728909a89333a85a0b27f22019 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= <ppisar@redhat.com>
Date: Thu, 9 Nov 2017 12:18:34 +0100
Subject: [PATCH] Accept numeric values in tests/time-posix-quiet.sh
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
tests/time-posix-quiet.sh failed randomly:
> --- out-q 2017-11-09 11:50:52.652813081 +0100
> +++ exp-q 2017-11-09 11:50:52.646813087 +0100
> @@ -1,2 +1,2 @@
> -user system :elapsed %CPU (avgtext+avgdata maxresident)k
> +user system :elapsed ?%CPU (avgtext+avgdata maxresident)k
> inputs+outputs (major+minor)pagefaults swaps
> FAIL tests/time-posix-quiet.sh (exit status: 1)
because the CPU usage was sometimes "0%CPU or "100%CPU" instead of expcted
"?%CPU".
This patch corrects the test.
Signed-off-by: Petr Písař <ppisar@redhat.com>
---
tests/time-posix-quiet.sh | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/tests/time-posix-quiet.sh b/tests/time-posix-quiet.sh
index 1e6f653..2a61d08 100755
--- a/tests/time-posix-quiet.sh
+++ b/tests/time-posix-quiet.sh
@@ -35,14 +35,14 @@ fail=
cat<<EOF > exp-default || framework_failure_ "failed to write exp-default"
Command exited with non-zero status
-user system :elapsed ?%CPU (avgtext+avgdata maxresident)k
+user system :elapsed %CPU (avgtext+avgdata maxresident)k
inputs+outputs (major+minor)pagefaults swaps
EOF
returns_ 1 env time -o out-def1 false || fail=1
# Remove the actual values (they'll differ every run)
-sed -e 's/[0-9.]*//g' -e 's/ *$//' out-def1 > out-default \
+sed -e 's/[0-9.?]*//g' -e 's/ *$//' out-def1 > out-default \
|| framework_failure_ "sed failed on out-def1"
compare_ out-default exp-default || fail=1
@@ -56,14 +56,14 @@ compare_ out-default exp-default || fail=1
## originally from Debian, "-q" supresses the "command exited..." message
cat<<EOF > exp-q || framework_failure_ "failed to write exp-q"
-user system :elapsed ?%CPU (avgtext+avgdata maxresident)k
+user system :elapsed %CPU (avgtext+avgdata maxresident)k
inputs+outputs (major+minor)pagefaults swaps
EOF
returns_ 1 env time -q -o out-q1 false || fail=1
# Remove the actual values (they'll differ every run)
-sed -e 's/[0-9.]*//g' -e 's/ *$//' out-q1 > out-q \
+sed -e 's/[0-9.?]*//g' -e 's/ *$//' out-q1 > out-q \
|| framework_failure_ "sed failed on out-q"
compare_ out-q exp-q || fail=1
@@ -82,7 +82,7 @@ EOF
returns_ 1 env time -p -o out-posix1 false || fail=1
# Remove the actual values (they'll differ every run)
-sed -e 's/[0-9.]*//g' -e 's/ *$//' out-posix1 > out-posix \
+sed -e 's/[0-9.?]*//g' -e 's/ *$//' out-posix1 > out-posix \
|| framework_failure_ "sed failed on out-posix1"
compare_ out-posix exp-posix || fail=1
--
2.13.6

View File

@ -1,75 +0,0 @@
From 5891844448acf635b95c6299c18391d4d68f0355 Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <hongjiu.lu@intel.com>
Date: Wed, 8 Nov 2017 16:50:21 +0100
Subject: [PATCH] Recompute CPU usage at microsecond level
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
If job finishes quickly, miliseconds arithmetic rounds to zero. If
that happens, recalculate CPU usage ratio with microsecond accuracy
to raise chance to get non-zero values.
Petr Pisar: Ported to 1.8.
Signed-off-by: Petr Písař <ppisar@redhat.com>
---
src/resuse.h | 1 +
src/time.c | 15 +++++++++++++++
2 files changed, 16 insertions(+)
diff --git a/src/resuse.h b/src/resuse.h
index a5edfaa..b21e2ad 100644
--- a/src/resuse.h
+++ b/src/resuse.h
@@ -23,6 +23,7 @@
/* Convert rusage's microseconds to miliseconds */
#define TV_MSEC tv_usec / 1000
+#define TV_USEC tv_usec
diff --git a/src/time.c b/src/time.c
index 9047374..9a3b042 100644
--- a/src/time.c
+++ b/src/time.c
@@ -429,6 +429,8 @@ summarize (fp, fmt, command, resp)
{
unsigned long r; /* Elapsed real milliseconds. */
unsigned long v; /* Elapsed virtual (CPU) milliseconds. */
+ unsigned long ru; /* Elapsed real microseconds. */
+ unsigned long vu; /* Elapsed virtual (CPU) microseconds. */
if (!quiet && output_format != posix_format)
{
@@ -453,6 +455,17 @@ summarize (fp, fmt, command, resp)
v = resp->ru.ru_utime.tv_sec * 1000 + resp->ru.ru_utime.TV_MSEC +
resp->ru.ru_stime.tv_sec * 1000 + resp->ru.ru_stime.TV_MSEC;
+ if (r == 0 && v == 0)
+ {
+ ru = resp->elapsed.tv_usec;
+ vu = resp->ru.ru_utime.TV_USEC + resp->ru.ru_stime.TV_USEC;
+ }
+ else
+ {
+ ru = 0;
+ vu = 0;
+ }
+
while (*fmt)
{
switch (*fmt)
@@ -510,6 +523,8 @@ summarize (fp, fmt, command, resp)
/* % cpu is (total cpu time)/(elapsed time). */
if (r > 0)
fprintf (fp, "%lu%%", (v * 100 / r));
+ else if (ru > 0)
+ fprintf (fp, "%lu%%", (vu * 100 / ru));
else
fprintf (fp, "?%%");
break;
--
2.13.6

View File

@ -1,171 +0,0 @@
From c5e97663cc9976e11ffa8491a6fdcb31702856ee Mon Sep 17 00:00:00 2001
From: Assaf Gordon <assafgordon@gmail.com>
Date: Wed, 8 Nov 2017 14:29:00 -0700
Subject: [PATCH] time: remove "Command exited with non-zero status" in POSIX
(-p) mode
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Suggested by Petr Pisar in
https://lists.gnu.org/archive/html/bug-time/2017-11/msg00001.html .
* src/time.c (summarize): Don't print the message in posix mode.
* tests/time-posix-quiet.sh: Test the output with -p and -q.
* Makefile.am (TESTS): Add new test.
* NEWS: Mention change.
Signed-off-by: Petr Písař <ppisar@redhat.com>
---
Makefile.am | 3 +-
NEWS | 10 ++++++
src/time.c | 2 +-
tests/time-posix-quiet.sh | 91 +++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 104 insertions(+), 2 deletions(-)
create mode 100755 tests/time-posix-quiet.sh
diff --git a/Makefile.am b/Makefile.am
index 30868db..861c3ae 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -75,7 +75,8 @@ tests_time_aux_CFLAGS =
TESTS = tests/help-version.sh \
tests/time-max-rss.sh \
- tests/time-exit-codes.sh
+ tests/time-exit-codes.sh \
+ tests/time-posix-quiet.sh
TEST_EXTENSIONS = .sh
diff --git a/NEWS b/NEWS
index 06a75bc..d05206f 100644
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,13 @@
+* Noteworthy changes in release ?.? (?-?-?) []
+
+** Changes in behaviour
+
+ "time -p" no longers adds the "Command exited with non-zero status" message.
+ This is a backward-incompatible change for better POSIX compliance.
+ Many downstream distributions previously patched 'time' to behave this way
+ (Debian added '-q', Fedora patched '-p').
+
+
* Noteworthy changes in release 1.8 (2017-11-07) [stable]
** Licensing
diff --git a/src/time.c b/src/time.c
index a6d99fb..6fa6c87 100644
--- a/src/time.c
+++ b/src/time.c
@@ -429,7 +429,7 @@ summarize (fp, fmt, command, resp)
unsigned long r; /* Elapsed real milliseconds. */
unsigned long v; /* Elapsed virtual (CPU) milliseconds. */
- if (!quiet)
+ if (!quiet && output_format != posix_format)
{
if (WIFSTOPPED (resp->waitstatus))
fprintf (fp, "Command stopped by signal %d\n",
diff --git a/tests/time-posix-quiet.sh b/tests/time-posix-quiet.sh
new file mode 100755
index 0000000..1e6f653
--- /dev/null
+++ b/tests/time-posix-quiet.sh
@@ -0,0 +1,91 @@
+#!/bin/sh
+
+# Test output quietness with -q and -p
+
+# Copyright (C) 2017 Assaf Gordon <assafgordon@gmail.com>
+#
+# This file is part of GNU Time.
+#
+# GNU Time is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# GNU Time is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GNU time. If not, see <http://www.gnu.org/licenses/>.
+
+# Written by Assaf Gordon
+. "${test_dir=.}/init.sh"
+
+which false > /dev/null || skip_ "'false' program required for this test"
+which sed > /dev/null || skip_ "'sed' program required for this test"
+
+fail=
+
+
+##
+## Default output
+##
+## Has extra "command exited with non-zero status" message
+
+cat<<EOF > exp-default || framework_failure_ "failed to write exp-default"
+Command exited with non-zero status
+user system :elapsed ?%CPU (avgtext+avgdata maxresident)k
+inputs+outputs (major+minor)pagefaults swaps
+EOF
+
+returns_ 1 env time -o out-def1 false || fail=1
+
+# Remove the actual values (they'll differ every run)
+sed -e 's/[0-9.]*//g' -e 's/ *$//' out-def1 > out-default \
+ || framework_failure_ "sed failed on out-def1"
+
+compare_ out-default exp-default || fail=1
+
+
+
+
+##
+## -q output
+##
+## originally from Debian, "-q" supresses the "command exited..." message
+
+cat<<EOF > exp-q || framework_failure_ "failed to write exp-q"
+user system :elapsed ?%CPU (avgtext+avgdata maxresident)k
+inputs+outputs (major+minor)pagefaults swaps
+EOF
+
+returns_ 1 env time -q -o out-q1 false || fail=1
+
+# Remove the actual values (they'll differ every run)
+sed -e 's/[0-9.]*//g' -e 's/ *$//' out-q1 > out-q \
+ || framework_failure_ "sed failed on out-q"
+
+compare_ out-q exp-q || fail=1
+
+
+##
+## -p (POSIX) output
+##
+## versions 1.8 and older add "Command exited with non-zero status" message.
+cat<<EOF > exp-posix || framework_failure_ "failed to write exp-posix"
+real
+user
+sys
+EOF
+
+returns_ 1 env time -p -o out-posix1 false || fail=1
+
+# Remove the actual values (they'll differ every run)
+sed -e 's/[0-9.]*//g' -e 's/ *$//' out-posix1 > out-posix \
+ || framework_failure_ "sed failed on out-posix1"
+
+compare_ out-posix exp-posix || fail=1
+
+
+exit $fail
--
2.13.6

View File

@ -1,56 +0,0 @@
From 5d15357e0858bd4dcf2788420ea544459d9e9b24 Mon Sep 17 00:00:00 2001
From: Assaf Gordon <assafgordon@gmail.com>
Date: Wed, 8 Nov 2017 14:49:51 -0700
Subject: [PATCH] time: use noreturn to pacify gcc-7
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Reported by Jim Meyering in
https://lists.gnu.org/archive/html/bug-time/2017-11/msg00000.html .
gcc-7 with --enable-gcc-warnings would warn about:
src/time.c: In function 'getargs':
src/time.c:664:4: warning: this statement may fall through
[-Wimplicit-fallthrough=]
usage (EXIT_SUCCESS);
^~~~~~~~~~~~~~~~~~~~
src/time.c:665:2: note: here
case 'o':
^~~~
This is a false-positive as usage() calls exit(3) and never returns
(but gcc seems unable to deduce that).
Use noreturn to suppress the warning.
* bootstrap.conf: Add gnulib's stdnoreturn module.
* src/time.c (usage): Mark as 'noreturn'.
Petr Písař: Ported to 1.8.
diff --git a/src/time.c b/src/time.c
index 6fa6c87..9047374 100644
--- a/src/time.c
+++ b/src/time.c
@@ -33,6 +33,7 @@
#include <errno.h>
#include <stdlib.h>
#include <stdbool.h>
+#include <stdnoreturn.h>
#include <string.h>
#include <limits.h>
#include <unistd.h>
@@ -214,7 +215,7 @@ static struct option longopts[] =
# define PROGRAM_NAME "time"
-static void
+noreturn static void
usage (int status)
{
if (status != EXIT_SUCCESS)
--
2.13.6

View File

@ -1,12 +1,13 @@
Summary: A GNU utility for monitoring a program's use of system resources
Name: time
Version: 1.8
Release: 3%{?dist}
Version: 1.9
Release: 1%{?dist}
# src/time.c: GPLv3+
# COPYING: GPLv3 text
# doc/time.texi: GFDL
# doc/fdl.texi: GFDL 1.3 text
# doc/time.info: GFDL
# lib/stdnoreturn.in.h: GPLv3+
# lib/strerror-override.c: GPLv3+
# lib/error.h: GPLv3+
## Not in a binary package
@ -16,6 +17,9 @@ Release: 3%{?dist}
# build-aux/install-sh: MIT and Public Domain
# build-aux/config.rpath: FSFULLR
# build-aux/test-driver: GPLv2+ with exceptions
# build-aux/update-copyright: GPLv3+
# build-aux/useless-if-before-free: GPLv3+
# build-aux/vc-list-files: GPLv3+
# build-aux/missing: GPLv2+ with exceptions
# build-aux/compile: GPLv2+ with exceptions
# build-aux/config.sub: GPLv3+ with exceptions
@ -24,25 +28,21 @@ Release: 3%{?dist}
# build-aux/texinfo.tex: GPLv3+ with exceptions
# build-aux/depcomp: GPLv2+ with exceptions
# build-aux/mdate-sh: GPLv2+ with exceptions
# m4/ssize_t.m4: FSFULLR
# m4/longlong.m4: FSFULLR
# GNUmakefile: GPLv3+
# m4/asm-underscore.m4: FSFULLR
# m4/gnulib-cache.m4: GPLv3+ with exceptions
# m4/host-cpu-c-abi.m4: FSFULLR
# m4/longlong.m4: FSFULLR
# m4/ssize_t.m4: FSFULLR
# m4/stdnoreturn.m4: FSFULLR
# maint.mk: GPLv3+
# tests/time-posix-quiet.sh: GPLv3+
License: GPLv3+ and GFDL
Url: http://www.gnu.org/software/%{name}/
Source: ftp://prep.ai.mit.edu/pub/gnu/%{name}/%{name}-%{version}.tar.gz
# Do not print command failure in POSIX mode, in upstream after 1.8
# <https://lists.gnu.org/archive/html/bug-time/2017-11/msg00001.html>
Patch0: time-1.8-time-remove-Command-exited-with-non-zero-status-in-P.patch
# Silent compiler warnings, in upstream after 1.8
Patch1: time-1.8-time-use-noreturn-to-pacify-gcc-7.patch
# Correct test added in
# time-remove-Command-exited-with-non-zero-status-in-P.patch
Patch2: time-1.8-Accept-numeric-values-in-tests-time-posix-quiet.sh.patch
# Bug #527276
Patch3: time-1.8-Recompute-CPU-usage-at-microsecond-level.patch
Source: ftp://ftp.gnu.org/gnu/%{name}/%{name}-%{version}.tar.gz
# Fix measuring time when a clock experiences a jump, bug #1004416,
# <http://lists.gnu.org/archive/html/bug-gnu-utils/2013-09/msg00003.html>
Patch4: time-1.8-Prefer-clock_gettime-CLOCK_MONOTONIC.patch
Patch0: time-1.8-Prefer-clock_gettime-CLOCK_MONOTONIC.patch
BuildRequires: autoconf
BuildRequires: automake
BuildRequires: bash
@ -63,11 +63,6 @@ the results.
%prep
%setup -q
%patch0 -p1
chmod +x tests/time-posix-quiet.sh
%patch1 -p1
%patch2 -p1
%patch3 -p1
%patch4 -p1
autoreconf -fi
%build
@ -99,6 +94,9 @@ fi
%{_infodir}/time.info*
%changelog
* Tue Mar 13 2018 Petr Pisar <ppisar@redhat.com> - 1.9-1
- 1.9 bump
* Fri Feb 09 2018 Fedora Release Engineering <releng@fedoraproject.org> - 1.8-3
- Rebuilt for https://fedoraproject.org/wiki/Fedora_28_Mass_Rebuild