]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
cephfs-tool: add stdout output support for JSON benchmark results
authorEdwin Rodriguez <edwin.rodriguez1@ibm.com>
Wed, 24 Jun 2026 13:06:58 +0000 (09:06 -0400)
committerEdwin Rodriguez <edwin.rodriguez1@ibm.com>
Wed, 1 Jul 2026 13:11:15 +0000 (09:11 -0400)
Signed-off-by: Edwin Rodriguez <edwin.rodriguez1@ibm.com>
doc/cephfs/cephfs-tool.rst
src/tools/cephfs/cephfs-tool.cc

index 334ba5786ae944d93a921cece6d07eb772ca9d3e..1083d17a0df1296e3693e65c7f7b33b87d8801df 100644 (file)
@@ -140,7 +140,7 @@ These options are used with the ``bench`` command.
 
 .. option:: --json <path>
 
-   Write structured benchmark results to a JSON file
+   Write structured benchmark results to a JSON file. Use ``-`` to output to stdout.
 
 .. option:: --duration <seconds>
 
index aa393cb55b346723cc8425671754096f01861273..7fe308e596ed1d24b06bb0ffbd14aef65a482503 100644 (file)
@@ -1721,13 +1721,20 @@ int do_bench(BenchConfig& config) {
   if (json_formatter) {
     json_formatter->close_section(); // summary
     json_formatter->close_section(); // benchmark
-    std::ofstream ofs(config.json_path);
-    if (ofs.is_open()) {
-      json_formatter->flush(ofs);
-      cout << "\nResults saved to " << config.json_path << std::endl;
+    if (config.json_path == "-") {
+      // Output to stdout
+      json_formatter->flush(cout);
+      cout << std::endl;
     } else {
-      cerr << "\nError: Could not open " << config.json_path << " for writing."
-           << std::endl;
+      // Output to file
+      std::ofstream ofs(config.json_path);
+      if (ofs.is_open()) {
+        json_formatter->flush(ofs);
+        cout << "\nResults saved to " << config.json_path << std::endl;
+      } else {
+        cerr << "\nError: Could not open " << config.json_path << " for writing."
+             << std::endl;
+      }
     }
   }
 
@@ -1808,7 +1815,7 @@ int main(int argc, char **argv) {
     ("root-path", po::value<string>(&config.mount_root)->default_value("/"), "Root path in CephFS")
     ("per-thread-mount", po::bool_switch(&config.per_thread_mount), "Use separate mount per thread")
     ("no-cleanup", po::bool_switch(&no_cleanup), "Disable cleanup of files")
-    ("json", po::value<string>(&config.json_path), "Output results to a JSON file")
+    ("json", po::value<string>(&config.json_path), "Output results to a JSON file (use '-' for stdout)")
     ("duration", po::value<int>(&config.duration)->default_value(0), "Limit each phase to N seconds (0 = no limit)")
     ("perf-dump", po::value<string>(&config.perf_dump_path), "File to dump performance counters to")
     ("progress", po::bool_switch(&config.show_progress), "Show progress and current bandwidth during benchmark")