mirror of
https://github.com/emilk/egui.git
synced 2026-08-31 22:00:03 -04:00
Use profiling crate to support more profiler backends (#5150)
Hey! I am not sure if this is something that's been considered before and decided against (I couldn't find any PR's or issues). This change removes the internal profiling macros in library crates and the `puffin` feature and replaces it with similar functions in the [profiling](https://github.com/aclysma/profiling) crate. This crate provides a layer of abstraction over various profiler instrumentation crates and allows library users to pick their favorite (supported) profiler. An additional benefit for puffin users is that dependencies of egui are included in the instrumentation output too (mainly wgpu which uses the profiling crate), so more details might be available when profiling. A breaking change is that instead of using the `puffin` feature on egui, users that want to profile the crate with puffin instead have to enable the `profile-with-puffin` feature on the profiling crate. Similarly they could instead choose to use `profile-with-tracy` etc. I tried to add a 'tracy' feature to egui_demo_app in order to showcase , however the /scripts/check.sh currently breaks on mutually exclusive features (which this introduces), so I decided against including it for the initial PR. I'm happy to iterate more on this if there is interest in taking this PR though. Screenshot showing the additional info for wgpu now available when using puffin 
This commit is contained in:
@@ -104,7 +104,7 @@ impl Painter {
|
||||
render_state: &RenderState,
|
||||
config: &WgpuConfiguration,
|
||||
) {
|
||||
crate::profile_function!();
|
||||
profiling::function_scope!();
|
||||
|
||||
let width = surface_state.width;
|
||||
let height = surface_state.height;
|
||||
@@ -156,7 +156,7 @@ impl Painter {
|
||||
viewport_id: ViewportId,
|
||||
window: Option<Arc<winit::window::Window>>,
|
||||
) -> Result<(), crate::WgpuError> {
|
||||
crate::profile_scope!("Painter::set_window"); // profile_function gives bad names for async functions
|
||||
profiling::scope!("Painter::set_window"); // profile_function gives bad names for async functions
|
||||
|
||||
if let Some(window) = window {
|
||||
let size = window.inner_size();
|
||||
@@ -182,7 +182,7 @@ impl Painter {
|
||||
viewport_id: ViewportId,
|
||||
window: Option<&winit::window::Window>,
|
||||
) -> Result<(), crate::WgpuError> {
|
||||
crate::profile_scope!("Painter::set_window_unsafe"); // profile_function gives bad names for async functions
|
||||
profiling::scope!("Painter::set_window_unsafe"); // profile_function gives bad names for async functions
|
||||
|
||||
if let Some(window) = window {
|
||||
let size = window.inner_size();
|
||||
@@ -273,7 +273,7 @@ impl Painter {
|
||||
width_in_pixels: NonZeroU32,
|
||||
height_in_pixels: NonZeroU32,
|
||||
) {
|
||||
crate::profile_function!();
|
||||
profiling::function_scope!();
|
||||
|
||||
let width = width_in_pixels.get();
|
||||
let height = height_in_pixels.get();
|
||||
@@ -344,7 +344,7 @@ impl Painter {
|
||||
width_in_pixels: NonZeroU32,
|
||||
height_in_pixels: NonZeroU32,
|
||||
) {
|
||||
crate::profile_function!();
|
||||
profiling::function_scope!();
|
||||
|
||||
if self.surfaces.contains_key(&viewport_id) {
|
||||
self.resize_and_generate_depth_texture_view_and_msaa_view(
|
||||
@@ -372,7 +372,7 @@ impl Painter {
|
||||
textures_delta: &epaint::textures::TexturesDelta,
|
||||
capture_data: Vec<UserData>,
|
||||
) -> f32 {
|
||||
crate::profile_function!();
|
||||
profiling::function_scope!();
|
||||
|
||||
let capture = !capture_data.is_empty();
|
||||
let mut vsync_sec = 0.0;
|
||||
@@ -418,7 +418,7 @@ impl Painter {
|
||||
};
|
||||
|
||||
let output_frame = {
|
||||
crate::profile_scope!("get_current_texture");
|
||||
profiling::scope!("get_current_texture");
|
||||
// This is what vsync-waiting happens on my Mac.
|
||||
let start = web_time::Instant::now();
|
||||
let output_frame = surface_state.surface.get_current_texture();
|
||||
@@ -514,13 +514,13 @@ impl Painter {
|
||||
}
|
||||
|
||||
let encoded = {
|
||||
crate::profile_scope!("CommandEncoder::finish");
|
||||
profiling::scope!("CommandEncoder::finish");
|
||||
encoder.finish()
|
||||
};
|
||||
|
||||
// Submit the commands: both the main buffer and user-defined ones.
|
||||
{
|
||||
crate::profile_scope!("Queue::submit");
|
||||
profiling::scope!("Queue::submit");
|
||||
// wgpu doesn't document where vsync can happen. Maybe here?
|
||||
let start = web_time::Instant::now();
|
||||
render_state
|
||||
@@ -552,7 +552,7 @@ impl Painter {
|
||||
}
|
||||
|
||||
{
|
||||
crate::profile_scope!("present");
|
||||
profiling::scope!("present");
|
||||
// wgpu doesn't document where vsync can happen. Maybe here?
|
||||
let start = web_time::Instant::now();
|
||||
output_frame.present();
|
||||
|
||||
Reference in New Issue
Block a user