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

Remove ::{{closure}} in more cases from function names #230

Merged
merged 6 commits into from
Aug 6, 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
5 changes: 4 additions & 1 deletion puffin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,13 @@ macro_rules! current_function_name {
}};
}

/// Automatically name the profiling scope based on function name.
/// Automatically name the profiling scope based on the function name.
///
/// Names should be descriptive, ASCII and without spaces.
///
/// [`profile_function`] should only be used for the outermost scope of a function
/// and not for lambdas. For other use-cases please use [`profile_scope`]
///
/// Example:
/// ```
/// # struct Image {};
Expand Down
8 changes: 5 additions & 3 deletions puffin/src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// The macro defines 'f()' at the place where macro is called.
// This code is located at the place of call and two closures deep.
// This code is typically located at the place of call and two closures deep.
// Strip away this useless suffix.
pub(crate) const USELESS_SCOPE_NAME_SUFFIX: &str = "::{{closure}}::{{closure}}::f";
pub(crate) const USELESS_SCOPE_NAME_SUFFIX: &str = "::f";
pub(crate) const USELESS_CLOSURE_SUFFIX: &str = "::{{closure}}";

#[doc(hidden)]
#[inline(never)]
Expand All @@ -10,7 +11,8 @@ pub fn clean_function_name(name: &str) -> String {
// Probably the user registered a user scope name.
return name.to_owned();
};
shorten_rust_function_name(name)
// Remove any additional trailing suffixes
shorten_rust_function_name(name.trim_end_matches(USELESS_CLOSURE_SUFFIX))
}

/// Shorten a rust function name by removing the leading parts of module paths.
Expand Down
Loading