Skip to content

Commit 170b21b

Browse files
authored
Add opt-in support for the 'puffin' profiler in eframe (#1483)
1 parent 973c3f2 commit 170b21b

File tree

20 files changed

+304
-9
lines changed

20 files changed

+304
-9
lines changed

Cargo.lock

Lines changed: 108 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ members = [
1212
"emath",
1313
"epaint",
1414
"epi",
15+
16+
"examples/puffin_profiler",
1517
]
1618

1719
[profile.dev]

eframe/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ NOTE: [`egui_web`](../egui_web/CHANGELOG.md), [`egui-winit`](../egui-winit/CHANG
2222
* `dark-light` (dark mode detection) is now an opt-in feature ([#1437](https://github.com/emilk/egui/pull/1437)).
2323
* Fixed potential scale bug when DPI scaling changes (e.g. when dragging a window between different displays) ([#1441](https://github.com/emilk/egui/pull/1441)).
2424
* MSRV (Minimum Supported Rust Version) is now `1.60.0` ([#1467](https://github.com/emilk/egui/pull/1467)).
25+
* Added new feature `puffin` to add [`puffin profiler`](https://github.com/EmbarkStudios/puffin) scopes ([#1483](https://github.com/emilk/egui/pull/1483)).
2526

2627

2728
## 0.17.0 - 2022-02-22

eframe/Cargo.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ persistence = [
3737
"epi/persistence",
3838
]
3939

40+
# Enable profiling with the puffin crate: https://github.com/EmbarkStudios/puffin
41+
# Only enabled on native, because of the low resolution (1ms) of time keeping in browsers.
42+
# eframe will call `puffin::GlobalProfiler::lock().new_frame()` for you
43+
puffin = ["egui_glow/puffin"]
44+
4045
# enable screen reader support (requires `ctx.options().screen_reader = true;`)
4146
screen_reader = [
4247
"egui-winit/screen_reader",
@@ -74,5 +79,7 @@ image = { version = "0.24", default-features = false, features = [
7479
"png",
7580
] }
7681
poll-promise = "0.1"
82+
puffin = "0.13"
83+
puffin_http = "0.10"
7784
rfd = "0.8"
7885
three-d = { version = "0.11", default-features = false }

eframe/README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@
88

99
`eframe` is the official framework library for writing apps using [`egui`](https://github.com/emilk/egui). The app can be compiled both to run natively (cross platform) or be compiled to a web app (using WASM).
1010

11-
To get started, go to <https://github.com/emilk/eframe_template/> and follow the instructions there!
11+
To get started, see the [crate examples](https://github.com/emilk/egui/tree/master/examples) and [single-file examples](https://github.com/emilk/egui/tree/master/eframe/examples).
12+
To learn how to set up `eframe` for web and native, go to <https://github.com/emilk/eframe_template/> and follow the instructions there!
1213

13-
You can also take a look at [the `eframe` examples folder](https://github.com/emilk/egui/tree/master/eframe/examples). There is also an excellent tutorial video at <https://www.youtube.com/watch?v=NtUkr_z7l84>.
14+
There is also a tutorial video at <https://www.youtube.com/watch?v=NtUkr_z7l84>.
1415

1516
For how to use `egui`, see [the egui docs](https://docs.rs/egui).
1617

@@ -37,6 +38,7 @@ Not all rust crates work when compiled to WASM, but here are some useful crates
3738
* Audio: [`cpal`](https://github.com/RustAudio/cpal).
3839
* HTTP client: [`ehttp`](https://github.com/emilk/ehttp).
3940
* Time: [`chrono`](https://github.com/chronotope/chrono).
41+
* WebSockets: [`ewebsock`](https://github.com/rerun-io/ewebsock).
4042

4143

4244
## Name

eframe/src/lib.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44
//! and are happy with just using egui for all visuals,
55
//! Then `eframe` is for you!
66
//!
7-
//! To get started, look at <https://github.com/emilk/eframe_template>.
8-
//!
9-
//! You can also take a look at [the `eframe` examples folder](https://github.com/emilk/egui/tree/master/eframe/examples).
7+
//! To get started, see the [crate examples](https://github.com/emilk/egui/tree/master/examples) and [single-file examples](https://github.com/emilk/egui/tree/master/eframe/examples).
8+
//! To learn how to set up `eframe` for web and native, go to <https://github.com/emilk/eframe_template/> and follow the instructions there!
109
//!
1110
//! You write your application code for [`epi`] (implementing [`epi::App`]) and then
1211
//! call from [`crate::run_native`] your `main.rs`, and/or call `eframe::start_web` from your `lib.rs`.

egui-winit/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ All notable changes to the `egui-winit` integration will be noted in this file.
77
* Renamed the feature `convert_bytemuck` to `bytemuck` ([#1467](https://github.com/emilk/egui/pull/1467)).
88
* Renamed the feature `serialize` to `serde` ([#1467](https://github.com/emilk/egui/pull/1467)).
99
* MSRV (Minimum Supported Rust Version) is now `1.60.0` ([#1467](https://github.com/emilk/egui/pull/1467)).
10+
* Added new feature `puffin` to add [`puffin profiler`](https://github.com/EmbarkStudios/puffin) scopes ([#1483](https://github.com/emilk/egui/pull/1483)).
1011

1112

1213
## 0.17.0 - 2022-02-22

egui-winit/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ epi_backend = ["epi", "glow"]
3636
# enable opening links in a browser when an egui hyperlink is clicked.
3737
links = ["webbrowser"]
3838

39+
# Enable profiling with the puffin crate: https://github.com/EmbarkStudios/puffin
40+
puffin = ["dep:puffin"]
41+
3942
# experimental support for a screen reader
4043
screen_reader = ["tts"]
4144

@@ -57,6 +60,7 @@ epi = { version = "0.17.0", path = "../epi", optional = true }
5760
arboard = { version = "2.1", optional = true, default-features = false }
5861
dark-light = { version = "0.2.1", optional = true }
5962
glow = { version = "0.11", optional = true }
63+
puffin = { version = "0.13", optional = true }
6064
serde = { version = "1.0", optional = true, features = ["derive"] }
6165
webbrowser = { version = "0.6", optional = true }
6266

egui-winit/src/epi.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ impl EpiIntegration {
191191
}
192192

193193
pub fn warm_up(&mut self, app: &mut dyn epi::App, window: &winit::window::Window) {
194+
crate::profile_function!();
194195
let saved_memory: egui::Memory = self.egui_ctx.memory().clone();
195196
self.egui_ctx.memory().set_everything_is_visible(true);
196197
let full_output = self.update(app, window);
@@ -230,6 +231,7 @@ impl EpiIntegration {
230231

231232
let raw_input = self.egui_winit.take_egui_input(window);
232233
let full_output = self.egui_ctx.run(raw_input, |egui_ctx| {
234+
crate::profile_scope!("App::update");
233235
app.update(egui_ctx, &mut self.frame);
234236
});
235237
self.pending_full_output.append(full_output);
@@ -274,17 +276,26 @@ impl EpiIntegration {
274276
pub fn save(&mut self, _app: &mut dyn epi::App, _window: &winit::window::Window) {
275277
#[cfg(feature = "persistence")]
276278
if let Some(storage) = self.frame.storage_mut() {
279+
crate::profile_function!();
280+
277281
if _app.persist_native_window() {
282+
crate::profile_scope!("native_window");
278283
epi::set_value(
279284
storage,
280285
STORAGE_WINDOW_KEY,
281286
&crate::WindowSettings::from_display(_window),
282287
);
283288
}
284289
if _app.persist_egui_memory() {
290+
crate::profile_scope!("egui_memory");
285291
epi::set_value(storage, STORAGE_EGUI_MEMORY_KEY, &*self.egui_ctx.memory());
286292
}
287-
_app.save(storage);
293+
{
294+
crate::profile_scope!("App::save");
295+
_app.save(storage);
296+
}
297+
298+
crate::profile_scope!("Storage::flush");
288299
storage.flush();
289300
}
290301
}

egui-winit/src/lib.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -646,3 +646,25 @@ fn translate_cursor(cursor_icon: egui::CursorIcon) -> Option<winit::window::Curs
646646
egui::CursorIcon::ZoomOut => Some(winit::window::CursorIcon::ZoomOut),
647647
}
648648
}
649+
650+
// ---------------------------------------------------------------------------
651+
652+
/// Profiling macro for feature "puffin"
653+
#[doc(hidden)]
654+
#[macro_export]
655+
macro_rules! profile_function {
656+
($($arg: tt)*) => {
657+
#[cfg(feature = "puffin")]
658+
puffin::profile_function!($($arg)*);
659+
};
660+
}
661+
662+
/// Profiling macro for feature "puffin"
663+
#[doc(hidden)]
664+
#[macro_export]
665+
macro_rules! profile_scope {
666+
($($arg: tt)*) => {
667+
#[cfg(feature = "puffin")]
668+
puffin::profile_scope!($($arg)*);
669+
};
670+
}

egui/examples/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ There are no stand-alone egui examples, because egui is not stand-alone!
22

33
There are plenty of examples in [the online demo](https://www.egui.rs/#demo). You can find the source code for it at <https://github.com/emilk/egui/tree/master/egui_demo_lib>.
44

5-
If you are using `eframe`, check out [the `eframe` examples](https://github.com/emilk/egui/tree/master/eframe/examples) and [the `eframe` template repository](https://github.com/emilk/eframe_template/).
5+
If you are using `eframe`, the [crate examples](https://github.com/emilk/egui/tree/master/examples) and [single-file examples](https://github.com/emilk/egui/tree/master/eframe/examples).
6+
To learn how to set up `eframe` for web and native, go to <https://github.com/emilk/eframe_template/> and follow the instructions there!

egui_glow/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ All notable changes to the `egui_glow` integration will be noted in this file.
99
* Fixed potential scale bug when DPI scaling changes (e.g. when dragging a window between different displays) ([#1441](https://github.com/emilk/egui/pull/1441)).
1010
* MSRV (Minimum Supported Rust Version) is now `1.60.0` ([#1467](https://github.com/emilk/egui/pull/1467)).
1111
* `clipboard`, `links`, `persistence`, `winit` are now all opt-in features ([#1467](https://github.com/emilk/egui/pull/1467)).
12+
* Added new feature `puffin` to add [`puffin profiler`](https://github.com/EmbarkStudios/puffin) scopes ([#1483](https://github.com/emilk/egui/pull/1483)).
1213

1314

1415
## 0.17.0 - 2022-02-22

egui_glow/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ persistence = [
4747
"epi?/persistence",
4848
]
4949

50+
# Enable profiling with the puffin crate: https://github.com/EmbarkStudios/puffin
51+
puffin = ["dep:puffin", "egui-winit?/puffin"]
52+
5053
# experimental support for a screen reader
5154
screen_reader = ["egui-winit?/screen_reader"]
5255

@@ -72,6 +75,7 @@ egui-winit = { version = "0.17.0", path = "../egui-winit", optional = true, defa
7275
"epi_backend",
7376
] }
7477
glutin = { version = "0.28.0", optional = true }
78+
puffin = { version = "0.13", optional = true }
7579

7680
# Web:
7781
[target.'cfg(target_arch = "wasm32")'.dependencies]

0 commit comments

Comments
 (0)