Skip to content

Commit

Permalink
Remove ::{{closure}} in more cases from function names (#230)
Browse files Browse the repository at this point in the history
### Checklist

* [x] I have read the [Contributor Guide](../CONTRIBUTING.md)
* [x] I have read and agree to the [Code of
Conduct](../CODE_OF_CONDUCT.md)
* [x] I have added a description of my changes and why I'd like them
included in the section below

### Description of Changes

This removes all `::{{closure}}` from the suffix of a function name when
cleaning the name. Previously this was limited to 2.

This is noticeable with the changes made in #225 where the `main
function` being labeled as `main::{{closure}}`

### Before

![image](https://github.com/user-attachments/assets/a484973e-088e-48cc-bef8-589db8b9bfd4)

### After 
![Screenshot 2024-08-05
131903](https://github.com/user-attachments/assets/84830f94-9d2b-4249-9295-e7d4896ad958)
  • Loading branch information
Hoodad authored Aug 6, 2024
1 parent cfc52c0 commit 3e569df
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
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

0 comments on commit 3e569df

Please sign in to comment.