Add output_multiplex.

This allows an arbitrary number of output_formats to be wrapped up
into a single object. This output format just forwards all calls to its
children.
This commit is contained in:
Allison Vacanti
2021-03-01 15:15:37 -05:00
parent 14d41bb7e1
commit 33a069af2b
3 changed files with 90 additions and 0 deletions

View File

@@ -13,6 +13,7 @@ set(srcs
markdown_format.cu
named_values.cu
option_parser.cu
output_multiplex.cu
runner.cu
state.cu
string_axis.cu

View File

@@ -0,0 +1,53 @@
#include <nvbench/output_multiplex.cuh>
#include <iostream>
namespace nvbench
{
output_multiplex::output_multiplex()
: output_format(std::cerr) // Nothing should write to this.
{}
void output_multiplex::do_print_device_info()
{
for (auto &format_ptr : m_formats)
{
format_ptr->print_device_info();
}
}
void output_multiplex::do_print_log_preamble()
{
for (auto &format_ptr : m_formats)
{
format_ptr->print_log_preamble();
}
}
void output_multiplex::do_print_log_epilogue()
{
for (auto &format_ptr : m_formats)
{
format_ptr->print_log_epilogue();
}
}
void output_multiplex::do_print_benchmark_list(const benchmark_vector &benches)
{
for (auto &format_ptr : m_formats)
{
format_ptr->print_benchmark_list(benches);
}
}
void output_multiplex::do_print_benchmark_results(
const benchmark_vector &benches)
{
for (auto &format_ptr : m_formats)
{
format_ptr->print_benchmark_results(benches);
}
}
} // namespace nvbench

View File

@@ -0,0 +1,36 @@
#pragma once
#include <nvbench/output_format.cuh>
#include <memory>
#include <vector>
namespace nvbench
{
/*!
* An nvbench::output_format that just forwards calls to other `output_format`s.
*/
struct output_multiplex : nvbench::output_format
{
output_multiplex();
template <typename Format, typename... Ts>
Format &emplace(Ts &&...ts)
{
m_formats.push_back(std::make_unique<Format>(std::forward<Ts>(ts)...));
return static_cast<Format &>(*m_formats.back());
}
private:
void do_print_device_info();
void do_print_log_preamble();
void do_print_log_epilogue();
void do_print_benchmark_list(const benchmark_vector &benches);
void do_print_benchmark_results(const benchmark_vector &benches);
std::vector<std::unique_ptr<nvbench::output_format>> m_formats;
};
} // namespace nvbench