From 9a9d3878215c5dec770759df43901da56bf15b7f Mon Sep 17 00:00:00 2001 From: Timon Date: Mon, 8 Jan 2024 10:19:57 +0100 Subject: [PATCH] Remove `register_user_scopes` from profile collection 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. --- puffin/src/lib.rs | 9 ++++++++- puffin/src/profile_view.rs | 9 +-------- puffin/src/scope_details.rs | 18 +----------------- 3 files changed, 10 insertions(+), 26 deletions(-) diff --git a/puffin/src/lib.rs b/puffin/src/lib.rs index 9fa62aba..fba67d35 100644 --- a/puffin/src/lib.rs +++ b/puffin/src/lib.rs @@ -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 { - 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 diff --git a/puffin/src/profile_view.rs b/puffin/src/profile_view.rs index a97aa38c..ba912e1f 100644 --- a/puffin/src/profile_view.rs +++ b/puffin/src/profile_view.rs @@ -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)] @@ -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) { // Register all scopes from the new frame into the scope collection. for new_scope in &new_frame.scope_delta { diff --git a/puffin/src/scope_details.rs b/puffin/src/scope_details.rs index 2ed31ed3..42ebb13d 100644 --- a/puffin/src/scope_details.rs +++ b/puffin/src/scope_details.rs @@ -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)] @@ -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> { - 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.