Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve the puffin_viewer UI #228

Merged
merged 20 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
**/*.rs.bk
**/target_ra/
**/target/
/*.puffin
35 changes: 35 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ edition = "2021"
license = "MIT OR Apache-2.0"
rust-version = "1.76"


[profile.dev.package."*"]
# Optimize all dependencies even in debug builds (does not affect workspace packages):
opt-level = 2


[workspace.lints.rust]
elided_lifetimes_in_paths = "warn"
future_incompatible = "warn"
Expand Down
54 changes: 1 addition & 53 deletions puffin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,59 +392,7 @@ macro_rules! profile_scope_if {
mod tests {
use std::borrow::Cow;

use crate::{
clean_function_name, set_scopes_on, short_file_name, utils::USELESS_SCOPE_NAME_SUFFIX,
GlobalFrameView, GlobalProfiler, ScopeId,
};

#[test]
fn test_short_file_name() {
for (before, after) in [
("", ""),
("foo.rs", "foo.rs"),
("foo/bar.rs", "foo/bar.rs"),
("foo/bar/baz.rs", "bar/baz.rs"),
("crates/cratename/src/main.rs", "cratename/src/main.rs"),
("crates/cratename/src/module/lib.rs", "cratename/…/module/lib.rs"),
("workspace/cratename/examples/hello_world.rs", "examples/hello_world.rs"),
("/rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/core/src/ops/function.rs", "core/…/function.rs"),
("/Users/emilk/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.24.1/src/runtime/runtime.rs", "tokio-1.24.1/…/runtime.rs"),
]
{
assert_eq!(short_file_name(before), after);
}
}

#[test]
fn test_clean_function_name() {
assert_eq!(clean_function_name(""), "");
assert_eq!(
clean_function_name(&format!("foo{}", USELESS_SCOPE_NAME_SUFFIX)),
"foo"
);
assert_eq!(
clean_function_name(&format!("foo::bar{}", USELESS_SCOPE_NAME_SUFFIX)),
"foo::bar"
);
assert_eq!(
clean_function_name(&format!("foo::bar::baz{}", USELESS_SCOPE_NAME_SUFFIX)),
"bar::baz"
);
assert_eq!(
clean_function_name(&format!(
"some::GenericThing<_, _>::function_name{}",
USELESS_SCOPE_NAME_SUFFIX
)),
"GenericThing<_, _>::function_name"
);
assert_eq!(
clean_function_name(&format!(
"<some::ConcreteType as some::bloody::Trait>::function_name{}",
USELESS_SCOPE_NAME_SUFFIX
)),
"<ConcreteType as Trait>::function_name"
);
}
use crate::{set_scopes_on, GlobalFrameView, GlobalProfiler, ScopeId};

#[test]
fn profile_macros_test() {
Expand Down
2 changes: 1 addition & 1 deletion puffin/src/profile_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub struct FrameView {

impl Default for FrameView {
fn default() -> Self {
let max_recent = 60 * 60 * 5;
let max_recent = 1_000;
let max_slow = 256;

Self {
Expand Down
4 changes: 4 additions & 0 deletions puffin/src/scope_details.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,18 @@ pub struct ScopeDetails {
/// Always initialized once registered.
/// It is `None` when an external library has yet to register this scope.
pub(crate) scope_id: Option<ScopeId>,

/// A name for a profile scope, a function profile scope does not have a custom provided name.
pub scope_name: Option<Cow<'static, str>>,

/// The function name of the function in which this scope is contained.
/// The name might be slightly modified to represent a short descriptive representation.
pub function_name: Cow<'static, str>,

/// The file path in which this scope is contained.
/// The path might be slightly modified to represent a short descriptive representation.
pub file_path: Cow<'static, str>,

/// The exact line number at which this scope is located.
pub line_nr: u32,
}
Expand Down
49 changes: 49 additions & 0 deletions puffin/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,52 @@ pub fn short_file_name(path: &str) -> String {
pub fn type_name_of<T>(_: T) -> &'static str {
std::any::type_name::<T>()
}

#[test]
fn test_short_file_name() {
for (before, after) in [
("", ""),
("foo.rs", "foo.rs"),
("foo/bar.rs", "foo/bar.rs"),
("foo/bar/baz.rs", "bar/baz.rs"),
("crates/cratename/src/main.rs", "cratename/src/main.rs"),
("crates/cratename/src/module/lib.rs", "cratename/…/module/lib.rs"),
("workspace/cratename/examples/hello_world.rs", "examples/hello_world.rs"),
("/rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/core/src/ops/function.rs", "core/…/function.rs"),
("/Users/emilk/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.24.1/src/runtime/runtime.rs", "tokio-1.24.1/…/runtime.rs"),
]
{
assert_eq!(short_file_name(before), after);
}
}

#[test]
fn test_clean_function_name() {
assert_eq!(clean_function_name(""), "");
assert_eq!(
clean_function_name(&format!("foo{}", USELESS_SCOPE_NAME_SUFFIX)),
"foo"
);
assert_eq!(
clean_function_name(&format!("foo::bar{}", USELESS_SCOPE_NAME_SUFFIX)),
"foo::bar"
);
assert_eq!(
clean_function_name(&format!("foo::bar::baz{}", USELESS_SCOPE_NAME_SUFFIX)),
"bar::baz"
);
assert_eq!(
clean_function_name(&format!(
"some::GenericThing<_, _>::function_name{}",
USELESS_SCOPE_NAME_SUFFIX
)),
"GenericThing<_, _>::function_name"
);
assert_eq!(
clean_function_name(&format!(
"<some::ConcreteType as some::bloody::Trait>::function_name{}",
USELESS_SCOPE_NAME_SUFFIX
)),
"<ConcreteType as Trait>::function_name"
);
}
2 changes: 2 additions & 0 deletions puffin_egui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ include = [

[dependencies]
egui = { version = "0.28.0", default-features = false }
egui_extras = { version = "0.28.0", default-features = false, features = ["serde"] }
indexmap = { version = "2.1.0", features = ["serde"] }
natord = "1.0.9"
once_cell = "1.7"
Expand All @@ -40,4 +41,5 @@ web-time = "0.2"
eframe = { version = "0.28.0", default-features = false, features = [
"default_fonts",
"glow",
"persistence",
] }
6 changes: 4 additions & 2 deletions puffin_egui/examples/eframe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ use eframe::egui;

fn main() -> eframe::Result<()> {
let mut frame_counter = 0;
let mut keep_repainting = false;
let mut keep_repainting = true;

puffin::set_scopes_on(true);

let options = eframe::NativeOptions {
viewport: egui::ViewportBuilder::default().with_inner_size([320.0, 240.0]),
Expand Down Expand Up @@ -43,7 +45,7 @@ fn main() -> eframe::Result<()> {
})
.unwrap();

sleep_ms(14);
sleep_ms(9);
if frame_counter % 49 == 0 {
puffin::profile_scope!("Spike");
std::thread::sleep(std::time::Duration::from_millis(20))
Expand Down
6 changes: 4 additions & 2 deletions puffin_egui/src/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ pub struct Filter {
impl Filter {
pub fn ui(&mut self, ui: &mut egui::Ui) {
ui.horizontal(|ui| {
ui.label("Scope filter:");
ui.text_edit_singleline(&mut self.filter);
ui.spacing_mut().item_spacing.x = 4.0;

ui.add(egui::TextEdit::singleline(&mut self.filter).hint_text("Scope filter"));
self.filter = self.filter.to_lowercase();

if ui.button("x").clicked() {
self.filter.clear();
}
Expand Down
Loading
Loading