mirror of
https://github.com/NVIDIA/nvbench.git
synced 2026-04-20 06:48:53 +00:00
Introduce jsonlist
This commit is contained in:
@@ -436,4 +436,66 @@ void json_printer::do_print_benchmark_results(const benchmark_vector &benches)
|
||||
m_ostream << root.dump(2) << "\n";
|
||||
}
|
||||
|
||||
void json_printer::do_print_benchmark_list(const benchmark_vector &benches)
|
||||
{
|
||||
if (benches.empty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
nlohmann::ordered_json root;
|
||||
auto &benchmarks = root["benchmarks"];
|
||||
|
||||
for (const auto &bench_ptr : benches)
|
||||
{
|
||||
const auto bench_index = benchmarks.size();
|
||||
auto &bench = benchmarks.emplace_back();
|
||||
|
||||
bench["name"] = bench_ptr->get_name();
|
||||
bench["index"] = bench_index;
|
||||
|
||||
// We have to ensure that the axes are represented as an array, not an
|
||||
// nil object when there are no axes.
|
||||
auto &axes = bench["axes"] = nlohmann::json::array();
|
||||
|
||||
for (const auto &axis_ptr : bench_ptr->get_axes().get_axes())
|
||||
{
|
||||
auto &axis = axes.emplace_back();
|
||||
|
||||
axis["name"] = axis_ptr->get_name();
|
||||
axis["type"] = axis_ptr->get_type_as_string();
|
||||
axis["flags"] = axis_ptr->get_flags_as_string();
|
||||
|
||||
auto &values = axis["values"];
|
||||
const auto axis_size = axis_ptr->get_size();
|
||||
for (std::size_t i = 0; i < axis_size; ++i)
|
||||
{
|
||||
auto &value = values.emplace_back();
|
||||
value["input_string"] = axis_ptr->get_input_string(i);
|
||||
value["description"] = axis_ptr->get_description(i);
|
||||
|
||||
switch (axis_ptr->get_type())
|
||||
{
|
||||
case nvbench::axis_type::int64:
|
||||
value["value"] = static_cast<int64_axis &>(*axis_ptr).get_value(i);
|
||||
break;
|
||||
|
||||
case nvbench::axis_type::float64:
|
||||
value["value"] = static_cast<float64_axis &>(*axis_ptr).get_value(i);
|
||||
break;
|
||||
|
||||
case nvbench::axis_type::string:
|
||||
value["value"] = static_cast<string_axis &>(*axis_ptr).get_value(i);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
} // end switch (axis type)
|
||||
} // end foreach axis value
|
||||
}
|
||||
} // end foreach bench
|
||||
|
||||
m_ostream << root.dump(2) << "\n";
|
||||
}
|
||||
|
||||
} // namespace nvbench
|
||||
|
||||
@@ -68,6 +68,7 @@ protected:
|
||||
const std::string &hint,
|
||||
const std::vector<nvbench::float64_t> &data) override;
|
||||
void do_print_benchmark_results(const benchmark_vector &benches) override;
|
||||
void do_print_benchmark_list(const benchmark_vector &) override;
|
||||
|
||||
bool m_enable_binary_output{false};
|
||||
std::size_t m_num_jsonbin_files{};
|
||||
|
||||
@@ -399,7 +399,14 @@ void option_parser::parse_range(option_parser::arg_iterator_t first,
|
||||
}
|
||||
else if (arg == "--list" || arg == "-l")
|
||||
{
|
||||
this->print_list();
|
||||
nvbench::markdown_printer printer{std::cout};
|
||||
this->print_list(printer);
|
||||
std::exit(0);
|
||||
}
|
||||
else if (arg == "--jsonlist" || arg == "-l")
|
||||
{
|
||||
nvbench::json_printer printer{std::cout};
|
||||
this->print_list(printer);
|
||||
std::exit(0);
|
||||
}
|
||||
else if (arg == "--persistence-mode" || arg == "--pm")
|
||||
@@ -580,11 +587,9 @@ void option_parser::print_version() const
|
||||
NVBENCH_GIT_VERSION);
|
||||
}
|
||||
|
||||
void option_parser::print_list() const
|
||||
void option_parser::print_list(printer_base& printer) const
|
||||
{
|
||||
const auto &bench_mgr = nvbench::benchmark_manager::get();
|
||||
|
||||
nvbench::markdown_printer printer{std::cout};
|
||||
printer.print_benchmark_list(bench_mgr.get_benchmarks());
|
||||
}
|
||||
|
||||
|
||||
@@ -79,7 +79,7 @@ private:
|
||||
std::ostream &printer_spec_to_ostream(const std::string &spec);
|
||||
|
||||
void print_version() const;
|
||||
void print_list() const;
|
||||
void print_list(printer_base& printer) const;
|
||||
void print_help() const;
|
||||
void print_help_axis() const;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user