Add state::get_axis_values_as_string for JSON output.

This commit is contained in:
Allison Vacanti
2021-03-05 18:58:36 -05:00
parent 922a6d09d0
commit 845c9ac662
3 changed files with 19 additions and 3 deletions

View File

@@ -182,7 +182,7 @@ void json_printer::do_print_benchmark_results(const benchmark_vector &benches)
auto &st = states[state_index];
st["index"] = state_index;
st["description"] = exec_state.get_short_description();
st["description"] = exec_state.get_axis_values_as_string();
st["device"] = exec_state.get_device()->get_id();
st["type_config_index"] = exec_state.get_type_config_index();

View File

@@ -112,7 +112,7 @@ const std::vector<summary> &state::get_summaries() const { return m_summaries; }
std::vector<summary> &state::get_summaries() { return m_summaries; }
std::string state::get_short_description(bool color) const
std::string state::get_axis_values_as_string(bool color) const
{
// Returns fmt_style if color is true, otherwise no style flags.
auto style = [&color](auto fmt_style) {
@@ -161,10 +161,21 @@ std::string state::get_short_description(bool color) const
}
}
return fmt::to_string(buffer);
}
std::string state::get_short_description(bool color) const
{
// Returns fmt_style if color is true, otherwise no style flags.
auto style = [&color](auto fmt_style) {
const fmt::text_style no_style;
return color ? fmt_style : no_style;
};
return fmt::format(
"{} [{}]",
fmt::format(style(fmt::emphasis::bold), "{}", m_benchmark.get().get_name()),
fmt::to_string(buffer));
this->get_axis_values_as_string(color));
}
void state::add_element_count(std::size_t elements, std::string column_name)

View File

@@ -176,6 +176,11 @@ struct state
return m_axis_values;
}
/*!
* Return a string of "axis_name1=input_string1 axis_name2=input_string2 ..."
*/
[[nodiscard]] std::string get_axis_values_as_string(bool color = false) const;
[[nodiscard]] const benchmark_base &get_benchmark() const
{
return m_benchmark;