diff --git a/Cargo.lock b/Cargo.lock index c8af92a969373c30a36ba7af19e3fc04e6675b25..70dadd1f2f939c0c8b755de23e6a25703fe14b21 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7107,6 +7107,7 @@ dependencies = [ "sum_tree", "taffy", "thiserror 2.0.12", + "tracy-client", "unicode-segmentation", "usvg", "util", @@ -16889,6 +16890,28 @@ dependencies = [ "tracing-serde", ] +[[package]] +name = "tracy-client" +version = "0.18.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef54005d3d760186fd662dad4b7bb27ecd5531cdef54d1573ebd3f20a9205ed7" +dependencies = [ + "loom", + "once_cell", + "rustc-demangle", + "tracy-client-sys", +] + +[[package]] +name = "tracy-client-sys" +version = "0.26.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "319c70195101a93f56db4c74733e272d720768e13471f400c78406a326b172b0" +dependencies = [ + "cc", + "windows-targets 0.52.6", +] + [[package]] name = "trait-variant" version = "0.1.2" @@ -20335,6 +20358,7 @@ dependencies = [ "time", "title_bar", "toolchain_selector", + "tracy-client", "tree-sitter-md", "tree-sitter-rust", "ui", diff --git a/Cargo.toml b/Cargo.toml index 9c64ef0464db0ad2d557c1e5d2e107fd3e6c4804..9581175e1bdb3a35896536e6fec38b433f119bb6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -667,6 +667,7 @@ tokio = { version = "1" } tokio-tungstenite = { version = "0.26", features = ["__rustls-tls"] } toml = "0.8" tower-http = "0.4.4" +tracy-client = { version = "0.18.2", default-features = false, features = ["enable", "demangle"] } tree-sitter = { version = "0.25.10", features = ["wasm"] } tree-sitter-bash = "0.25.0" tree-sitter-c = "0.23" diff --git a/crates/gpui/Cargo.toml b/crates/gpui/Cargo.toml index 4544b561c33f4507e8264e4eed46711425ce2a04..da387d05f5f19d2526f89d402a36c6cd8cd30dcd 100644 --- a/crates/gpui/Cargo.toml +++ b/crates/gpui/Cargo.toml @@ -72,6 +72,7 @@ screen-capture = [ "scap", ] windows-manifest = [] +tracy = ["dep:tracy-client"] [lib] path = "src/gpui.rs" @@ -124,6 +125,7 @@ strum.workspace = true sum_tree.workspace = true taffy = "=0.9.0" thiserror.workspace = true +tracy-client = { workspace = true, optional = true } util.workspace = true uuid.workspace = true waker-fn = "1.2.0" diff --git a/crates/gpui/src/app.rs b/crates/gpui/src/app.rs index 07ff04e32abc19dbe681ab6214d06469fe7917ff..1bf9b6c1791a7575d12da2d0933c54bbb222597f 100644 --- a/crates/gpui/src/app.rs +++ b/crates/gpui/src/app.rs @@ -130,6 +130,9 @@ impl Application { /// Builds an app with the given asset source. #[allow(clippy::new_without_default)] pub fn new() -> Self { + #[cfg(feature = "tracy")] + let _zone = tracy_client::span!(); + #[cfg(any(test, feature = "test-support"))] log::info!("GPUI was compiled in test mode"); @@ -175,6 +178,9 @@ impl Application { where F: 'static + FnOnce(&mut App), { + #[cfg(feature = "tracy")] + let _zone = tracy_client::span!(); + let this = self.0.clone(); let platform = self.0.borrow().platform.clone(); platform.run(Box::new(move || { diff --git a/crates/zed/Cargo.toml b/crates/zed/Cargo.toml index c2e27cc34fa76e0860bb1f6d7f994c7799c3c744..9d993ff4eb4c097004fff243be2ec5fefe902d3c 100644 --- a/crates/zed/Cargo.toml +++ b/crates/zed/Cargo.toml @@ -18,6 +18,10 @@ path = "src/zed-main.rs" name = "zed" path = "src/main.rs" +[features] +tracy = ["dep:tracy-client", "gpui/tracy"] +tracy-memory = ["tracy"] + [dependencies] acp_tools.workspace = true activity_indicator.workspace = true @@ -146,6 +150,7 @@ theme_selector.workspace = true time.workspace = true title_bar.workspace = true toolchain_selector.workspace = true +tracy-client = { workspace = true, optional = true } ui.workspace = true ui_input.workspace = true ui_prompt.workspace = true diff --git a/crates/zed/src/main.rs b/crates/zed/src/main.rs index 29868be577bac136e97781a0082d77fa35c73e25..09ef9203a547452b52e3b5a60c0a72c8f34df430 100644 --- a/crates/zed/src/main.rs +++ b/crates/zed/src/main.rs @@ -59,10 +59,20 @@ use zed::{ use crate::zed::OpenRequestKind; -#[cfg(feature = "mimalloc")] +#[cfg(all(feature = "mimalloc", not(features = "tracy-memory")))] #[global_allocator] static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc; +#[cfg(all(feature = "mimalloc", features = "tracy-memory"))] +#[global_allocator] +static GLOBAL: tracy_client::ProfiledAllocator = + tracy_client::ProfiledAllocator::new(mimalloc::MiMalloc, 100); + +#[cfg(all(not(feature = "mimalloc"), feature = "tracy-memory"))] +#[global_allocator] +static GLOBAL: tracy_client::ProfiledAllocator = + tracy_client::ProfiledAllocator::new(std::alloc::System, 100); + fn files_not_created_on_launch(errors: HashMap>) { let message = "Zed failed to launch"; let error_details = errors @@ -165,6 +175,9 @@ fn fail_to_open_window(e: anyhow::Error, _cx: &mut App) { } pub fn main() { + #[cfg(feature = "tracy")] + let _zone = tracy_client::span!(); + #[cfg(unix)] util::prevent_root_execution(); @@ -371,6 +384,9 @@ pub fn main() { }); app.run(move |cx| { + #[cfg(feature = "tracy")] + let _zone = tracy_client::span!(); + menu::init(); zed_actions::init(); diff --git a/crates/zed/src/zed-main.rs b/crates/zed/src/zed-main.rs index 6c49c197dda01e97828c3662aa09ecf57804dfbc..8f4ef0a062fcb7d28f44025fd35e707779a08180 100644 --- a/crates/zed/src/zed-main.rs +++ b/crates/zed/src/zed-main.rs @@ -2,6 +2,12 @@ #![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] pub fn main() { + #[cfg(feature = "tracy")] + { + tracy_client::register_demangler!(); + tracy_client::Client::start(); + } + // separated out so that the file containing the main function can be imported by other crates, // while having all gpui resources that are registered in main (primarily actions) initialized zed::main();