From e4a1cd33b59a615530a19c5a4d99425204b8d776 Mon Sep 17 00:00:00 2001 From: Keith Busch Date: Tue, 17 Dec 2019 00:56:53 +0900 Subject: [PATCH] Fix intel json latency statistics output format Missing any support for the json output. Link: https://github.com/linux-nvme/nvme-cli/commit/b7eb621f1a998f9b7a58501fdf6e6773ddc937ff#commitcomment-36448196 Signed-off-by: Keith Busch --- plugins/intel/intel-nvme.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/plugins/intel/intel-nvme.c b/plugins/intel/intel-nvme.c index bcfb57d..64801e9 100644 --- a/plugins/intel/intel-nvme.c +++ b/plugins/intel/intel-nvme.c @@ -782,21 +782,25 @@ static void show_lat_stats(struct intel_lat_stats *stats, int write) static int get_lat_stats_log(int argc, char **argv, struct command *cmd, struct plugin *plugin) { struct intel_lat_stats stats; + enum nvme_print_flags flags; int err, fd; const char *desc = "Get Intel Latency Statistics log and show it."; const char *raw = "dump output in binary format"; const char *write = "Get write statistics (read default)"; struct config { + char *output_format; int raw_binary; int write; }; struct config cfg = { + .output_format = "normal", }; OPT_ARGS(opts) = { OPT_FLAG("write", 'w', &cfg.write, write), + OPT_FMT("output-format", 'o', &cfg.output_format, "Output format: normal|json|binary"), OPT_FLAG("raw-binary", 'b', &cfg.raw_binary, raw), OPT_END() }; @@ -805,16 +809,28 @@ static int get_lat_stats_log(int argc, char **argv, struct command *cmd, struct if (fd < 0) return fd; + err = flags = validate_output_format(cfg.output_format); + if (flags < 0) + goto close_fd; + + if (cfg.raw_binary) + flags = BINARY; + err = nvme_get_log(fd, NVME_NSID_ALL, cfg.write ? 0xc2 : 0xc1, false, sizeof(stats), &stats); if (!err) { - if (!cfg.raw_binary) - show_lat_stats(&stats, cfg.write); - else + if (flags & JSON) + json_lat_stats(&stats, cfg.write); + else if (flags & BINARY) d_raw((unsigned char *)&stats, sizeof(stats)); + else + show_lat_stats(&stats, cfg.write); } else if (err > 0) fprintf(stderr, "NVMe Status:%s(%x)\n", nvme_status_to_string(err), err); + +close_fd: + close(fd); return err; } -- 2.50.1