clang-format

This commit is contained in:
Guillaume Meunier
2024-03-30 17:00:34 +01:00
parent bb660cfb3f
commit 9cceaac648
122 changed files with 2904 additions and 2783 deletions
+80 -94
View File
@@ -25,8 +25,8 @@
#include "implot.h"
#include "utils/ranges.h"
#include <cmath>
#include <spdlog/spdlog.h>
#include <limits>
#include <spdlog/spdlog.h>
namespace
{
@@ -34,9 +34,9 @@ float compute_plot_max_value(float * data, int count, ptrdiff_t stride)
{
float max = 0;
uintptr_t ptr = (uintptr_t)data;
for(int i = 0; i < count; i++)
for (int i = 0; i < count; i++)
{
max = std::max(max, *(float*)(ptr + i * stride));
max = std::max(max, *(float *)(ptr + i * stride));
}
// First power of 10 less than the max
@@ -47,18 +47,18 @@ float compute_plot_max_value(float * data, int count, ptrdiff_t stride)
std::pair<float, std::string> compute_plot_unit(float max_value)
{
if (max_value > 1e9)
return { 1e-9, "G" };
return {1e-9, "G"};
if (max_value > 1e6)
return { 1e-6, "M" };
return {1e-6, "M"};
if (max_value > 1e3)
return { 1e-3, "k" };
return {1e-3, "k"};
if (max_value > 1)
return { 1, "" };
return {1, ""};
if (max_value > 1e-3)
return { 1e3, "m" };
return {1e3, "m"};
if (max_value > 1e-6)
return { 1e6, "u" };
return { 1e9, "n" };
return {1e6, "u"};
return {1e9, "n"};
}
struct getter_data
@@ -72,15 +72,15 @@ struct getter_data
ImPlotPoint getter(int index, void * data_)
{
getter_data& data = *(getter_data*)data_;
getter_data & data = *(getter_data *)data_;
int offset_index = (index + data.offset) % data.count;
return ImPlotPoint(index, *(float*)(data.data + offset_index * data.stride) * data.multiplier);
}
return ImPlotPoint(index, *(float *)(data.data + offset_index * data.stride) * data.multiplier);
}
} // namespace
void scenes::stream::accumulate_metrics(XrTime predicted_display_time, const std::vector<std::shared_ptr<shard_accumulator::blit_handle>>& blit_handles, const gpu_timestamps& timestamps)
void scenes::stream::accumulate_metrics(XrTime predicted_display_time, const std::vector<std::shared_ptr<shard_accumulator::blit_handle>> & blit_handles, const gpu_timestamps & timestamps)
{
uint64_t rx = network_session->bytes_received();
uint64_t tx = network_session->bytes_sent();
@@ -88,13 +88,13 @@ void scenes::stream::accumulate_metrics(XrTime predicted_display_time, const std
float dt = (predicted_display_time - last_metric_time) * 1e-9f;
bandwidth_rx = 0.8 * bandwidth_rx + 0.2 * float(rx - bytes_received) / dt;
bandwidth_tx = 0.8 * bandwidth_tx + 0.2 * float(tx - bytes_sent ) /dt;
bandwidth_tx = 0.8 * bandwidth_tx + 0.2 * float(tx - bytes_sent) / dt;
last_metric_time = predicted_display_time;
bytes_received = rx;
bytes_sent = tx;
*(gpu_timestamps*)&global_metrics[metrics_offset] = timestamps;
*(gpu_timestamps *)&global_metrics[metrics_offset] = timestamps;
global_metrics[metrics_offset].cpu_time = application::get_cpu_time().count() * 1e-9f;
global_metrics[metrics_offset].bandwidth_rx = bandwidth_rx * 8;
global_metrics[metrics_offset].bandwidth_tx = bandwidth_tx * 8;
@@ -103,15 +103,16 @@ void scenes::stream::accumulate_metrics(XrTime predicted_display_time, const std
decoder_metrics.resize(blit_handles.size());
auto min_encode_begin = std::numeric_limits<decltype(blit_handles[0]->timing_info.encode_begin)>::max();
for(const auto& bh: blit_handles)
for (const auto & bh: blit_handles)
min_encode_begin = std::min(min_encode_begin, bh->timing_info.encode_begin);
for(auto&& [metrics, bh]: utils::zip(decoder_metrics, blit_handles))
for (auto && [metrics, bh]: utils::zip(decoder_metrics, blit_handles))
{
if (metrics.size() != global_metrics.size())
metrics.resize(global_metrics.size());
metrics[metrics_offset] = decoder_metric{
// clang-format off
.send_begin = (bh->timing_info.send_begin - min_encode_begin) * 1e-9f,
.send_end = (bh->timing_info.send_end - min_encode_begin) * 1e-9f,
.received_first_packet = (bh->feedback.received_first_packet - min_encode_begin) * 1e-9f,
@@ -120,6 +121,7 @@ void scenes::stream::accumulate_metrics(XrTime predicted_display_time, const std
.received_from_decoder = (bh->feedback.received_from_decoder - min_encode_begin) * 1e-9f,
.blitted = (bh->feedback.blitted - min_encode_begin) * 1e-9f,
.displayed = (bh->feedback.displayed - min_encode_begin) * 1e-9f,
// clang-format on
};
}
@@ -133,28 +135,20 @@ XrCompositionLayerQuad scenes::stream::plot_performance_metrics(XrTime predicted
ImGui::SetNextWindowPos({0, 0});
ImGui::SetNextWindowSize(ImGui::GetMainViewport()->Size);
ImGui::Begin("Performance metrics", nullptr,
ImGuiWindowFlags_NoTitleBar |
ImGuiWindowFlags_NoResize |
ImGuiWindowFlags_NoMove);
ImGui::Begin("Performance metrics", nullptr, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove);
ImVec2 window_size = ImGui::GetWindowSize() - ImVec2(2,2) * style.WindowPadding;
ImVec2 window_size = ImGui::GetWindowSize() - ImVec2(2, 2) * style.WindowPadding;
static const std::array plots = {
plot("CPU time", {
{"", &global_metric::cpu_time},
},
"s"),
plot("GPU time", {
{"Reproject", &global_metric::gpu_time},
{"Blit", &global_metric::gpu_barrier},
},
"s"),
plot("Network", {
{"Download", &global_metric::bandwidth_rx},
{"Upload", &global_metric::bandwidth_tx},
},
"bit/s"),
// clang-format off
plot("CPU time", {{"", &global_metric::cpu_time}}, "s"),
plot("GPU time", {{"Reproject", &global_metric::gpu_time},
{"Blit", &global_metric::gpu_barrier}}, "s"),
plot("Network", {{"Download", &global_metric::bandwidth_rx},
{"Upload", &global_metric::bandwidth_tx}}, "bit/s"),
// clang-format on
};
int n_plots = plots.size() + decoders.size();
@@ -164,8 +158,8 @@ XrCompositionLayerQuad scenes::stream::plot_performance_metrics(XrTime predicted
int n_rows = ceil((float)n_plots / n_cols);
ImVec2 plot_size = ImVec2(
window_size.x / n_cols - style.ItemSpacing.x * (n_cols-1) / n_cols,
window_size.y / n_rows - style.ItemSpacing.y * (n_rows-1) / n_rows);
window_size.x / n_cols - style.ItemSpacing.x * (n_cols - 1) / n_cols,
window_size.y / n_rows - style.ItemSpacing.y * (n_rows - 1) / n_rows);
ImPlot::PushStyleColor(ImPlotCol_PlotBg, IM_COL32(32, 32, 32, 64));
ImPlot::PushStyleColor(ImPlotCol_FrameBg, IM_COL32(0, 0, 0, 0));
@@ -174,17 +168,17 @@ XrCompositionLayerQuad scenes::stream::plot_performance_metrics(XrTime predicted
ImPlot::PushStyleColor(ImPlotCol_AxisBgHovered, IM_COL32(0, 0, 0, 0));
int n = 0;
for(const auto& [title, subplots, unit]: plots)
for (const auto & [title, subplots, unit]: plots)
{
if (ImPlot::BeginPlot(title, plot_size, ImPlotFlags_NoTitle | ImPlotFlags_NoMenus | ImPlotFlags_NoBoxSelect | ImPlotFlags_NoMouseText | ImPlotFlags_NoChild))
{
float min_v = 0;
float max_v = 0;
for (const auto& [subtitle, data]: subplots)
for (const auto & [subtitle, data]: subplots)
{
max_v = std::max(max_v, compute_plot_max_value(&(global_metrics.data()->*data), global_metrics.size(), sizeof(global_metric)));
}
auto [ multiplier, prefix ] = compute_plot_unit(max_v);
auto [multiplier, prefix] = compute_plot_unit(max_v);
if (axis_scale[n] == 0 || std::isnan(axis_scale[n]))
axis_scale[n] = max_v;
@@ -199,7 +193,7 @@ XrCompositionLayerQuad scenes::stream::plot_performance_metrics(XrTime predicted
ImPlot::SetNextLineStyle(color);
ImPlot::SetNextFillStyle(color, 0.25);
for (const auto& [subtitle, data]: subplots)
for (const auto & [subtitle, data]: subplots)
{
getter_data gdata{
.data = (uintptr_t) & (global_metrics.data()->*data),
@@ -217,7 +211,7 @@ XrCompositionLayerQuad scenes::stream::plot_performance_metrics(XrTime predicted
ImGui::SameLine();
}
for(auto&& [index, metrics]: utils::enumerate(decoder_metrics))
for (auto && [index, metrics]: utils::enumerate(decoder_metrics))
{
std::string title = "Decoder " + std::to_string(index);
if (ImPlot::BeginPlot(title.c_str(), plot_size, ImPlotFlags_NoTitle | ImPlotFlags_NoMenus | ImPlotFlags_NoBoxSelect | ImPlotFlags_NoMouseText | ImPlotFlags_NoChild))
@@ -235,83 +229,75 @@ XrCompositionLayerQuad scenes::stream::plot_performance_metrics(XrTime predicted
ImPlot::SetupAxes(nullptr, title_with_units, ImPlotAxisFlags_NoDecorations, 0);
ImPlot::SetupAxesLimits(0, metrics.size() - 1, min_v * 1e3f, axis_scale[n] * 1e3f, ImGuiCond_Always);
getter_data getter_send_begin{
.data = (uintptr_t)&(metrics.data()->send_begin),
.stride = sizeof(decoder_metric),
.offset = metrics_offset,
.count = (int)metrics.size(),
.multiplier = 1e3f
};
.data = (uintptr_t) & (metrics.data()->send_begin),
.stride = sizeof(decoder_metric),
.offset = metrics_offset,
.count = (int)metrics.size(),
.multiplier = 1e3f};
getter_data getter_send_end{
.data = (uintptr_t)&(metrics.data()->send_end),
.stride = sizeof(decoder_metric),
.offset = metrics_offset,
.count = (int)metrics.size(),
.multiplier = 1e3f
};
.data = (uintptr_t) & (metrics.data()->send_end),
.stride = sizeof(decoder_metric),
.offset = metrics_offset,
.count = (int)metrics.size(),
.multiplier = 1e3f};
getter_data getter_received_first_packet{
.data = (uintptr_t)&(metrics.data()->received_first_packet),
.stride = sizeof(decoder_metric),
.offset = metrics_offset,
.count = (int)metrics.size(),
.multiplier = 1e3f
};
.data = (uintptr_t) & (metrics.data()->received_first_packet),
.stride = sizeof(decoder_metric),
.offset = metrics_offset,
.count = (int)metrics.size(),
.multiplier = 1e3f};
getter_data getter_received_last_packet{
.data = (uintptr_t)&(metrics.data()->received_last_packet),
.stride = sizeof(decoder_metric),
.offset = metrics_offset,
.count = (int)metrics.size(),
.multiplier = 1e3f
};
.data = (uintptr_t) & (metrics.data()->received_last_packet),
.stride = sizeof(decoder_metric),
.offset = metrics_offset,
.count = (int)metrics.size(),
.multiplier = 1e3f};
getter_data getter_sent_to_decoder{
.data = (uintptr_t)&(metrics.data()->sent_to_decoder),
.stride = sizeof(decoder_metric),
.offset = metrics_offset,
.count = (int)metrics.size(),
.multiplier = 1e3f
};
.data = (uintptr_t) & (metrics.data()->sent_to_decoder),
.stride = sizeof(decoder_metric),
.offset = metrics_offset,
.count = (int)metrics.size(),
.multiplier = 1e3f};
getter_data getter_received_from_decoder{
.data = (uintptr_t)&(metrics.data()->received_from_decoder),
.stride = sizeof(decoder_metric),
.offset = metrics_offset,
.count = (int)metrics.size(),
.multiplier = 1e3f
};
.data = (uintptr_t) & (metrics.data()->received_from_decoder),
.stride = sizeof(decoder_metric),
.offset = metrics_offset,
.count = (int)metrics.size(),
.multiplier = 1e3f};
getter_data getter_blitted{
.data = (uintptr_t)&(metrics.data()->blitted),
.stride = sizeof(decoder_metric),
.offset = metrics_offset,
.count = (int)metrics.size(),
.multiplier = 1e3f
};
.data = (uintptr_t) & (metrics.data()->blitted),
.stride = sizeof(decoder_metric),
.offset = metrics_offset,
.count = (int)metrics.size(),
.multiplier = 1e3f};
getter_data getter_displayed{
.data = (uintptr_t)&(metrics.data()->displayed),
.stride = sizeof(decoder_metric),
.offset = metrics_offset,
.count = (int)metrics.size(),
.multiplier = 1e3f
};
.data = (uintptr_t) & (metrics.data()->displayed),
.stride = sizeof(decoder_metric),
.offset = metrics_offset,
.count = (int)metrics.size(),
.multiplier = 1e3f};
// clang-format off
ImPlot::PlotShadedG("Send", getter, &getter_send_begin, getter, &getter_send_end, metrics.size());
ImPlot::PlotShadedG("Receive", getter, &getter_received_first_packet, getter, &getter_received_last_packet, metrics.size());
ImPlot::PlotShadedG("Decode", getter, &getter_sent_to_decoder, getter, &getter_received_from_decoder, metrics.size());
ImPlot::PlotLineG("Blitted", getter, &getter_blitted, metrics.size());
ImPlot::PlotLineG("Displayed", getter, &getter_displayed, metrics.size());
// clang-format on
ImPlot::EndPlot();
}
if (++n % n_cols != 0)
ImGui::SameLine();
}
ImPlot::PopStyleColor(5);