1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-29 04:40: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

![image](https://github.com/user-attachments/assets/49fc0e7e-8f88-40cb-a69e-74ca2e3f90f3)
This commit is contained in:
Ted de Munnik
2024-12-16 09:15:54 +01:00
committed by GitHub
parent 9aae14cdf4
commit 3af907919b
46 changed files with 272 additions and 482 deletions

View File

@@ -1363,7 +1363,7 @@ impl Tessellator {
self.tessellate_ellipse(ellipse, out);
}
Shape::Mesh(mesh) => {
crate::profile_scope!("mesh");
profiling::scope!("mesh");
if self.options.validate_meshes && !mesh.is_valid() {
debug_assert!(false, "Invalid Mesh in Shape::Mesh");
@@ -1596,7 +1596,7 @@ impl Tessellator {
return;
}
crate::profile_function!();
profiling::function_scope!();
let PathShape {
points,
@@ -1977,7 +1977,7 @@ impl Tessellator {
/// A list of clip rectangles with matching [`Mesh`].
#[allow(unused_mut)]
pub fn tessellate_shapes(&mut self, mut shapes: Vec<ClippedShape>) -> Vec<ClippedPrimitive> {
crate::profile_function!();
profiling::function_scope!();
#[cfg(feature = "rayon")]
if self.options.parallel_tessellation {
@@ -1987,7 +1987,7 @@ impl Tessellator {
let mut clipped_primitives: Vec<ClippedPrimitive> = Vec::default();
{
crate::profile_scope!("tessellate");
profiling::scope!("tessellate");
for clipped_shape in shapes {
self.tessellate_clipped_shape(clipped_shape, &mut clipped_primitives);
}
@@ -2024,7 +2024,7 @@ impl Tessellator {
/// then replace the original shape with their tessellated meshes.
#[cfg(feature = "rayon")]
fn parallel_tessellation_of_large_shapes(&self, shapes: &mut [ClippedShape]) {
crate::profile_function!();
profiling::function_scope!();
use rayon::prelude::*;
@@ -2054,7 +2054,7 @@ impl Tessellator {
.enumerate()
.filter(|(_, clipped_shape)| should_parallelize(&clipped_shape.shape))
.map(|(index, clipped_shape)| {
crate::profile_scope!("tessellate_big_shape");
profiling::scope!("tessellate_big_shape");
// TODO(emilk): reuse tessellator in a thread local
let mut tessellator = (*self).clone();
let mut mesh = Mesh::default();
@@ -2063,7 +2063,7 @@ impl Tessellator {
})
.collect();
crate::profile_scope!("distribute results", tessellated.len().to_string());
profiling::scope!("distribute results", tessellated.len().to_string());
for (index, mesh) in tessellated {
shapes[index].shape = Shape::Mesh(mesh);
}