Skip to content

Commit ae97072

Browse files
authored
Clean function and shorten file names only in macros (#182)
### 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 Clean the function names and shorten the file paths from the `::{{closure}}::{{closure}}::f` suffix directly in the `profile_function!` and `profile_scope!` macros when registering the scope (in the `OnceLock::get_or_init` closure). Motivation: Avoid making assumptions about the format of the function names and file paths, for those who are using puffin directly as a general profiling tool (not going through `profile_function!` and `profile_scope!` macros).
1 parent e076333 commit ae97072

File tree

3 files changed

+7
-25
lines changed

3 files changed

+7
-25
lines changed

puffin/src/global_profiler.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,8 @@ impl GlobalProfiler {
135135
) {
136136
if !scope_details.is_empty() {
137137
// Here we can run slightly heavy logic as its only ran once for each scope.
138-
self.new_scopes.extend(
139-
scope_details
140-
.iter()
141-
.map(|x| Arc::new(x.clone().into_readable().clone())),
142-
);
138+
self.new_scopes
139+
.extend(scope_details.iter().map(|x| Arc::new(x.clone())));
143140
}
144141

145142
self.current_frame

puffin/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,8 @@ macro_rules! profile_function {
216216
let scope_id = SCOPE_ID.get_or_init(|| {
217217
$crate::ThreadProfiler::call(|tp| {
218218
let id = tp.register_function_scope(
219-
$crate::current_function_name!(),
220-
file!(),
219+
$crate::clean_function_name($crate::current_function_name!()),
220+
$crate::short_file_name(file!()),
221221
line!(),
222222
);
223223
id
@@ -254,8 +254,8 @@ macro_rules! profile_scope {
254254
$crate::ThreadProfiler::call(|tp| {
255255
let id = tp.register_named_scope(
256256
$name,
257-
$crate::current_function_name!(),
258-
file!(),
257+
$crate::clean_function_name($crate::current_function_name!()),
258+
$crate::short_file_name(file!()),
259259
line!(),
260260
);
261261
id

puffin/src/scope_details.rs

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::{clean_function_name, short_file_name, ScopeId};
1+
use crate::ScopeId;
22
use std::{borrow::Cow, collections::HashMap, sync::Arc};
33

44
#[derive(Default, Clone)]
@@ -186,21 +186,6 @@ impl ScopeDetails {
186186
}
187187
}
188188

189-
/// Turns the scope details into a more readable version:
190-
///
191-
/// * Consistent / shortened file path across platforms
192-
/// * Consistent / shortened function name
193-
#[inline]
194-
pub(crate) fn into_readable(self) -> Self {
195-
Self {
196-
scope_id: self.scope_id,
197-
scope_name: self.scope_name,
198-
function_name: clean_function_name(&self.function_name).into(),
199-
file_path: short_file_name(&self.file_path).into(),
200-
line_nr: self.line_nr,
201-
}
202-
}
203-
204189
// This function should not be exposed as only puffin should allocate ids.
205190
#[inline]
206191
pub(crate) fn with_scope_id(mut self, scope_id: ScopeId) -> Self {

0 commit comments

Comments
 (0)