pub struct RenderStats {
pub frame_id: u64,
pub backend: BackendKind,
pub presented: bool,
pub stages: StageTimes,
pub counters: FrameCounters,
pub frame_unavailable: &'static [(StageId, &'static str)],
}Expand description
一帧的完整统计。
Fields§
§frame_id: u64帧序号(调用方自增)。
backend: BackendKind后端种类。
presented: bool本帧是否真正上屏。
stages: StageTimes各阶段测量值。
counters: FrameCounters计数器。
本帧额外不可用的阶段(后端声明之外的临时原因,例如查询失败)。
Implementations§
Source§impl RenderStats
impl RenderStats
Sourcepub fn new(frame_id: u64, backend: BackendKind) -> Self
pub fn new(frame_id: u64, backend: BackendKind) -> Self
新建一帧统计(全部阶段为空,等待打点)。
Sourcepub fn stage(&self, id: StageId) -> Stage
pub fn stage(&self, id: StageId) -> Stage
解析某阶段的三态结果。
优先级:本帧测量值 > 后端能力表 > 本帧临时不可用。
可测量但本帧没打点 → Unavailable("本帧未经过该阶段"),不是 NotApplicable。
Sourcepub fn validate(&self) -> Result<(), StatsError>
pub fn validate(&self) -> Result<(), StatsError>
自检:拒绝自相矛盾的数据(见 StatsError)。
这是“不许把测不到写成 0“的守卫:任何被后端声明为不可测量的阶段,
一旦被填了 Some(_)(哪怕 Duration::ZERO),这里都会报错。
Sourcepub fn reset_for_next_frame(&mut self, frame_id: u64)
pub fn reset_for_next_frame(&mut self, frame_id: u64)
重置为下一帧(保留 frame_id/backend,清空阶段与计数器)。
为什么复用而不是每帧新建:开启统计时也应零堆分配。
Sourcepub fn write_json(&self, out: &mut String)
pub fn write_json(&self, out: &mut String)
追加一行 JSON(不分配:写进调用方的 String)。
口径:unavailable 只输出原因字符串,not_applicable 输出 null
且带独立键 —— 三者在前端可区分,不会被误读成 0。
Source§impl RenderStats
impl RenderStats
Sourcepub fn is_backend_stage(id: StageId) -> bool
pub fn is_backend_stage(id: StageId) -> bool
某阶段是否由后端负责。
Sourcepub fn merge_backend(&mut self, src: Option<RenderStats>) -> bool
pub fn merge_backend(&mut self, src: Option<RenderStats>) -> bool
合并后端上报的统计:只取后端负责的阶段,并做自检。
字段所有权(B1 裁决):
stages:仅BACKEND_STAGES里的 12 项由后端提供,Runtime 自己的阶段 (event_dispatch/layout/after_frame/after_present/total_frame)不会被覆盖;counters:由后端提供(脏区数、实例数、图集字节等只有后端知道);presented:由 Runtime 独占,本函数不复制(见下方注释);frame_unavailable:由后端提供(该帧临时不可测的原因)。
返回:true = 后端确实提供了数据;false = 未接入(所有后端阶段保持 None,
绝不伪造)。
自检失败(例如后端把 gpu_execute 填成 Measured)时不采纳该帧的后端数据,
并打一条日志 —— 宁可少数据,也不要自相矛盾的数据。
Sourcepub fn backend_stage_sum(&self) -> Duration
pub fn backend_stage_sum(&self) -> Duration
后端上报的阶段耗时之和(用于“不得超过 window.render 墙钟“的验收)。
Trait Implementations§
Source§impl Clone for RenderStats
impl Clone for RenderStats
impl Copy for RenderStats
Auto Trait Implementations§
impl Forget for RenderStats
impl Freeze for RenderStats
impl Move for RenderStats
impl RefUnwindSafe for RenderStats
impl Send for RenderStats
impl Sync for RenderStats
impl Unpin for RenderStats
impl UnsafeUnpin for RenderStats
impl UnwindSafe for RenderStats
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more