Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=arista.com header.i=@arista.com header.b="rKjfluoU" Received: from mail-il1-x162.google.com (mail-il1-x162.google.com [IPv6:2607:f8b0:4864:20::162]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B0314A5 for ; Tue, 5 Dec 2023 11:54:00 -0800 (PST) Received: by mail-il1-x162.google.com with SMTP id e9e14a558f8ab-35d725ac060so8842035ab.2 for ; Tue, 05 Dec 2023 11:54:00 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701806040; x=1702410840; h=content-transfer-encoding:message-id:date:subject:cc:to:from :dkim-signature:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=2pZbVC711RiY8zwNbtdCrL95s2KSwDCS/6iaVyA7+nw=; b=JFPvxK3NP/XdsB1Kx143fDn/CYJ+t47TiAGpFPg193zMypTWXipXLicPkX5+6QKAAs fzA6eppqcWxE8IyhZMRoifp3L+UKV15eEug41fE0PG1ymOoDdaKNd9Tcu6A8y1WtN0G3 0+seFox7q7ofiJYPBv21oL2127Zd3PjdLjIqA2iD6kIkP/jJaHrBhhaXGQD4VOsZc7by D2zTIkJ7BtzD0zMcFHv+mC22udUu7iRrWGNNW2G66OFRdFIYLtgpq6TX46Hxpbb9REc4 LpJKiBGK3RHEDN6/v0ySvAdhfmrME94eAdC20MqngYmj8+r3kviKmNyYRJQRqHz5m+RF 8BPw== X-Gm-Message-State: AOJu0Yy6Ee73w4jk17iiY3Wfz6PcoLzGu66b+cCsmctYyRXw4qDQd53s t+ujjbx2f4FxVivaATeMuQkpHTWfEKwUbB7qYAHyPuZpl3xe X-Google-Smtp-Source: AGHT+IGh2miTtfc42/i/yML4JaDpfo03wd+8HPgsu4vxAd/BFFIZO1ZvqNfoDDhl3esSfD356Z3naXks3sdE X-Received: by 2002:a92:cf43:0:b0:35d:59a2:1291 with SMTP id c3-20020a92cf43000000b0035d59a21291mr6974591ilr.61.1701806039997; Tue, 05 Dec 2023 11:53:59 -0800 (PST) Received: from smtp.aristanetworks.com ([74.123.28.25]) by smtp-relay.gmail.com with ESMTPS id p13-20020a92da4d000000b0035d69093b7dsm278911ilq.30.2023.12.05.11.53.59 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 05 Dec 2023 11:53:59 -0800 (PST) X-Relaying-Domain: arista.com Received: from rthukral-upstreamDmesgFix-1.sjc.aristanetworks.com (rthukral-upstreamDmesgFix-1-us310.sjc.aristanetworks.com [10.245.203.220]) by smtp.aristanetworks.com (Postfix) with ESMTP id 1213F400F82; Tue, 5 Dec 2023 11:53:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=arista.com; s=Arista-A; t=1701806039; bh=2pZbVC711RiY8zwNbtdCrL95s2KSwDCS/6iaVyA7+nw=; h=From:To:Cc:Subject:Date:From; b=rKjfluoU83wsq3I4dCMMaWWA493M3m9wJr9dvBUWTjJzpmicp35BjEpDnfzyYiGlK o3u5WeawyhRvwlCUHW9J1WOjJ0OzbXYikkkJSXLt1XkOaENaDX7U46dRI/jLlfTMEP hMbbmnMK1qmJi/FqKORi7NabIHGEkm15L8RJh3cpruW8WD51/ZmjOhA0SLPh1ppShI +Pol1UfSY0O6N9zYrcNzVVPG13IVgRiXRwVsPgJ3CJ7bRIo7WiZA8kCptHq7rnWGpc lNCBWKcUOL3AYg4MNq/JrJ6Wb/m354uqDexljkL6rJ6R9bm7GZ+p4KqmHzVu7BiAyt sVVGAD9nR9BRA== From: Rishabh Thukral To: util-linux@vger.kernel.org, kzak@redhat.com Cc: colona@arista.com, Rishabh Thukral Subject: [PATCH] util-linux/sys-utils dmesg support for additional human readable timestamp Date: Tue, 5 Dec 2023 11:53:33 -0800 Message-ID: <20231205195333.15832-1-rthukral@arista.com> Content-Transfer-Encoding: 8bit Precedence: bulk X-Mailing-List: util-linux@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: The dmesg logs have timestamps in seconds since boot format which can be converted to other formats. However, there is no option to include both the original timestamp as present in the buffer along with the converted timestamp in the specified format. This change updates the --time-format option in dmesg to enable the user to specify it multiple times with different formats with each input providing a timestamp format among the currently supported choices. This enables seeing the dmesg logs in both seconds since boot and human readable format simultaneously in each row of the log output. The sequence of timestamp format follows the order in which the user provides the desired formats. Signed-off-by: Rishabh Thukral --- sys-utils/dmesg.1.adoc | 4 +- sys-utils/dmesg.c | 257 ++++++++++++++++++++++++++--------------- 2 files changed, 168 insertions(+), 93 deletions(-) diff --git a/sys-utils/dmesg.1.adoc b/sys-utils/dmesg.1.adoc index 6f4941ede..16af7d940 100644 --- a/sys-utils/dmesg.1.adoc +++ b/sys-utils/dmesg.1.adoc @@ -133,9 +133,11 @@ Display record until the specified time. Supported is the subsecond granularity. Do not print kernel's timestamps. *--time-format* _format_:: -Print timestamps using the given _format_, which can be *ctime*, *reltime*, *delta* or *iso*. The first three formats are aliases of the time-format-specific options. The *iso* format is a *dmesg* implementation of the ISO-8601 timestamp format. The purpose of this format is to make the comparing of timestamps between two systems, and any other parsing, easy. The definition of the *iso* timestamp is: YYYY-MM-DDHH:MM:SS,<-+>. ++Print timestamps using the given _format_, which can be *ctime*, *reltime*, *delta*, *iso* or *raw*. The first three formats are aliases of the time-format-specific options. The *raw* format uses the default timestamp format showing seconds since boot. The *iso* format is a *dmesg* implementation of the ISO-8601 timestamp format. The purpose of this format is to make the comparing of timestamps between two systems, and any other parsing, easy. The definition of the *iso* timestamp is: YYYY-MM-DDHH:MM:SS,<-+>. + The *iso* format has the same issue as *ctime*: the time may be inaccurate when a system is suspended and resumed. ++ +*--time-format* may be used multiple times with different values for _format_ to output each specified format. *-u*, *--userspace*:: Print userspace messages. diff --git a/sys-utils/dmesg.c b/sys-utils/dmesg.c index 79e1c1690..866d2da52 100644 --- a/sys-utils/dmesg.c +++ b/sys-utils/dmesg.c @@ -161,7 +161,8 @@ enum { DMESG_TIMEFTM_TIME_DELTA, /* [time ] */ DMESG_TIMEFTM_ISO8601 /* 2013-06-13T22:11:00,123456+0100 */ }; -#define is_timefmt(c, f) ((c)->time_fmt == (DMESG_TIMEFTM_ ##f)) +#define TOTAL_DMESG_TIMESTAMP_FORMATS_SUPPORTED 8 +#define DEFAULT_TIMESTAMP_FORMAT DMESG_TIMEFTM_TIME struct dmesg_control { /* bit arrays -- see include/bitops.h */ @@ -199,7 +200,8 @@ struct dmesg_control { char *filename; char *mmap_buff; size_t pagesize; - unsigned int time_fmt; /* time format */ + size_t ntime_fmts; + unsigned int time_fmts[2 * TOTAL_DMESG_TIMESTAMP_FORMATS_SUPPORTED]; /* time format */ struct ul_jsonwrt jfmt; /* -J formatting */ @@ -316,7 +318,7 @@ static void __attribute__((__noreturn__)) usage(void) fputs(_(" -T, --ctime show human-readable timestamp (may be inaccurate!)\n"), out); fputs(_(" -t, --notime don't show any timestamp with messages\n"), out); fputs(_(" --time-format show timestamp using the given format:\n" - " [delta|reltime|ctime|notime|iso]\n" + " [delta|reltime|ctime|notime|iso|raw]\n" "Suspending/resume will make ctime and iso timestamps inaccurate.\n"), out); fputs(_(" --since