Skip to content

Commit 6b11862

Browse files
committed
logging: output command and latency debug for json format
Use nvme_show_key_value() to output the message as json format. Also changed the dry_run variable name to dry_run_state since duplicated. Signed-off-by: Tokunori Ikegami <[email protected]>
1 parent c511dfd commit 6b11862

1 file changed

Lines changed: 31 additions & 30 deletions

File tree

util/logging.c

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,15 @@
1717

1818
#include "logging.h"
1919
#include "sighdl.h"
20+
#include "nvme-print.h"
2021

2122
struct submit_data {
2223
struct timeval start;
2324
struct timeval end;
2425
};
2526

2627
int log_level;
27-
static bool dry_run;
28+
static bool dry_run_state;
2829
static struct submit_data sb;
2930

3031
int map_log_level(int verbose, bool quiet)
@@ -59,49 +60,49 @@ int map_log_level(int verbose, bool quiet)
5960

6061
void set_dry_run(bool enable)
6162
{
62-
dry_run = enable;
63+
dry_run_state = enable;
6364
}
6465

6566
static void nvme_show_common(struct nvme_passthru_cmd *cmd)
6667
{
67-
printf("opcode : %02x\n", cmd->opcode);
68-
printf("flags : %02x\n", cmd->flags);
69-
printf("rsvd1 : %04x\n", cmd->rsvd1);
70-
printf("nsid : %08x\n", cmd->nsid);
71-
printf("cdw2 : %08x\n", cmd->cdw2);
72-
printf("cdw3 : %08x\n", cmd->cdw3);
73-
printf("data_len : %08x\n", cmd->data_len);
74-
printf("metadata_len : %08x\n", cmd->metadata_len);
75-
printf("addr : %"PRIx64"\n", (uint64_t)(uintptr_t)cmd->addr);
76-
printf("metadata : %"PRIx64"\n", (uint64_t)(uintptr_t)cmd->metadata);
77-
printf("cdw10 : %08x\n", cmd->cdw10);
78-
printf("cdw11 : %08x\n", cmd->cdw11);
79-
printf("cdw12 : %08x\n", cmd->cdw12);
80-
printf("cdw13 : %08x\n", cmd->cdw13);
81-
printf("cdw14 : %08x\n", cmd->cdw14);
82-
printf("cdw15 : %08x\n", cmd->cdw15);
83-
printf("timeout_ms : %08x\n", cmd->timeout_ms);
68+
nvme_show_key_value("opcode ", "%02x", cmd->opcode);
69+
nvme_show_key_value("flags ", "%02x", cmd->flags);
70+
nvme_show_key_value("rsvd1 ", "%04x", cmd->rsvd1);
71+
nvme_show_key_value("nsid ", "%08x", cmd->nsid);
72+
nvme_show_key_value("cdw2 ", "%08x", cmd->cdw2);
73+
nvme_show_key_value("cdw3 ", "%08x", cmd->cdw3);
74+
nvme_show_key_value("data_len ", "%08x", cmd->data_len);
75+
nvme_show_key_value("metadata_len ", "%08x", cmd->metadata_len);
76+
nvme_show_key_value("addr ", "%"PRIx64"", (uint64_t)(uintptr_t)cmd->addr);
77+
nvme_show_key_value("metadata ", "%"PRIx64"", (uint64_t)(uintptr_t)cmd->metadata);
78+
nvme_show_key_value("cdw10 ", "%08x", cmd->cdw10);
79+
nvme_show_key_value("cdw11 ", "%08x", cmd->cdw11);
80+
nvme_show_key_value("cdw12 ", "%08x", cmd->cdw12);
81+
nvme_show_key_value("cdw13 ", "%08x", cmd->cdw13);
82+
nvme_show_key_value("cdw14 ", "%08x", cmd->cdw14);
83+
nvme_show_key_value("cdw15 ", "%08x", cmd->cdw15);
84+
nvme_show_key_value("timeout_ms ", "%08x", cmd->timeout_ms);
8485
}
8586

8687
static void nvme_show_command(struct nvme_passthru_cmd *cmd, int err)
8788
{
8889
nvme_show_common(cmd);
89-
printf("result : %08x\n", cmd->result);
90-
printf("err : %d\n", err);
90+
nvme_show_key_value("result ", "%08x", cmd->result);
91+
nvme_show_key_value("err ", "%d", err);
9192
}
9293

9394
static void nvme_show_command64(struct nvme_passthru_cmd64 *cmd, int err)
9495
{
9596
nvme_show_common((struct nvme_passthru_cmd *)cmd);
96-
printf("result : %"PRIx64"\n", (uint64_t)(uintptr_t)cmd->result);
97-
printf("err : %d\n", err);
97+
nvme_show_key_value("result ", "%"PRIx64"", (uint64_t)(uintptr_t)cmd->result);
98+
nvme_show_key_value("err ", "%d", err);
9899
}
99100

100101
static void nvme_show_latency(struct timeval start, struct timeval end)
101102
{
102-
printf("latency : %llu us\n",
103-
(unsigned long long)((end.tv_sec - start.tv_sec) * 1000000 +
104-
(end.tv_usec - start.tv_usec)));
103+
nvme_show_key_value("latency ", "%llu us",
104+
(unsigned long long)((end.tv_sec - start.tv_sec) * 1000000 +
105+
(end.tv_usec - start.tv_usec)));
105106
}
106107

107108
static void nvme_log_retry(int errnum)
@@ -122,7 +123,7 @@ int nvme_submit_passthru(int fd, unsigned long ioctl_cmd,
122123
if (log_level >= LOG_DEBUG)
123124
gettimeofday(&start, NULL);
124125

125-
if (!dry_run) {
126+
if (!dry_run_state) {
126127
retry:
127128
err = ioctl(fd, ioctl_cmd, cmd);
128129
if (err && (errno == EAGAIN ||
@@ -155,7 +156,7 @@ int nvme_submit_passthru64(int fd, unsigned long ioctl_cmd,
155156
if (log_level >= LOG_DEBUG)
156157
gettimeofday(&start, NULL);
157158

158-
if (!dry_run) {
159+
if (!dry_run_state) {
159160
retry:
160161
err = ioctl(fd, ioctl_cmd, cmd);
161162
if (err && (errno == EAGAIN ||
@@ -197,8 +198,8 @@ static void nvme_show_req_admin(const struct nvme_mi_admin_req_hdr *hdr, size_t
197198
};
198199

199200
nvme_show_common(&cmd);
200-
printf("doff : %08x\n", le32_to_cpu(hdr->doff));
201-
printf("dlen : %08x\n", le32_to_cpu(hdr->dlen));
201+
nvme_show_key_value("doff ", "%08x", le32_to_cpu(hdr->doff));
202+
nvme_show_key_value("dlen ", "%08x", le32_to_cpu(hdr->dlen));
202203
}
203204

204205
static void nvme_show_req(__u8 type, const struct nvme_mi_msg_hdr *hdr, size_t hdr_len,

0 commit comments

Comments
 (0)