mirror of
https://github.com/emilk/egui.git
synced 2026-08-30 13:20:05 -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:
@@ -100,7 +100,7 @@ pub struct FileStorage {
|
||||
impl Drop for FileStorage {
|
||||
fn drop(&mut self) {
|
||||
if let Some(join_handle) = self.last_save_join_handle.take() {
|
||||
crate::profile_scope!("wait_for_save");
|
||||
profiling::scope!("wait_for_save");
|
||||
join_handle.join().ok();
|
||||
}
|
||||
}
|
||||
@@ -109,7 +109,7 @@ impl Drop for FileStorage {
|
||||
impl FileStorage {
|
||||
/// Store the state in this .ron file.
|
||||
pub(crate) fn from_ron_filepath(ron_filepath: impl Into<PathBuf>) -> Self {
|
||||
crate::profile_function!();
|
||||
profiling::function_scope!();
|
||||
let ron_filepath: PathBuf = ron_filepath.into();
|
||||
log::debug!("Loading app state from {:?}…", ron_filepath);
|
||||
Self {
|
||||
@@ -122,7 +122,7 @@ impl FileStorage {
|
||||
|
||||
/// Find a good place to put the files that the OS likes.
|
||||
pub fn from_app_id(app_id: &str) -> Option<Self> {
|
||||
crate::profile_function!(app_id);
|
||||
profiling::function_scope!();
|
||||
if let Some(data_dir) = storage_dir(app_id) {
|
||||
if let Err(err) = std::fs::create_dir_all(&data_dir) {
|
||||
log::warn!(
|
||||
@@ -155,7 +155,7 @@ impl crate::Storage for FileStorage {
|
||||
|
||||
fn flush(&mut self) {
|
||||
if self.dirty {
|
||||
crate::profile_function!();
|
||||
profiling::scope!("FileStorage::flush");
|
||||
self.dirty = false;
|
||||
|
||||
let file_path = self.ron_filepath.clone();
|
||||
@@ -184,7 +184,7 @@ impl crate::Storage for FileStorage {
|
||||
}
|
||||
|
||||
fn save_to_disk(file_path: &PathBuf, kv: &HashMap<String, String>) {
|
||||
crate::profile_function!();
|
||||
profiling::function_scope!();
|
||||
|
||||
if let Some(parent_dir) = file_path.parent() {
|
||||
if !parent_dir.exists() {
|
||||
@@ -199,7 +199,7 @@ fn save_to_disk(file_path: &PathBuf, kv: &HashMap<String, String>) {
|
||||
let mut writer = std::io::BufWriter::new(file);
|
||||
let config = Default::default();
|
||||
|
||||
crate::profile_scope!("ron::serialize");
|
||||
profiling::scope!("ron::serialize");
|
||||
if let Err(err) = ron::ser::to_writer_pretty(&mut writer, &kv, config)
|
||||
.and_then(|_| writer.flush().map_err(|err| err.into()))
|
||||
{
|
||||
@@ -220,7 +220,7 @@ fn read_ron<T>(ron_path: impl AsRef<Path>) -> Option<T>
|
||||
where
|
||||
T: serde::de::DeserializeOwned,
|
||||
{
|
||||
crate::profile_function!();
|
||||
profiling::function_scope!();
|
||||
match std::fs::File::open(ron_path) {
|
||||
Ok(file) => {
|
||||
let reader = std::io::BufReader::new(file);
|
||||
|
||||
Reference in New Issue
Block a user