Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Profiling #1565

Merged
merged 3 commits into from
Jan 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ pkg/
Cargo.lock
.cargo/
dist/
traces/
7 changes: 7 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ smol = ["iced_futures/smol"]
palette = ["iced_core/palette"]
# Enables querying system information
system = ["iced_winit/system"]
# Enables chrome traces
chrome-trace = [
"iced_winit/chrome-trace",
"iced_glutin?/trace",
"iced_wgpu?/tracing",
"iced_glow?/tracing",
]

[badges]
maintenance = { status = "actively-developed" }
Expand Down
4 changes: 4 additions & 0 deletions glow/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ version = "0.5"
path = "../graphics"
features = ["font-fallback", "font-icons", "opengl"]

[dependencies.tracing]
version = "0.1.6"
optional = true

[package.metadata.docs.rs]
rustdoc-args = ["--cfg", "docsrs"]
all-features = true
6 changes: 6 additions & 0 deletions glow/src/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ use glow::HasContext;

use std::cell::RefCell;

#[cfg(feature = "tracing")]
use tracing::info_span;

#[derive(Debug)]
pub(crate) struct Pipeline {
program: <glow::Context as HasContext>::Program,
Expand Down Expand Up @@ -148,6 +151,9 @@ impl Pipeline {
images: &[layer::Image],
layer_bounds: Rectangle<u32>,
) {
#[cfg(feature = "tracing")]
let _ = info_span!("Glow::Image", "DRAW").entered();

unsafe {
gl.use_program(Some(self.program));
gl.bind_vertex_array(Some(self.vertex_array));
Expand Down
6 changes: 6 additions & 0 deletions glow/src/quad.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ use glow::HasContext;
use iced_graphics::layer;
use iced_native::Rectangle;

#[cfg(feature = "tracing")]
use tracing::info_span;

#[derive(Debug)]
pub enum Pipeline {
Core(core::Pipeline),
Expand Down Expand Up @@ -42,6 +45,9 @@ impl Pipeline {
scale: f32,
bounds: Rectangle<u32>,
) {
#[cfg(feature = "tracing")]
let _ = info_span!("Glow::Quad", "DRAW").enter();

match self {
Pipeline::Core(pipeline) => {
pipeline.draw(
Expand Down
6 changes: 6 additions & 0 deletions glow/src/triangle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ use iced_graphics::triangle::{ColoredVertex2D, Vertex2D};
use glow::HasContext;
use std::marker::PhantomData;

#[cfg(feature = "tracing")]
use tracing::info_span;

const DEFAULT_VERTICES: usize = 1_000;
const DEFAULT_INDICES: usize = 1_000;

Expand Down Expand Up @@ -58,6 +61,9 @@ impl Pipeline {
transformation: Transformation,
scale_factor: f32,
) {
#[cfg(feature = "tracing")]
let _ = info_span!("Glow::Triangle", "DRAW").enter();

unsafe {
gl.enable(glow::MULTISAMPLE);
gl.enable(glow::SCISSOR_TEST);
Expand Down
5 changes: 5 additions & 0 deletions glutin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ keywords = ["gui", "ui", "graphics", "interface", "widgets"]
categories = ["gui"]

[features]
trace = ["iced_winit/trace"]
debug = ["iced_winit/debug"]
system = ["iced_winit/system"]

Expand All @@ -35,3 +36,7 @@ features = ["application"]
version = "0.5"
path = "../graphics"
features = ["opengl"]

[dependencies.tracing]
version = "0.1.6"
optional = true
44 changes: 32 additions & 12 deletions glutin/src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ use iced_winit::{Clipboard, Command, Debug, Proxy, Settings};
use glutin::window::Window;
use std::mem::ManuallyDrop;

#[cfg(feature = "tracing")]
use tracing::{info_span, instrument::Instrument};

/// Runs an [`Application`] with an executor, compositor, and the provided
/// settings.
pub fn run<A, E, C>(
Expand All @@ -35,9 +38,15 @@ where
use glutin::platform::run_return::EventLoopExtRunReturn;
use glutin::ContextBuilder;

#[cfg(feature = "trace")]
let _guard = iced_winit::Profiler::init();

let mut debug = Debug::new();
debug.startup_started();

#[cfg(feature = "tracing")]
let _ = info_span!("Application::Glutin", "RUN").entered();

let mut event_loop = EventLoopBuilder::with_user_event().build();
let proxy = event_loop.create_proxy();

Expand Down Expand Up @@ -124,18 +133,26 @@ where

let (mut sender, receiver) = mpsc::unbounded();

let mut instance = Box::pin(run_instance::<A, E, C>(
application,
compositor,
renderer,
runtime,
proxy,
debug,
receiver,
context,
init_command,
settings.exit_on_close_request,
));
let mut instance = Box::pin({
let run_instance = run_instance::<A, E, C>(
application,
compositor,
renderer,
runtime,
proxy,
debug,
receiver,
context,
init_command,
settings.exit_on_close_request,
);

#[cfg(feature = "tracing")]
let run_instance =
run_instance.instrument(info_span!("Application", "LOOP"));

run_instance
});

let mut context = task::Context::from_waker(task::noop_waker_ref());

Expand Down Expand Up @@ -333,6 +350,9 @@ async fn run_instance<A, E, C>(
messages.push(message);
}
event::Event::RedrawRequested(_) => {
#[cfg(feature = "tracing")]
let _ = info_span!("Application", "FRAME").entered();

debug.render_started();

#[allow(unsafe_code)]
Expand Down
4 changes: 4 additions & 0 deletions wgpu/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ version = "0.5"
path = "../graphics"
features = ["font-fallback", "font-icons"]

[dependencies.tracing]
version = "0.1.6"
optional = true

[dependencies.encase]
version = "0.3.0"
features = ["glam"]
Expand Down
5 changes: 5 additions & 0 deletions wgpu/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ use iced_graphics::{Primitive, Viewport};
use iced_native::alignment;
use iced_native::{Font, Size};

#[cfg(feature = "tracing")]
use tracing::info_span;

#[cfg(any(feature = "image", feature = "svg"))]
use crate::image;

Expand Down Expand Up @@ -77,6 +80,8 @@ impl Backend {
overlay_text: &[T],
) {
log::debug!("Drawing");
#[cfg(feature = "tracing")]
let _ = info_span!("Wgpu::Backend", "PRESENT").entered();

let target_size = viewport.physical_size();
let scale_factor = viewport.scale_factor() as f32;
Expand Down
6 changes: 6 additions & 0 deletions wgpu/src/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ use iced_native::image;
#[cfg(feature = "svg")]
use iced_native::svg;

#[cfg(feature = "tracing")]
use tracing::info_span;

#[derive(Debug)]
pub struct Pipeline {
#[cfg(feature = "image")]
Expand Down Expand Up @@ -289,6 +292,9 @@ impl Pipeline {
target: &wgpu::TextureView,
_scale: f32,
) {
#[cfg(feature = "tracing")]
let _ = info_span!("Wgpu::Image", "DRAW").entered();

let instances: &mut Vec<Instance> = &mut Vec::new();

#[cfg(feature = "image")]
Expand Down
9 changes: 9 additions & 0 deletions wgpu/src/quad.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ use bytemuck::{Pod, Zeroable};
use std::mem;
use wgpu::util::DeviceExt;

#[cfg(feature = "tracing")]
use tracing::info_span;

#[derive(Debug)]
pub struct Pipeline {
pipeline: wgpu::RenderPipeline,
Expand Down Expand Up @@ -173,6 +176,9 @@ impl Pipeline {
bounds: Rectangle<u32>,
target: &wgpu::TextureView,
) {
#[cfg(feature = "tracing")]
let _ = info_span!("Wgpu::Quad", "DRAW").entered();

let uniforms = Uniforms::new(transformation, scale);

{
Expand Down Expand Up @@ -207,6 +213,9 @@ impl Pipeline {

instance_buffer.copy_from_slice(instance_bytes);

#[cfg(feature = "tracing")]
let _ = info_span!("Wgpu::Quad", "BEGIN_RENDER_PASS").enter();

{
let mut render_pass =
encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
Expand Down
8 changes: 8 additions & 0 deletions wgpu/src/triangle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ use crate::Transformation;
use iced_graphics::layer::mesh::{self, Mesh};
use iced_graphics::triangle::ColoredVertex2D;
use iced_graphics::Size;
#[cfg(feature = "tracing")]
use tracing::info_span;

#[derive(Debug)]
pub struct Pipeline {
Expand Down Expand Up @@ -53,6 +55,9 @@ impl Pipeline {
scale_factor: f32,
meshes: &[Mesh<'_>],
) {
#[cfg(feature = "tracing")]
let _ = info_span!("Wgpu::Triangle", "DRAW").entered();

// Count the total amount of vertices & indices we need to handle
let count = mesh::attribute_count_of(meshes);

Expand Down Expand Up @@ -247,6 +252,9 @@ impl Pipeline {
(target, None, wgpu::LoadOp::Load)
};

#[cfg(feature = "tracing")]
let _ = info_span!("Wgpu::Triangle", "BEGIN_RENDER_PASS").enter();

let mut render_pass =
encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
label: Some("iced_wgpu::triangle render pass"),
Expand Down
20 changes: 20 additions & 0 deletions winit/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ keywords = ["gui", "ui", "graphics", "interface", "widgets"]
categories = ["gui"]

[features]
trace = ["tracing", "tracing-core", "tracing-subscriber"]
chrome-trace = ["trace", "tracing-chrome"]
debug = ["iced_native/debug"]
system = ["sysinfo"]
application = []
Expand All @@ -37,6 +39,24 @@ path = "../graphics"
version = "0.5"
path = "../futures"

[dependencies.tracing]
version = "0.1.37"
optional = true
features = ["std"]

[dependencies.tracing-core]
version = "0.1.30"
optional = true

[dependencies.tracing-subscriber]
version = "0.3.16"
optional = true
features = ["registry"]

[dependencies.tracing-chrome]
version = "0.7.0"
optional = true

[target.'cfg(target_os = "windows")'.dependencies.winapi]
version = "0.3.6"

Expand Down
Loading