From: Edwin Rodriguez Date: Wed, 24 Jun 2026 13:06:58 +0000 (-0400) Subject: cephfs-tool: add stdout output support for JSON benchmark results X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=eb107111d6d2abecc6e660f66c3b76af5793e912;p=ceph.git cephfs-tool: add stdout output support for JSON benchmark results Signed-off-by: Edwin Rodriguez --- diff --git a/doc/cephfs/cephfs-tool.rst b/doc/cephfs/cephfs-tool.rst index 334ba5786ae9..1083d17a0df1 100644 --- a/doc/cephfs/cephfs-tool.rst +++ b/doc/cephfs/cephfs-tool.rst @@ -140,7 +140,7 @@ These options are used with the ``bench`` command. .. option:: --json - Write structured benchmark results to a JSON file + Write structured benchmark results to a JSON file. Use ``-`` to output to stdout. .. option:: --duration diff --git a/src/tools/cephfs/cephfs-tool.cc b/src/tools/cephfs/cephfs-tool.cc index aa393cb55b34..7fe308e596ed 100644 --- a/src/tools/cephfs/cephfs-tool.cc +++ b/src/tools/cephfs/cephfs-tool.cc @@ -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(&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(&config.json_path), "Output results to a JSON file") + ("json", po::value(&config.json_path), "Output results to a JSON file (use '-' for stdout)") ("duration", po::value(&config.duration)->default_value(0), "Limit each phase to N seconds (0 = no limit)") ("perf-dump", po::value(&config.perf_dump_path), "File to dump performance counters to") ("progress", po::bool_switch(&config.show_progress), "Show progress and current bandwidth during benchmark")