mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-03 09:56:38 -05:00
bench: Represents paths with fs::path instead of std::string
Also uses fs::path quoting in bench printed strings and fixes a misleading error message. Originally suggested https://github.com/bitcoin/bitcoin/pull/20744#issuecomment-1022486215 Co-authored-by: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com>
This commit is contained in:
parent
3ace3a17c9
commit
824e1ffa9f
3 changed files with 11 additions and 10 deletions
|
@ -24,20 +24,19 @@ const std::function<std::vector<const char*>()> G_TEST_COMMAND_LINE_ARGUMENTS{};
|
|||
|
||||
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
|
||||
return;
|
||||
}
|
||||
std::ofstream fout{fs::PathFromString(filename)};
|
||||
std::ofstream fout{file};
|
||||
if (fout.is_open()) {
|
||||
ankerl::nanobench::render(tpl, benchmarkResults, fout);
|
||||
std::cout << "Created " << file << std::endl;
|
||||
} 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
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#ifndef BITCOIN_BENCH_BENCH_H
|
||||
#define BITCOIN_BENCH_BENCH_H
|
||||
|
||||
#include <fs.h>
|
||||
#include <util/macros.h>
|
||||
|
||||
#include <chrono>
|
||||
|
@ -44,8 +45,8 @@ struct Args {
|
|||
bool is_list_only;
|
||||
std::chrono::milliseconds min_time;
|
||||
std::vector<double> asymptote;
|
||||
std::string output_csv;
|
||||
std::string output_json;
|
||||
fs::path output_csv;
|
||||
fs::path output_json;
|
||||
std::string regex_filter;
|
||||
};
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
#include <clientversion.h>
|
||||
#include <crypto/sha256.h>
|
||||
#include <fs.h>
|
||||
#include <util/strencodings.h>
|
||||
#include <util/system.h>
|
||||
|
||||
|
@ -108,8 +109,8 @@ int main(int argc, char** argv)
|
|||
args.asymptote = parseAsymptote(argsman.GetArg("-asymptote", ""));
|
||||
args.is_list_only = argsman.GetBoolArg("-list", false);
|
||||
args.min_time = std::chrono::milliseconds(argsman.GetIntArg("-min_time", DEFAULT_MIN_TIME_MS));
|
||||
args.output_csv = argsman.GetArg("-output_csv", "");
|
||||
args.output_json = argsman.GetArg("-output_json", "");
|
||||
args.output_csv = fs::PathFromString(argsman.GetArg("-output_csv", ""));
|
||||
args.output_json = fs::PathFromString(argsman.GetArg("-output_json", ""));
|
||||
args.regex_filter = argsman.GetArg("-filter", DEFAULT_BENCH_FILTER);
|
||||
|
||||
benchmark::BenchRunner::RunAll(args);
|
||||
|
|
Loading…
Add table
Reference in a new issue