Skip to content

Commit

Permalink
Remove register_user_scopes from profile collection
Browse files Browse the repository at this point in the history
Because scope collection is more of a data structure that users might use them selves. And allocating id's is more of a puffin specific thing. This was feedback from Traverse.
  • Loading branch information
TimonPost committed Jan 8, 2024
1 parent 7687e37 commit 9a9d387
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 26 deletions.
9 changes: 8 additions & 1 deletion puffin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,14 @@ impl GlobalProfiler {
/// This function is relevant when you're registering measurement not performed using the puffin profiler macros.
/// Scope id is always supposed to be `None` as it will be set by puffin.
pub fn register_user_scopes(&mut self, scopes: &[ScopeDetails]) -> Vec<ScopeId> {
let new_scopes = self.scope_collection.register_user_scopes(scopes);
let mut new_scopes = Vec::with_capacity(scopes.len());
for scope_detail in scopes {
let new_scope_id = fetch_add_scope_id();
let scope = self.scope_collection.insert(Arc::new(
(*scope_detail).clone().with_scope_id(new_scope_id),
));
new_scopes.push(scope);
}
let new_scope_ids = new_scopes.iter().filter_map(|x| x.scope_id).collect();
self.new_scopes.extend(new_scopes);
new_scope_ids
Expand Down
9 changes: 1 addition & 8 deletions puffin/src/profile_view.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::sync::{Arc, Mutex};

use crate::{FrameData, FrameSinkId, ScopeCollection, ScopeDetails};
use crate::{FrameData, FrameSinkId, ScopeCollection};

/// A view of recent and slowest frames, used by GUIs.
#[derive(Clone)]
Expand Down Expand Up @@ -44,13 +44,6 @@ impl FrameView {
&self.scope_collection
}

/// Insert user scopes into puffin.
/// Scopes details should only be registered once for each scope and need be inserted before being reported to puffin.
/// This function should only be relevant when your not using puffin through the profiler macros.
pub fn register_user_scopes(&mut self, scopes: &[ScopeDetails]) {
self.scope_collection.register_user_scopes(scopes);
}

pub fn add_frame(&mut self, new_frame: Arc<FrameData>) {
// Register all scopes from the new frame into the scope collection.
for new_scope in &new_frame.scope_delta {
Expand Down
18 changes: 1 addition & 17 deletions puffin/src/scope_details.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{clean_function_name, fetch_add_scope_id, short_file_name, ScopeId};
use crate::{clean_function_name, short_file_name, ScopeId};
use std::{borrow::Cow, collections::HashMap, sync::Arc};

#[derive(Default, Clone)]
Expand Down Expand Up @@ -43,22 +43,6 @@ impl ScopeCollection {
.clone()
}

/// Manually register scope details. After a scope is inserted it can be reported to puffin.
pub(crate) fn register_user_scopes(
&mut self,
scopes: &[ScopeDetails],
) -> Vec<Arc<ScopeDetails>> {
let mut new_scopes = Vec::with_capacity(scopes.len());
for scope_detail in scopes {
let new_scope_id = fetch_add_scope_id();
let scope = self.insert(Arc::new(
(*scope_detail).clone().with_scope_id(new_scope_id),
));
new_scopes.push(scope);
}
new_scopes
}

/// Fetches all registered scopes and their ids.
/// Useful for fetching scope id by it's scope name.
/// For profiler scopes and user scopes this is the manual provided name.
Expand Down

0 comments on commit 9a9d387

Please sign in to comment.