From nobody Wed Mar 09 21:33:15 2022 X-Original-To: dev-commits-src-main@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 A39DE19F77A6; Wed, 9 Mar 2022 21:33:15 +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 4KDQRH4CQhz3qx5; Wed, 9 Mar 2022 21:33:15 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1646861595; 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=Je3hjJfJJHzj2mLEe2U8Pr9wa27qiIV6+vUSWCqFrEE=; b=d3Jm6XRIG0HQSlElRPEX3BNhEpw4ouLqQVJ+FPCHncwO8EOHh+L9G4q8UPocw5DxdTdj6V UtbQwfWzztk4ti2RPN9Jecg9CQ1dkRu2wmAfFbwi8G3l+cN5gPpmu8Sow0eMga5hXPuq92 KnalOC/BAqUiEECedQZo7el5acqWD6S2a0pWD/qZpZTKg9C8pnrHbxAIrmTkKq0t6XPbTN zwIymhvt7n59qC6yfCKCWe1VqcV056Ddc8IPhFmWnTs1sN6gxVf/7FseQaSMYVB7Kp7SeG bIiKEN7g/gNRwe/0EB+PUW5rVoFb+OfJumFkzlNDdi3Bpbkwdm2WGkDjDINY2w== 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 7032818A74; Wed, 9 Mar 2022 21:33:15 +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 229LXFxr016857; Wed, 9 Mar 2022 21:33:15 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 229LXFvG016856; Wed, 9 Mar 2022 21:33:15 GMT (envelope-from git) Date: Wed, 9 Mar 2022 21:33:15 GMT Message-Id: <202203092133.229LXFvG016856@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: "Simon J. Gerraty" Subject: git: 6c4afed5667a - main - script add -T fmt to print time-stamps List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: sjg X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 6c4afed5667a65f3c5bd308a934e7de8c0526954 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1646861595; 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=Je3hjJfJJHzj2mLEe2U8Pr9wa27qiIV6+vUSWCqFrEE=; b=F0JlrFt1KoCBWkUyGaPie4OYQMqllweQ10XyNXu5HHyO13y81DqJ0U3rtJDLegi/7fokUO 7RpQw1ccztJf9SB1k87fregJYcRhrApEgXehPuVIzobY9GgS0uCe/20w506nv3k0uB6ddc 9MnjhDpyaMw8YFrFXgZh2e96IHUYigk9Gp+PB6hBo5531OHWZPmhkeFAMVrXjIY8rYszIT 2jGZQgdS/domPGlIMk2q3eEaMrPpyWeBhsD33vFuuCmQf+6Xy2+eaWoidQIk7Nybo1oNYL tO05zA4Kb1G7DHe2qJaGKb7PzT0BXhkVfXu9I/NBCOcc4Y7IYD4Dap6K+Y8Hgw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1646861595; a=rsa-sha256; cv=none; b=i9GXtfP/MGp98PumOGNksMh6tKgrghmkCG9MCFp2O0X8qTynu/Zsp3FhF1B1gawAYnsVMq Bvk7nZx1sABLWsB7S5vfBdcIX9SNpxeCX245QDfhAyRnXB/MiMDe1KB3vFYNBNw6gGfBRx 7TBFu8mBizvAkCh2nXGEf9poHLmNSbqqBU8QqzdoEVkJDIg56QKb3fPEGtN6ttBzSyIg0B liRjRpvwTsx5zJf7sQY1XOjrt77bW3aIUEOEluxja+uLKIpmDQf0gKUvRBLbNcLUGy3mQV m4cB0Jbs3oUsCS2/KMnVQBfU4N6I1XWNTDLlIDwToRCceLVn3+COZHS6sgThYw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by sjg: URL: https://cgit.FreeBSD.org/src/commit/?id=6c4afed5667a65f3c5bd308a934e7de8c0526954 commit 6c4afed5667a65f3c5bd308a934e7de8c0526954 Author: Simon J. Gerraty AuthorDate: 2022-03-09 21:33:03 +0000 Commit: Simon J. Gerraty CommitDate: 2022-03-09 21:33:03 +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 --- usr.bin/script/script.1 | 16 +++++++++++++++- usr.bin/script/script.c | 38 +++++++++++++++++++++++++++++--------- 2 files changed, 44 insertions(+), 10 deletions(-) diff --git a/usr.bin/script/script.1 b/usr.bin/script/script.1 index 04fa75fc1612..e6c422b476f5 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,19 @@ 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]\ , +which is useful for both tools and humans to read, should be used. .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..2e540a935ecd 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] " +#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(); @@ -559,15 +571,23 @@ 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; + l = strftime(buf, sizeof buf, tstamp_fmt, + localtime(&tclock)); + (void)write(STDOUT_FILENO, buf, l); + } 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)