From nobody Wed Nov 02 12:35:53 2022 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4N2RFP4wlLz4h4Ts; Wed, 2 Nov 2022 12:35:53 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4N2RFP3shkz43lD; Wed, 2 Nov 2022 12:35:53 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1667392553; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=kXAix9wvIgI/9KVRDQjOTDHPnedab6+4oPlM3+Bir8g=; b=Xy4U/inJEeowPCnp+KLrf76KxSaE7cGU8T6z5fg/rhqg21YTJP0uHB3gUhsOlq7nFJXrLw kcXYdjFaZBoW14Cv+JBc1UiI2ofl0oM0P/bhQzGhA7Bp4bKco3vYSztgnI1eb9mhoxjsd2 0OhXdLeH+7raLBy5l/tUl5wwhx2R7RHqZ5wyqxntBlS7JaoS1XF2516nKQuBPXNNMLm27J qEOLhOkBbSQsSxLhU+R1V3cY3FzCMxDMSO6QsGFC092i/LZQvd7W8Vly6VIFyYNbugnJiQ wz5nqCkDGlgJAV2jUWlxnI0QwTGEmmuMFAJWSr7X5vyZqxhdP9HUKlSVwxNZyg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4N2RFP2hXWzwLD; Wed, 2 Nov 2022 12:35:53 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 2A2CZrU5081282; Wed, 2 Nov 2022 12:35:53 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 2A2CZrhb081281; Wed, 2 Nov 2022 12:35:53 GMT (envelope-from git) Date: Wed, 2 Nov 2022 12:35:53 GMT Message-Id: <202211021235.2A2CZrhb081281@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: =?utf-8?Q?Dag-Erling=20Sm=C3=B8rgrav?= Subject: git: 9ba17e2d1c2f - stable/13 - script add -T fmt to print time-stamps List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: des X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 9ba17e2d1c2ffc9d00ce020d53523365a0d85f1b Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1667392553; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=kXAix9wvIgI/9KVRDQjOTDHPnedab6+4oPlM3+Bir8g=; b=boUuBlay9TEso35u1VEOLxzndc0NGEiHdDAEQCbxXQCFYXWhaCRgxWAJMQBvuf8O7EYOns TXGbnupM4F8c1PXsBQ4ZQG2Sf/ggV4EjQVFrwB8cIdd4kwfvPIZ4bYUpn4tMpeKZwiQjJk DEeoXaisOBfdnORTJvUUHkKWctroW9RFSicnG5PzhmdyR8yWWej7gskroY7Jm/ST/hpcF7 6B2HR/zKvI+syQraKc/odFRT57MCFSFoEVomXPlNggaKIfPnaoP8s23HjdR3NpZ7LNzSDP PW0HpkWrWq/iEH4in0LvwatZwcr6zPc2WtS/QZAFSaRwV67paVS4vyOM6tjtgg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1667392553; a=rsa-sha256; cv=none; b=RcRVB52waXdcnhTsN4jJvvP70k0tHzUg3zMhsfKx3t3InUJc1/CDc0LWejI2YMXe/ziFLR 0vje0RDBYFnsVek+aNbdvr5DskXLA83cCfZJhX0jRZXtt20KOOIbI+glnli0RAJTK+C/IO NYyWzLH6MD+UOYsP5O04rEr8E8lem1dIra76dFX4TxUy12WC7uG5x1uYEYrZA/wSXWU31s n7D7Vo4Vo4iPmvNMS5WjyySCUDqgsVBPohAWU/u6IllwvedusbmZ/bOX0laGXJvNz6Jopt 9XcueEaFDcZZV1O8v9rzW18gAaEXGhipkzzCwRv3/yd7Muv2pxktQEfs4D38TQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=9ba17e2d1c2ffc9d00ce020d53523365a0d85f1b commit 9ba17e2d1c2ffc9d00ce020d53523365a0d85f1b Author: Simon J. Gerraty AuthorDate: 2022-03-09 21:33:03 +0000 Commit: Dag-Erling Smørgrav CommitDate: 2022-11-02 09:44:46 +0000 script add -T fmt to print time-stamps script -r is useful for recording time-stamps of when output happened. With -T, rather than playback the script in real-time we simply print the time-stamps to show when the output happened. This is very useful for example, for analyzing boot time activity. If the fmt provided contains no % characters the default %n@ %s [%Y-%m-%d %T] is used, which lends itself to analysis by tools as well as humans. Sponsored by: Juniper Networks, Inc. Reviewed by: allanjude Differential Revision: https://reviews.freebsd.org/D34511 (cherry picked from commit 6c4afed5667a65f3c5bd308a934e7de8c0526954) script -T skip timstamps for same second The result is much more readable if we only output the time-stamp when it is at least 1s since last one. (cherry picked from commit 7b45ad3f89cc4d65a23f7d034329dd3f8dd3105f) script: use %n at the end of default tstamp_fmt Since we are only outputting time-stamps when they differ ending it with a newline, interferes with the output less. (cherry picked from commit 31fde973577d0e09caccf0d762135bfa6b14f1f3) --- usr.bin/script/script.1 | 18 +++++++++++++++++- usr.bin/script/script.c | 43 ++++++++++++++++++++++++++++++++++--------- 2 files changed, 51 insertions(+), 10 deletions(-) diff --git a/usr.bin/script/script.1 b/usr.bin/script/script.1 index 04fa75fc1612..36523148fa90 100644 --- a/usr.bin/script/script.1 +++ b/usr.bin/script/script.1 @@ -28,7 +28,7 @@ .\" @(#)script.1 8.1 (Berkeley) 6/6/93 .\" $FreeBSD$ .\" -.Dd January 5, 2021 +.Dd March 9, 2022 .Dt SCRIPT 1 .Os .Sh NAME @@ -43,6 +43,7 @@ .Nm .Fl p .Op Fl deq +.Op Fl T Ar fmt .Op Ar file .Sh DESCRIPTION The @@ -119,6 +120,21 @@ causes to flush after every character I/O event. The default interval is 30 seconds. +.It Fl T Ar fmt +Implies +.Fl p , +but just reports the time-stamp of each output. +This is very useful for assessing the timing of events. +.Pp +If +.Ar fmt +does not contain any +.Ql % +characters, it indicates the default format: +.Ql %n@ %s [%Y-%m-%d %T]%n , +which is useful for both tools and humans to read, should be used. +Note that time-stamps will only be output when different from the +previous one. .El .Pp The script ends when the forked shell (or command) exits (a diff --git a/usr.bin/script/script.c b/usr.bin/script/script.c index 9c18dc73390f..430f48ad63df 100644 --- a/usr.bin/script/script.c +++ b/usr.bin/script/script.c @@ -89,6 +89,13 @@ static TAILQ_HEAD(, buf_elm) obuf_list = TAILQ_HEAD_INITIALIZER(obuf_list); static struct termios tt; +#ifndef TSTAMP_FMT +/* useful for tool and human reading */ +# define TSTAMP_FMT "%n@ %s [%Y-%m-%d %T]%n" +#endif +static const char *tstamp_fmt = TSTAMP_FMT; +static int tflg; + static void done(int) __dead2; static void doshell(char **); static void finish(void); @@ -121,7 +128,7 @@ main(int argc, char *argv[]) warning. (not needed w/clang) */ showexit = 0; - while ((ch = getopt(argc, argv, "adeFfkpqrt:")) != -1) + while ((ch = getopt(argc, argv, "adeFfkpqrT:t:")) != -1) switch(ch) { case 'a': aflg = 1; @@ -154,6 +161,11 @@ main(int argc, char *argv[]) if (flushtime < 0) err(1, "invalid flush time %d", flushtime); break; + case 'T': + tflg = pflg = 1; + if (strchr(optarg, '%')) + tstamp_fmt = optarg; + break; case '?': default: usage(); @@ -511,12 +523,14 @@ playback(FILE *fp) off_t nread, save_len; size_t l; time_t tclock; + time_t lclock; int reg; if (fstat(fileno(fp), &pst) == -1) err(1, "fstat failed"); reg = S_ISREG(pst.st_mode); + lclock = 0; for (nread = 0; !reg || nread < pst.st_size; nread += save_len) { if (fread(&stamp, sizeof(stamp), 1, fp) != 1) { @@ -559,15 +573,26 @@ playback(FILE *fp) (void)consume(fp, stamp.scr_len, buf, reg); break; case 'o': - tsi.tv_sec = tso.tv_sec - tsi.tv_sec; - tsi.tv_nsec = tso.tv_nsec - tsi.tv_nsec; - if (tsi.tv_nsec < 0) { - tsi.tv_sec -= 1; - tsi.tv_nsec += 1000000000; + if (tflg) { + if (stamp.scr_len == 0) + continue; + if (tclock - lclock > 0) { + l = strftime(buf, sizeof buf, tstamp_fmt, + localtime(&tclock)); + (void)write(STDOUT_FILENO, buf, l); + } + lclock = tclock; + } else { + tsi.tv_sec = tso.tv_sec - tsi.tv_sec; + tsi.tv_nsec = tso.tv_nsec - tsi.tv_nsec; + if (tsi.tv_nsec < 0) { + tsi.tv_sec -= 1; + tsi.tv_nsec += 1000000000; + } + if (usesleep) + (void)nanosleep(&tsi, NULL); + tsi = tso; } - if (usesleep) - (void)nanosleep(&tsi, NULL); - tsi = tso; while (stamp.scr_len > 0) { l = MIN(DEF_BUF, stamp.scr_len); if (fread(buf, sizeof(char), l, fp) != l)