Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support marker file paths with thread ID #143

Merged
merged 3 commits into from
Apr 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions samply/src/mac/task_profiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ use crate::shared::jitdump_manager::JitDumpManager;
use crate::shared::lib_mappings::{
LibMappingAdd, LibMappingInfo, LibMappingOp, LibMappingOpQueue, LibMappingRemove,
};
use crate::shared::marker_file;
use crate::shared::marker_file::get_markers;
use crate::shared::perf_map::try_load_perf_map;
use crate::shared::process_sample_data::{MarkerSpanOnThread, ProcessSampleData};
Expand Down Expand Up @@ -533,10 +534,19 @@ impl TaskProfiler {
);
}
JitdumpOrMarkerPath::MarkerFilePath(marker_file_path) => {
// TODO: Detect which thread the marker file is opened on, and use that thread's
// thread handle so that the markers are put on that thread in the profile.
// count the number of - characters in marker_file_path
let marker_info = marker_file::parse_marker_file_path(&marker_file_path);
let thread_handle = if marker_info.tid.is_some() {
self.live_threads
.iter()
.find(|(_, thread)| thread.tid == marker_info.tid.unwrap())
.map(|(_, thread)| thread.profile_thread)
.unwrap_or(self.main_thread_handle)
} else {
self.main_thread_handle
};
self.marker_file_paths
.push((self.main_thread_handle, marker_file_path));
.push((thread_handle, marker_file_path));
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions samply/src/mac/thread_profiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ use super::thread_info::{
pub struct ThreadProfiler {
thread_act: thread_act_t,
name: Option<String>,
tid: u32,
profile_thread: ThreadHandle,
pub(crate) tid: u32,
pub(crate) profile_thread: ThreadHandle,
tick_count: usize,
stack_memory: ForeignMemory,
previous_sample_cpu_time_us: u64,
Expand Down
18 changes: 18 additions & 0 deletions samply/src/shared/marker_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,24 @@ impl Iterator for MarkerFile {
}
}

pub struct MarkerFileInfo {
pub prefix: String,
pub pid: u32,
pub tid: Option<u32>,
}

#[allow(unused)]
pub fn parse_marker_file_path(path: &Path) -> MarkerFileInfo {
let filename = path.file_name().unwrap().to_str().unwrap();
// strip .txt extension
let filename = &filename[..filename.len() - 4];
let mut parts = filename.splitn(3, '-');
let prefix = parts.next().unwrap().to_owned();
let pid = parts.next().unwrap().parse().unwrap();
let tid = parts.next().map(|tid| tid.parse().unwrap());
MarkerFileInfo { prefix, pid, tid }
}

pub fn get_markers(
marker_file: &Path,
extra_dir: Option<&Path>,
Expand Down
Loading