Introduce presentation metrics and send them to comet

This commit is contained in:
Héctor Ramón Jiménez 2025-04-09 21:50:21 +02:00
parent 6508ad67c1
commit 015f5283a8
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
8 changed files with 210 additions and 42 deletions

View file

@ -94,6 +94,7 @@ pub fn run() -> impl Stream<Item = Event> {
let mut last_message = String::new();
let mut last_commands_spawned = 0;
let mut last_present_window = None;
loop {
match receive(&mut stream, &mut buffer).await {
@ -146,6 +147,11 @@ pub fn run() -> impl Stream<Item = Event> {
last_message.clear();
last_commands_spawned = 0;
}
client::Event::SpanStarted(
span::Stage::Present(window),
) => {
last_present_window = Some(window);
}
client::Event::SpanStarted(_) => {}
client::Event::SpanFinished(
stage,
@ -173,6 +179,30 @@ pub fn run() -> impl Stream<Item = Event> {
span::Stage::Draw(window) => {
Span::Draw { window }
}
span::Stage::Prepare(primitive) => {
let Some(window) =
last_present_window
else {
continue;
};
Span::Prepare {
window,
primitive,
}
}
span::Stage::Render(primitive) => {
let Some(window) =
last_present_window
else {
continue;
};
Span::Render {
window,
primitive,
}
}
span::Stage::Present(window) => {
Span::Present { window }
}

View file

@ -21,6 +21,14 @@ pub enum Span {
Draw {
window: window::Id,
},
Prepare {
window: window::Id,
primitive: Primitive,
},
Render {
window: window::Id,
primitive: Primitive,
},
Present {
window: window::Id,
},
@ -30,6 +38,26 @@ pub enum Span {
},
}
#[derive(
Debug,
Clone,
Copy,
PartialEq,
Eq,
PartialOrd,
Ord,
Hash,
Serialize,
Deserialize,
)]
pub enum Primitive {
Quad,
Triangle,
Shader,
Text,
Image,
}
impl Span {
pub fn stage(&self) -> Stage {
match self {
@ -39,6 +67,8 @@ impl Span {
Span::Layout { window } => Stage::Layout(*window),
Span::Interact { window } => Stage::Interact(*window),
Span::Draw { window } => Stage::Draw(*window),
Span::Prepare { primitive, .. } => Stage::Prepare(*primitive),
Span::Render { primitive, .. } => Stage::Render(*primitive),
Span::Present { window } => Stage::Present(*window),
Span::Custom { window, name } => {
Stage::Custom(*window, name.clone())
@ -58,6 +88,8 @@ pub enum Stage {
Interact(window::Id),
Draw(window::Id),
Present(window::Id),
Prepare(Primitive),
Render(Primitive),
Custom(window::Id, String),
}
@ -70,6 +102,8 @@ impl std::fmt::Display for Stage {
Stage::Layout(_) => "Layout",
Stage::Interact(_) => "Interact",
Stage::Draw(_) => "Draw",
Stage::Prepare(_) => "Prepare",
Stage::Render(_) => "Render",
Stage::Present(_) => "Present",
Stage::Custom(_, name) => name,
})