From 0f241355daf4e87917ff246e8af9bea241941ab9 Mon Sep 17 00:00:00 2001 From: Tomasz Sobczyk Date: Thu, 20 May 2021 13:22:11 +0200 Subject: [PATCH] Add output_file option to gather_statistics. It is optional. When specified it will also forward the final results output to the provided file. --- docs/stats.md | 2 ++ src/tools/stats.cpp | 20 +++++++++++++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/docs/stats.md b/docs/stats.md index 286788f8..8fe50ee5 100644 --- a/docs/stats.md +++ b/docs/stats.md @@ -10,6 +10,8 @@ Any name that doesn't designate an argument name or is not an argument will be i `input_file` - the path to the .bin or .binpack input file to read +`output_file` - optional path to the output file to write the results too. Results are always written on the console, so if this is specified the results will be written in both places. + `max_count` - the maximum number of positions to process. Default: no limit. ## Groups diff --git a/src/tools/stats.cpp b/src/tools/stats.cpp index 7e70f5a3..538b2a9e 100644 --- a/src/tools/stats.cpp +++ b/src/tools/stats.cpp @@ -1130,7 +1130,8 @@ namespace Stockfish::Tools::Stats void do_gather_statistics( const std::string& filename, StatisticGathererSet& statistic_gatherers, - std::uint64_t max_count) + std::uint64_t max_count, + const std::optional& output_filename) { Thread* th = Threads.main(); Position& pos = th->rootPos; @@ -1171,7 +1172,13 @@ namespace Stockfish::Tools::Stats std::cout << "Finished gathering statistics.\n\n"; std::cout << "Results:\n\n"; - std::cout << statistic_gatherers.get_output().to_string(); + const auto output_str = statistic_gatherers.get_output().to_string(); + std::cout << output_str; + if (output_filename.has_value()) + { + std::ofstream out_file(*output_filename); + out_file << output_str; + } } void gather_statistics(std::istringstream& is) @@ -1183,6 +1190,7 @@ namespace Stockfish::Tools::Stats StatisticGathererSet statistic_gatherers; std::string input_file; + std::optional output_file; std::uint64_t max_count = std::numeric_limits::max(); while(true) @@ -1195,13 +1203,19 @@ namespace Stockfish::Tools::Stats if (token == "input_file") is >> input_file; + else if (token == "output_file") + { + std::string s; + is >> s; + output_file = s; + } else if (token == "max_count") is >> max_count; else registry.add_statistic_gatherers_by_group(statistic_gatherers, token); } - do_gather_statistics(input_file, statistic_gatherers, max_count); + do_gather_statistics(input_file, statistic_gatherers, max_count, output_file); } }