From 7c4ad6d1fdde1d75eacc1aa8d9bbf837d3de463c Mon Sep 17 00:00:00 2001 From: Markus Stange Date: Thu, 7 Mar 2024 16:19:08 -0500 Subject: [PATCH] Only recycle threads when --reuse-threads is specified. This fixes unintended behavior - we were always combining non-overlapping threads with the same name inside the same process into one thread. We only want to do that if --reuse-threads is specified. --- samply/src/linux_shared/processes.rs | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/samply/src/linux_shared/processes.rs b/samply/src/linux_shared/processes.rs index 28d4b816..56c25335 100644 --- a/samply/src/linux_shared/processes.rs +++ b/samply/src/linux_shared/processes.rs @@ -86,13 +86,21 @@ where if let Some(name) = name.as_deref() { profile.set_thread_name(main_thread_handle, name); } + let (thread_recycler, jit_function_recycler) = if self.process_recycler.is_some() { + ( + Some(ThreadRecycler::new()), + Some(JitFunctionRecycler::default()), + ) + } else { + (None, None) + }; let process = Process::new( pid, process_handle, main_thread_handle, name, - Some(ThreadRecycler::new()), - Some(JitFunctionRecycler::default()), + thread_recycler, + jit_function_recycler, ); entry.insert(process) } @@ -107,13 +115,21 @@ where profile.add_process(&format!("<{pid}>"), pid as u32, fake_start_time); let main_thread_handle = profile.add_thread(process_handle, pid as u32, fake_start_time, true); + let (thread_recycler, jit_function_recycler) = if self.process_recycler.is_some() { + ( + Some(ThreadRecycler::new()), + Some(JitFunctionRecycler::default()), + ) + } else { + (None, None) + }; Process::new( pid, process_handle, main_thread_handle, - None, - Some(ThreadRecycler::new()), - Some(JitFunctionRecycler::default()), + None, // no name + thread_recycler, + jit_function_recycler, ) }) }