修复若干问题

This commit is contained in:
2026-08-15 03:21:01 +08:00
parent 04a9156cd6
commit 6655e8571b
54 changed files with 1525 additions and 397 deletions
+40 -2
View File
@@ -13,6 +13,7 @@
#include <cmath>
#include <cstddef>
#include <cstdint>
#include <deque>
#include <memory>
#include <optional>
#include <stdexcept>
@@ -219,6 +220,9 @@ public:
successful_render_count_ = 0;
pixel_frame_count_ = 0;
last_render_ms_ = 0.0;
last_pixel_encode_ms_ = 0.0;
render_history_.clear();
pixel_history_.clear();
last_event_ = "monitoring_reset";
}
@@ -325,6 +329,7 @@ public:
last_pixel_encode_ms_ = std::chrono::duration<double, std::milli>(
encode_finished - encode_started)
.count();
record_sample(pixel_history_, encode_finished);
}
[[nodiscard]] std::string action(const Gallery_Action_Request& request,
@@ -433,19 +438,21 @@ public:
[[nodiscard]] std::string telemetry_json() const override {
const auto status = scene_.frame_status();
const auto now = std::chrono::steady_clock::now();
return nlohmann::json{
{"kernel_observer",
{{"mode", mode_id(frame_mode_)},
{"last_event", last_event_},
{"pending_frame_count", status.pending_frame_count},
{"dropped_frame_count", status.dropped_frame_count}}},
{"render_performance",
{"performance",
{{"render_attempt_count", render_attempt_count_},
{"successful_render_count", successful_render_count_},
{"failed_render_count",
render_attempt_count_ - successful_render_count_},
{"measured_fps", recent_rate(render_history_, now)},
{"last_render_ms", last_render_ms_},
{"pixel_response_fps", 0.0},
{"pixel_response_fps", recent_rate(pixel_history_, now)},
{"last_pixel_encode_ms", last_pixel_encode_ms_},
{"last_pixel_bytes", last_pixel_bytes_},
{"automatic_low_latency_scheduler", can_render_automatically()}}},
@@ -462,6 +469,31 @@ public:
}
private:
using Performance_Clock = std::chrono::steady_clock;
static void record_sample(std::deque<Performance_Clock::time_point>& samples,
Performance_Clock::time_point now) {
samples.push_back(now);
const auto cutoff = now - std::chrono::seconds(2);
while (!samples.empty() && samples.front() < cutoff)
samples.pop_front();
}
static double recent_rate(
const std::deque<Performance_Clock::time_point>& samples,
Performance_Clock::time_point now) {
const auto cutoff = now - std::chrono::seconds(1);
const auto first = std::find_if(samples.begin(), samples.end(),
[cutoff](auto sample) {
return sample >= cutoff;
});
const auto count = std::distance(first, samples.end());
if (count < 2)
return 0.0;
const double seconds = std::chrono::duration<double>(samples.back() - *first).count();
return seconds > 0.0 ? static_cast<double>(count - 1) / seconds : 0.0;
}
static std::vector<Point> initial_points() {
return {{{-0.62F, -0.10F, 0.0F}, {255, 32, 24, 255}, 74.0F},
{{0.0F, -0.10F, 0.0F}, {24, 255, 36, 255}, 74.0F},
@@ -513,6 +545,8 @@ private:
std::chrono::steady_clock::now() - started)
.count();
successful_render_count_ += rendered ? 1U : 0U;
if (rendered)
record_sample(render_history_, std::chrono::steady_clock::now());
return rendered;
}
@@ -524,6 +558,8 @@ private:
std::chrono::steady_clock::now() - started)
.count();
successful_render_count_ += rendered ? 1U : 0U;
if (rendered)
record_sample(render_history_, std::chrono::steady_clock::now());
return rendered;
}
@@ -546,6 +582,8 @@ private:
double last_render_ms_{};
double last_pixel_encode_ms_{};
std::size_t last_pixel_bytes_{};
std::deque<Performance_Clock::time_point> render_history_;
std::deque<Performance_Clock::time_point> pixel_history_;
std::string last_event_{"initialized"};
std::string last_action_result_;
};