From: Klaus Jensen Date: Thu, 26 Jan 2023 08:52:41 +0000 (+0100) Subject: nvme-print: pretty print fdp event timestamp X-Git-Tag: v2.3~8^2 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=045b6bfa500f11dd80e5ad4ed92afaef1e132a5f;p=users%2Fsagi%2Fnvme-cli.git nvme-print: pretty print fdp event timestamp Properly parse the nvme timestamp of FDP events and print it. Signed-off-by: Klaus Jensen --- diff --git a/nvme-print.c b/nvme-print.c index 17e012f0..cabce68c 100644 --- a/nvme-print.c +++ b/nvme-print.c @@ -2498,7 +2498,7 @@ static void json_nvme_fdp_events(struct nvme_fdp_events_log *log) json_object_add_value_uint(obj_event, "type", event->type); json_object_add_value_uint(obj_event, "fdpef", event->flags); json_object_add_value_uint(obj_event, "pid", le16_to_cpu(event->pid)); - json_object_add_value_uint64(obj_event, "timestamp", le64_to_cpu(event->timestamp)); + json_object_add_value_uint64(obj_event, "timestamp", le64_to_cpu(*(uint64_t *)&event->ts)); json_object_add_value_uint(obj_event, "nsid", le32_to_cpu(event->nsid)); if (event->type == NVME_FDP_EVENT_REALLOC) { @@ -2539,6 +2539,10 @@ static const char *nvme_fdp_event_to_string(enum nvme_fdp_event_type event) void nvme_show_fdp_events(struct nvme_fdp_events_log *log, enum nvme_print_flags flags) { + struct tm *tm; + char buffer[320]; + time_t ts; + if (flags & BINARY) return d_raw((unsigned char*)log, sizeof(*log)); if (flags & JSON) @@ -2549,9 +2553,13 @@ void nvme_show_fdp_events(struct nvme_fdp_events_log *log, for (unsigned int i = 0; i < n; i++) { struct nvme_fdp_event *event = &log->events[i]; + ts = int48_to_long(event->ts.timestamp) / 1000; + tm = localtime(&ts); + printf("Event[%u]\n", i); printf(" Event Type: 0x%"PRIx8" (%s)\n", event->type, nvme_fdp_event_to_string(event->type)); - printf(" Event Timestamp: %"PRIu64"\n", le64_to_cpu(event->timestamp)); + printf(" Event Timestamp: %"PRIu64" (%s)\n", int48_to_long(event->ts.timestamp), + strftime(buffer, sizeof(buffer), "%c %Z", tm) ? buffer : "-"); if (event->flags & NVME_FDP_EVENT_F_PIV) printf(" Placement Identifier (PID): 0x%"PRIx16"\n", le16_to_cpu(event->pid));