1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-30 21:30:03 -04:00

Add more puffin profile scopes to eframe (#3330)

* Add puffin profile scopes to the startup and running of eframe

* puffin_profiler example: start puffin right away

* cargo format let-else statements

* More profile scopes

* Add some `#[inline]`

* Standardize puffin profile scope definitions

* standardize again

* Silence warning when puffin is disabled
This commit is contained in:
Emil Ernerfeldt
2023-09-13 09:00:38 +02:00
committed by GitHub
parent 2bc6814acc
commit fc3bddd0cf
17 changed files with 414 additions and 255 deletions

View File

@@ -112,22 +112,30 @@ pub fn check_for_gl_error_impl(gl: &glow::Context, file: &str, line: u32, contex
// ---------------------------------------------------------------------------
/// Profiling macro for feature "puffin"
macro_rules! profile_function {
($($arg: tt)*) => {
#[cfg(feature = "puffin")]
#[cfg(not(target_arch = "wasm32"))]
puffin::profile_function!($($arg)*);
};
}
pub(crate) use profile_function;
mod profiling_scopes {
#![allow(unused_macros)]
#![allow(unused_imports)]
/// Profiling macro for feature "puffin"
macro_rules! profile_scope {
($($arg: tt)*) => {
#[cfg(feature = "puffin")]
#[cfg(not(target_arch = "wasm32"))]
puffin::profile_scope!($($arg)*);
};
/// 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;
}
pub(crate) use profile_scope;
#[allow(unused_imports)]
pub(crate) use profiling_scopes::*;

View File

@@ -494,10 +494,13 @@ impl Painter {
"Mismatch between texture size and texel count"
);
let data: Vec<u8> = image
.srgba_pixels(None)
.flat_map(|a| a.to_array())
.collect();
let data: Vec<u8> = {
crate::profile_scope!("font -> sRGBA");
image
.srgba_pixels(None)
.flat_map(|a| a.to_array())
.collect()
};
self.upload_texture_srgb(delta.pos, image.size, delta.options, &data);
}
@@ -511,6 +514,7 @@ impl Painter {
options: egui::TextureOptions,
data: &[u8],
) {
crate::profile_function!();
assert_eq!(data.len(), w * h * 4);
assert!(
w <= self.max_texture_side && h <= self.max_texture_side,
@@ -561,6 +565,7 @@ impl Painter {
let level = 0;
if let Some([x, y]) = pos {
crate::profile_scope!("gl.tex_sub_image_2d");
self.gl.tex_sub_image_2d(
glow::TEXTURE_2D,
level,
@@ -575,6 +580,7 @@ impl Painter {
check_for_gl_error!(&self.gl, "tex_sub_image_2d");
} else {
let border = 0;
crate::profile_scope!("gl.tex_image_2d");
self.gl.tex_image_2d(
glow::TEXTURE_2D,
level,