Add some tracing spans

This commit is contained in:
Imbris 2020-10-31 16:53:25 -04:00
parent d2166fed3d
commit 9df8368c88
2 changed files with 13 additions and 1 deletions

View File

@ -15,6 +15,7 @@ use super::{
scale::{Scale, ScaleMode},
};
use crate::{render::Renderer, window::Window, Error};
use common::span;
use iced::{mouse, Cache, Size, UserInterface};
use iced_winit::Clipboard;
use vek::*;
@ -127,6 +128,7 @@ impl IcedUi {
root: E,
renderer: &mut Renderer,
) -> (Vec<M>, mouse::Interaction) {
span!(_guard, "maintain", "IcedUi::maintain");
// Handle window resizing and scale mode changing
let scaled_dims = if let Some(new_dims) = self.window_resized.take() {
let old_scaled_dims = self.scale.scaled_window_size();
@ -167,24 +169,30 @@ impl IcedUi {
// TODO: convert to f32 at source
let window_size = self.scale.scaled_window_size().map(|e| e as f32);
span!(guard, "build user_interface");
let mut user_interface = UserInterface::build(
root,
Size::new(window_size.x, window_size.y),
self.cache.take().unwrap(),
&mut self.renderer,
);
drop(guard);
span!(guard, "update user_interface");
let messages = user_interface.update(
&self.events,
cursor_position,
Some(&self.clipboard),
&mut self.renderer,
);
drop(guard);
// Clear events
self.events.clear();
span!(guard, "draw user_interface");
let (primitive, mouse_interaction) =
user_interface.draw(&mut self.renderer, cursor_position);
drop(guard);
self.cache = Some(user_interface.into_cache());

View File

@ -20,7 +20,7 @@ use crate::{
},
Error,
};
use common::util::srgba_to_linear;
use common::{span, util::srgba_to_linear};
use std::{convert::TryInto, ops::Range};
use vek::*;
@ -171,6 +171,7 @@ impl IcedRenderer {
}
pub fn draw(&mut self, primitive: Primitive, renderer: &mut Renderer) {
span!(_guard, "draw", "IcedRenderer::draw");
// Re-use memory
self.draw_commands.clear();
self.mesh.clear();
@ -739,6 +740,7 @@ impl IcedRenderer {
}
pub fn render(&self, renderer: &mut Renderer, maybe_globals: Option<&Consts<Globals>>) {
span!(_guard, "render", "IcedRenderer::render");
let mut scissor = default_scissor(renderer);
let globals = maybe_globals.unwrap_or(&self.default_globals);
let mut locals = &self.interface_locals;
@ -796,6 +798,7 @@ impl iced::Renderer for IcedRenderer {
element: &iced::Element<'a, M, Self>,
limits: &iced::layout::Limits,
) -> iced::layout::Node {
span!(_guard, "layout", "IcedRenderer::layout");
let node = element.layout(self, limits);
// Trim text measurements cache?
@ -809,6 +812,7 @@ impl iced::Renderer for IcedRenderer {
(overlay_primitive, overlay_interaction): Self::Output,
overlay_bounds: iced::Rectangle,
) -> Self::Output {
span!(_guard, "overlay", "IcedRenderer::overlay");
(
Primitive::Group {
primitives: vec![base_primitive, Primitive::Clip {