merge bitcoin#24252: Represent paths with fs::path instead of std::string

This commit is contained in:
Kittywhiskers Van Gogh 2022-02-03 10:53:57 -05:00 committed by pasta
parent e41615572e
commit 357d1b6792
No known key found for this signature in database
GPG Key ID: 52527BEDABE87984
3 changed files with 11 additions and 10 deletions

View File

@ -18,20 +18,19 @@ const std::function<void(const std::string&)> G_TEST_LOG_FUN{};
namespace { namespace {
void GenerateTemplateResults(const std::vector<ankerl::nanobench::Result>& benchmarkResults, const std::string& filename, const char* tpl) void GenerateTemplateResults(const std::vector<ankerl::nanobench::Result>& benchmarkResults, const fs::path& file, const char* tpl)
{ {
if (benchmarkResults.empty() || filename.empty()) { if (benchmarkResults.empty() || file.empty()) {
// nothing to write, bail out // nothing to write, bail out
return; return;
} }
std::ofstream fout{fs::PathFromString(filename)}; std::ofstream fout{file};
if (fout.is_open()) { if (fout.is_open()) {
ankerl::nanobench::render(tpl, benchmarkResults, fout); ankerl::nanobench::render(tpl, benchmarkResults, fout);
std::cout << "Created " << file << std::endl;
} else { } else {
std::cout << "Could write to file '" << filename << "'" << std::endl; std::cout << "Could not write to file " << file << std::endl;
} }
std::cout << "Created '" << filename << "'" << std::endl;
} }
} // namespace } // namespace

View File

@ -5,6 +5,7 @@
#ifndef BITCOIN_BENCH_BENCH_H #ifndef BITCOIN_BENCH_BENCH_H
#define BITCOIN_BENCH_BENCH_H #define BITCOIN_BENCH_BENCH_H
#include <fs.h>
#include <util/macros.h> #include <util/macros.h>
#include <chrono> #include <chrono>
@ -44,8 +45,8 @@ struct Args {
std::string regex_filter; std::string regex_filter;
bool is_list_only; bool is_list_only;
std::vector<double> asymptote; std::vector<double> asymptote;
std::string output_csv; fs::path output_csv;
std::string output_json; fs::path output_json;
}; };
class BenchRunner class BenchRunner

View File

@ -5,6 +5,7 @@
#include <bench/bench.h> #include <bench/bench.h>
#include <crypto/sha256.h> #include <crypto/sha256.h>
#include <fs.h>
#include <stacktraces.h> #include <stacktraces.h>
#include <util/strencodings.h> #include <util/strencodings.h>
#include <util/system.h> #include <util/system.h>
@ -57,8 +58,8 @@ int main(int argc, char** argv)
args.regex_filter = argsman.GetArg("-filter", DEFAULT_BENCH_FILTER); args.regex_filter = argsman.GetArg("-filter", DEFAULT_BENCH_FILTER);
args.is_list_only = argsman.GetBoolArg("-list", false); args.is_list_only = argsman.GetBoolArg("-list", false);
args.asymptote = parseAsymptote(argsman.GetArg("-asymptote", "")); args.asymptote = parseAsymptote(argsman.GetArg("-asymptote", ""));
args.output_csv = argsman.GetArg("-output_csv", ""); args.output_csv = fs::PathFromString(argsman.GetArg("-output_csv", ""));
args.output_json = argsman.GetArg("-output_json", ""); args.output_json = fs::PathFromString(argsman.GetArg("-output_json", ""));
benchmark::BenchRunner::RunAll(args); benchmark::BenchRunner::RunAll(args);