8#include <spdlog/spdlog.h>
11#include <tabulate/color.hpp>
12#include <tabulate/font_align.hpp>
13#include <tabulate/font_style.hpp>
14#include <tabulate/table.hpp>
15#include <tabulate/termcolor.hpp>
23 using Row = tabulate::Table::Row_t;
25 void format_solid_border(tabulate::Table& table)
27 table.format().border_top(
"─").border_bottom(
"─").border_left(
"│").border_right(
"│");
30 auto format_records(
const auto& records,
const Row& title_names,
auto row_adder) -> std::string
32 using namespace tabulate;
34 auto content_table = tabulate::Table{};
35 format_solid_border(content_table);
37 content_table.add_row(title_names);
38 for (
auto& cell : content_table.row(0))
40 cell.format().font_color(Color::yellow).font_align(FontAlign::center).font_style({ FontStyle::bold });
43 using native_type = std::remove_cvref_t<
decltype(records)>;
50 for (
const auto& [name, split_record] : records)
52 if constexpr (
is_vector_type<std::remove_cvref_t<
decltype(split_record)>>::value)
54 for (
const auto [n_pipe, record] : std::views::zip(std::views::iota(0), split_record))
59 row_adder(row, n_pipe, record);
60 content_table.add_row(row);
61 content_table.row(content_table.size() - 1).format().border_top(
"-");
62 content_table[content_table.size() - 1][0].format().border_top(
" ");
67 auto row = Row{ name };
68 row_adder(row, n_pipe, record);
69 content_table.add_row(row);
75 auto row = Row{ name };
76 row_adder(row, split_record);
77 content_table.add_row(row);
83 auto row = Row{ records.first };
84 row_adder(row, records.second);
85 content_table.add_row(row);
88 content_table.column(0).format().font_align(FontAlign::left);
90 for (
const auto [idx, _] :
91 std::views::zip(std::views::iota(std::size_t{}), title_names) | std::views::drop(1))
93 content_table.column(idx).format().font_align(FontAlign::center);
96 auto sstream = std::stringstream{};
97 sstream << termcolor::colorize << content_table;
108 "Bytes written (KB)",
110 [](Row& row,
int idx, std::size_t bytes)
112 const auto kb_written = bytes == 0 ? std::numeric_limits<double>::quiet_NaN()
113 :
static_cast<double>(bytes) / 1000.;
114 row.emplace_back(std::format(
"{}", idx));
115 row.emplace_back(std::format(
"{:.1f}", kb_written));
117 spdlog::debug(
"Bytes written to output sinks:\n{}", str);
130 [](Row& row,
int idx,
const TaskStat& stat)
132 const auto total_time_ms = stat.total_time_ms;
133 const auto ave_time =
134 stat.total_time_ms == 0
136 : 1e6 * stat.total_time_ms /
static_cast<double>(stat.total_sample_size);
137 row.push_back(std::format(
"{}", idx));
138 row.push_back(std::format(
"{:.1f}", total_time_ms));
139 row.push_back(std::format(
"{:.1f}", ave_time));
140 row.push_back(std::format(
"{}", stat.total_sample_size));
143 spdlog::debug(
"Performance report from required tasks:\n{}", str);
150 std::ranges::sort(stats,
151 [](
const auto& left,
const auto& right) ->
bool
152 {
return left.second.send_time < right.second.send_time; });
157 const auto first_time = stats.front().second.send_time;
158 for (
auto& [_, stat] : stats)
160 stat.send_time_offset = stat.send_time - first_time;
170 "Receiv latency (us)",
172 [](Row& row, int,
const auto& stats)
174 const auto& [remote_socket, stat] = stats;
175 row.push_back(std::format(
"{}", remote_socket));
176 row.push_back(std::format(
"{}", stat.connection_name));
177 row.push_back(std::format(
"{} (+{})", stat.send_time, stat.send_time_offset));
178 row.push_back(std::format(
"{}", stat.receiv_time - stat.send_time));
180 spdlog::debug(
"Performance report from sockets:\n{}", str);
188 "Avg. time (ns/frame)",
189 "Avg. bytes (/frame)",
192 [](Row& row,
const auto& stat)
194 const auto avg_time =
195 static_cast<double>(stat.total_time_ns) /
static_cast<double>(stat.n_frames);
197 const auto bytes_per_frame =
static_cast<double>(stat.total_bytes_read) /
198 static_cast<double>(stat.n_frames);
199 row.push_back(std::format(
"{:.1f}", avg_time));
200 row.push_back(std::format(
"{:.0f}", bytes_per_frame));
201 row.push_back(std::format(
"{}", stat.n_frames));
203 spdlog::debug(
"Performance report from frame reading processes:\n{}", str);
215 [](Row& row,
const auto& stat)
217 row.push_back(std::format(
"{}", stat.empty_trash));
218 row.push_back(std::format(
"{}", stat.full_trash));
219 row.push_back(std::format(
"{}", stat.full_valid));
221 spdlog::debug(
"Buffer Queue report:\n{}", str);
std::vector< std::pair< std::string, FrameReadingStat > > frame_reading_records_
std::pair< std::string_view, QueueStat > queue_record_
void report_buffer_result()
std::vector< std::pair< std::string, std::vector< std::pair< std::string, FecSwitchStat > > > > switch_socket_records_
void report_task_result()
std::map< std::string, std::vector< TaskStat > > task_records_
std::map< std::string, std::vector< std::size_t > > sink_records_
void report_socket_result()
void report_sink_file_result()
void report_frame_reading_result()