Skip to main content

RenderStats

Struct RenderStats 

Source
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

计数器。

§frame_unavailable: &'static [(StageId, &'static str)]

本帧额外不可用的阶段(后端声明之外的临时原因,例如查询失败)。

Implementations§

Source§

impl RenderStats

Source

pub fn new(frame_id: u64, backend: BackendKind) -> Self

新建一帧统计(全部阶段为空,等待打点)。

Source

pub fn stage(&self, id: StageId) -> Stage

解析某阶段的三态结果。

优先级:本帧测量值 > 后端能力表 > 本帧临时不可用。 可测量但本帧没打点 → Unavailable("本帧未经过该阶段"),不是 NotApplicable。

Source

pub fn validate(&self) -> Result<(), StatsError>

自检:拒绝自相矛盾的数据(见 StatsError)。

这是“不许把测不到写成 0“的守卫:任何被后端声明为不可测量的阶段, 一旦被填了 Some(_)(哪怕 Duration::ZERO),这里都会报错。

Source

pub fn reset_for_next_frame(&mut self, frame_id: u64)

重置为下一帧(保留 frame_id/backend,清空阶段与计数器)。

为什么复用而不是每帧新建:开启统计时也应零堆分配。

Source

pub fn write_json(&self, out: &mut String)

追加一行 JSON(不分配:写进调用方的 String)。

口径:unavailable 只输出原因字符串,not_applicable 输出 null 且带独立键 —— 三者在前端可区分,不会被误读成 0。

Source§

impl RenderStats

Source

pub fn is_backend_stage(id: StageId) -> bool

某阶段是否由后端负责。

Source

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)时不采纳该帧的后端数据, 并打一条日志 —— 宁可少数据,也不要自相矛盾的数据。

Source

pub fn backend_stage_sum(&self) -> Duration

后端上报的阶段耗时之和(用于“不得超过 window.render 墙钟“的验收)。

Trait Implementations§

Source§

impl Clone for RenderStats

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for RenderStats

Source§

impl Debug for RenderStats

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Forget for RenderStats

§

impl Freeze for RenderStats
where &'static [(StageId, &'static str)]: Freeze,

§

impl Move for RenderStats

§

impl RefUnwindSafe for RenderStats

§

impl Send for RenderStats
where &'static [(StageId, &'static str)]: Send,

§

impl Sync for RenderStats

§

impl Unpin for RenderStats
where &'static [(StageId, &'static str)]: Unpin,

§

impl UnsafeUnpin for RenderStats
where &'static [(StageId, &'static str)]: UnsafeUnpin,

§

impl UnwindSafe for RenderStats
where &'static [(StageId, &'static str)]: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.