]> www.infradead.org Git - users/sagi/nvme-cli.git/commitdiff
nvme-print: pretty print fdp event timestamp
authorKlaus Jensen <k.jensen@samsung.com>
Thu, 26 Jan 2023 08:52:41 +0000 (09:52 +0100)
committerKlaus Jensen <k.jensen@samsung.com>
Thu, 26 Jan 2023 13:54:56 +0000 (14:54 +0100)
Properly parse the nvme timestamp of FDP events and print it.

Signed-off-by: Klaus Jensen <k.jensen@samsung.com>
nvme-print.c

index 17e012f0437f2a12f27c1a5e577a26b5edad2acd..cabce68cd21b0443011183631dd90ab1a33823d8 100644 (file)
@@ -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));