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

Use profiling crate to support more profiler backends #5150

Merged
merged 33 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
5d7060c
Convert custom profiling function and scope abstractions in epaint to…
teddemunnik Sep 22, 2024
7e38bb4
Convert custom profiling function and scope abstractions in egui to p…
teddemunnik Sep 22, 2024
96a64e6
Convert custom profiling function and scope abstractions in egui to p…
teddemunnik Sep 22, 2024
ba0fb95
Convert custom profiling function and scope abstractions in egui-glow…
teddemunnik Sep 22, 2024
65ed0d8
Convert custom profiling function and scope abstractions in egui-wgpu…
teddemunnik Sep 22, 2024
6f44f71
Convert custom profiling function and scope abstractions in egui-extr…
teddemunnik Sep 22, 2024
8c1fe36
Make egui_demo_app work with the new profiling crate macros
teddemunnik Sep 22, 2024
0775067
Convert custom profiling function and scope abstractions, and puffin …
teddemunnik Sep 22, 2024
a5dec2c
Update puffin_profiler sample to use enable puffin feature in the pro…
teddemunnik Sep 22, 2024
f327f85
Update docstring to reference the profiling crate instead of a specif…
teddemunnik Sep 22, 2024
f177a29
Add tracy feature to egui_demo_app to test out another profiling crat…
teddemunnik Sep 22, 2024
d21a5c7
Fix typo
teddemunnik Sep 22, 2024
b08c82b
Fix remaining usages of profile_function!()
teddemunnik Sep 22, 2024
5777057
Remove tracy feature as mutually exclusive features are not handled b…
teddemunnik Sep 22, 2024
c023e83
Fix compile error on wasm due to profiling dependency being native only
teddemunnik Sep 22, 2024
3cccf8a
Merge remote-tracking branch 'upstream/master' into pr/profiling-crate
teddemunnik Sep 23, 2024
c981259
Merge remote-tracking branch 'upstream/master' into pr/profiling-crate
teddemunnik Sep 23, 2024
ad4dc3b
Review feedback: alphabetical sorting of cargo dependencies
teddemunnik Sep 24, 2024
383dc6e
Add crate level docs about the usage of the profiling crate
teddemunnik Sep 25, 2024
b16593f
Merge branch 'master' into pr/profiling-crate
teddemunnik Oct 27, 2024
b1309d7
Update to profiling 1.0.16
teddemunnik Oct 27, 2024
e866c67
Replace usages of #[profiling::function] with profiling::function_sco…
teddemunnik Oct 27, 2024
23c15a7
Fix regressions caused by initial switch to procedural macros, and ma…
teddemunnik Oct 27, 2024
4e37c17
Disable default features for profiling crate, disabling it's procedur…
teddemunnik Oct 27, 2024
a6dc835
Ignore profiling dependency from cargo machete. It looks unused, as i…
teddemunnik Oct 27, 2024
b7dbd7a
Merge branch 'master' into pr/profiling-crate
teddemunnik Oct 27, 2024
c51b193
Fix compilation error after syncing with master by replacing a new us…
teddemunnik Oct 27, 2024
088161c
Replace more usages of built in profiling macro with profiling crate …
teddemunnik Oct 27, 2024
051b3ba
Mark TOML sample as TOML so that doc test does not attempt to run it …
teddemunnik Oct 27, 2024
13e2db6
Also mark egui inline toml as toml to not fail doc tests
teddemunnik Oct 27, 2024
ed3de69
Merge branch 'master' into pr/profiling-crate
teddemunnik Dec 14, 2024
2ff6c4b
Fix compilation issues after merge with master
teddemunnik Dec 14, 2024
dfd43aa
Convert new usages of crate::profile_scope! to profiling::scope!
teddemunnik Dec 15, 2024
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
30 changes: 23 additions & 7 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1235,7 +1235,7 @@ dependencies = [
"parking_lot",
"percent-encoding",
"pollster 0.4.0",
"puffin",
"profiling",
"raw-window-handle 0.6.2",
"ron",
"serde",
Expand Down Expand Up @@ -1263,7 +1263,7 @@ dependencies = [
"epaint",
"log",
"nohash-hasher",
"puffin",
"profiling",
"ron",
"serde",
]
Expand All @@ -1278,7 +1278,7 @@ dependencies = [
"egui",
"epaint",
"log",
"puffin",
"profiling",
"thiserror",
"type-map",
"web-time",
Expand All @@ -1296,7 +1296,7 @@ dependencies = [
"document-features",
"egui",
"log",
"puffin",
"profiling",
"raw-window-handle 0.6.2",
"serde",
"smithay-clipboard",
Expand All @@ -1321,6 +1321,7 @@ dependencies = [
"image",
"log",
"poll-promise",
"profiling",
"puffin",
"puffin_http",
"rfd",
Expand Down Expand Up @@ -1360,7 +1361,7 @@ dependencies = [
"image",
"log",
"mime_guess2",
"puffin",
"profiling",
"resvg",
"serde",
"syntect",
Expand All @@ -1380,7 +1381,7 @@ dependencies = [
"glutin-winit",
"log",
"memoffset",
"puffin",
"profiling",
"wasm-bindgen",
"web-sys",
"winit",
Expand Down Expand Up @@ -1528,7 +1529,7 @@ dependencies = [
"log",
"nohash-hasher",
"parking_lot",
"puffin",
"profiling",
"rayon",
"serde",
]
Expand Down Expand Up @@ -3109,6 +3110,20 @@ name = "profiling"
version = "1.0.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "afbdc74edc00b6f6a218ca6a5364d6226a259d4b8ea1af4a0ea063f27e179f4d"
dependencies = [
"profiling-procmacros",
"puffin",
]

[[package]]
name = "profiling-procmacros"
version = "1.0.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a65f2e60fbf1063868558d69c6beacf412dc755f9fc020f514b7955fc914fe30"
dependencies = [
"quote",
"syn",
]

[[package]]
name = "puffin"
Expand Down Expand Up @@ -3147,6 +3162,7 @@ dependencies = [
"eframe",
"env_logger",
"log",
"profiling",
"puffin",
"puffin_http",
]
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ log = { version = "0.4", features = ["std"] }
nohash-hasher = "0.2"
parking_lot = "0.12"
pollster = "0.4"
profiling = {version = "1.0", default-features = false }
puffin = "0.19"
puffin_http = "0.16"
raw-window-handle = "0.6.0"
Expand Down
15 changes: 1 addition & 14 deletions crates/eframe/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,19 +71,6 @@ persistence = [
"serde",
]

## Enable profiling with the [`puffin`](https://docs.rs/puffin) crate.
##
## `eframe` will call `puffin::GlobalProfiler::lock().new_frame()` for you
##
## Only enabled on native, because of the low resolution (1ms) of clocks in browsers.
puffin = [
"dep:puffin",
"egui/puffin",
"egui_glow?/puffin",
"egui-wgpu?/puffin",
"egui-winit/puffin",
]

## Enables wayland support and fixes clipboard issue.
wayland = ["egui-winit/wayland", "egui-wgpu?/wayland", "egui_glow?/wayland", "glutin?/wayland", "glutin-winit?/wayland"]

Expand Down Expand Up @@ -127,6 +114,7 @@ ahash.workspace = true
document-features.workspace = true
log.workspace = true
parking_lot.workspace = true
profiling.workspace = true
raw-window-handle.workspace = true
static_assertions = "1.1.0"
web-time.workspace = true
Expand Down Expand Up @@ -157,7 +145,6 @@ pollster = { workspace = true, optional = true } # needed for wgpu
glutin = { workspace = true, optional = true, default-features = false, features = ["egl", "wgl"] }
glutin-winit = { workspace = true, optional = true, default-features = false, features = ["egl", "wgl"] }
home = { workspace = true, optional = true }
puffin = { workspace = true, optional = true }
wgpu = { workspace = true, optional = true, features = [
# Let's enable some backends so that users can use `eframe` out-of-the-box
# without having to explicitly opt-in to backends
Expand Down
7 changes: 3 additions & 4 deletions crates/eframe/src/epi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -788,8 +788,7 @@ pub struct IntegrationInfo {
///
/// This includes [`App::update`] as well as rendering (except for vsync waiting).
///
/// For a more detailed view of cpu usage, use the [`puffin`](https://crates.io/crates/puffin)
/// profiler together with the `puffin` feature of `eframe`.
/// For a more detailed view of cpu usage, connect your preferred profiler by enabling it's feature in [`profiling`](https://crates.io/crates/profiling).
///
/// `None` if this is the first frame.
pub cpu_usage: Option<f32>,
Expand Down Expand Up @@ -831,7 +830,7 @@ impl Storage for DummyStorage {
/// Get and deserialize the [RON](https://github.com/ron-rs/ron) stored at the given key.
#[cfg(feature = "ron")]
pub fn get_value<T: serde::de::DeserializeOwned>(storage: &dyn Storage, key: &str) -> Option<T> {
crate::profile_function!(key);
profiling::function_scope!(key);
storage
.get_string(key)
.and_then(|value| match ron::from_str(&value) {
Expand All @@ -847,7 +846,7 @@ pub fn get_value<T: serde::de::DeserializeOwned>(storage: &dyn Storage, key: &st
/// Serialize the given value as [RON](https://github.com/ron-rs/ron) and store with the given key.
#[cfg(feature = "ron")]
pub fn set_value<T: serde::Serialize>(storage: &mut dyn Storage, key: &str, value: &T) {
crate::profile_function!(key);
profiling::function_scope!(key);
match ron::ser::to_string(value) {
Ok(string) => storage.set_string(key, string),
Err(err) => log::error!("eframe failed to encode data using ron: {}", err),
Expand Down
6 changes: 3 additions & 3 deletions crates/eframe/src/icon_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub trait IconDataExt {
/// # Errors
/// If this is not a valid png.
pub fn from_png_bytes(png_bytes: &[u8]) -> Result<IconData, image::ImageError> {
crate::profile_function!();
profiling::function_scope!();
let image = image::load_from_memory(png_bytes)?;
Ok(from_image(image))
}
Expand All @@ -38,7 +38,7 @@ fn from_image(image: image::DynamicImage) -> IconData {

impl IconDataExt for IconData {
fn to_image(&self) -> Result<image::RgbaImage, String> {
crate::profile_function!();
profiling::function_scope!();
let Self {
rgba,
width,
Expand All @@ -48,7 +48,7 @@ impl IconDataExt for IconData {
}

fn to_png_bytes(&self) -> Result<Vec<u8>, String> {
crate::profile_function!();
profiling::function_scope!();
let image = self.to_image()?;
let mut png_bytes: Vec<u8> = Vec::new();
image
Expand Down
41 changes: 11 additions & 30 deletions crates/eframe/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,17 @@
//! ## Feature flags
#![doc = document_features::document_features!()]
//!
//! ## Instrumentation
//! This crate supports using the [profiling](https://crates.io/crates/profiling) crate for instrumentation.
//! You can enable features on the profiling crates in your application to add instrumentation for all
//! crates that support it, including egui. See the profiling crate docs for more information.
//! ```toml
//! [dependencies]
//! profiling = "1.0"
//! [features]
//! profile-with-puffin = ["profiling/profile-with-puffin"]
//! ```
//!

#![warn(missing_docs)] // let's keep eframe well-documented
#![allow(clippy::needless_doctest_main)]
Expand Down Expand Up @@ -445,33 +456,3 @@ impl std::fmt::Display for Error {

/// Short for `Result<T, eframe::Error>`.
pub type Result<T = (), E = Error> = std::result::Result<T, E>;

// ---------------------------------------------------------------------------

mod profiling_scopes {
#![allow(unused_macros)]
#![allow(unused_imports)]

/// Profiling macro for feature "puffin"
macro_rules! profile_function {
($($arg: tt)*) => {
#[cfg(feature = "puffin")]
#[cfg(not(target_arch = "wasm32"))] // Disabled on web because of the coarse 1ms clock resolution there.
puffin::profile_function!($($arg)*);
};
}
pub(crate) use profile_function;

/// Profiling macro for feature "puffin"
macro_rules! profile_scope {
($($arg: tt)*) => {
#[cfg(feature = "puffin")]
#[cfg(not(target_arch = "wasm32"))] // Disabled on web because of the coarse 1ms clock resolution there.
puffin::profile_scope!($($arg)*);
};
}
pub(crate) use profile_scope;
}

#[allow(unused_imports)]
pub(crate) use profiling_scopes::{profile_function, profile_scope};
8 changes: 4 additions & 4 deletions crates/eframe/src/native/app_icon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ enum AppIconStatus {
/// Since window creation can be lazy, call this every frame until it's either successfully or gave up.
/// (See [`AppIconStatus`])
fn set_title_and_icon(_title: &str, _icon_data: Option<&IconData>) -> AppIconStatus {
crate::profile_function!();
profiling::function_scope!();

#[cfg(target_os = "windows")]
{
Expand Down Expand Up @@ -201,7 +201,7 @@ fn set_app_icon_windows(icon_data: &IconData) -> AppIconStatus {
#[allow(unsafe_code)]
fn set_title_and_icon_mac(title: &str, icon_data: Option<&IconData>) -> AppIconStatus {
use crate::icon_data::IconDataExt as _;
crate::profile_function!();
profiling::function_scope!();

use objc2::ClassType;
use objc2_app_kit::{NSApplication, NSImage};
Expand Down Expand Up @@ -237,7 +237,7 @@ fn set_title_and_icon_mac(title: &str, icon_data: Option<&IconData>) -> AppIconS
log::trace!("NSImage::initWithData…");
let app_icon = NSImage::initWithData(NSImage::alloc(), &data);

crate::profile_scope!("setApplicationIconImage_");
profiling::scope!("setApplicationIconImage_");
log::trace!("setApplicationIconImage…");
app.setApplicationIconImage(app_icon.as_deref());
}
Expand All @@ -246,7 +246,7 @@ fn set_title_and_icon_mac(title: &str, icon_data: Option<&IconData>) -> AppIconS
if let Some(main_menu) = app.mainMenu() {
if let Some(item) = main_menu.itemAtIndex(0) {
if let Some(app_menu) = item.submenu() {
crate::profile_scope!("setTitle_");
profiling::scope!("setTitle_");
app_menu.setTitle(&NSString::from_str(title));
}
}
Expand Down
Loading
Loading