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

Do not panic on frame id 0 as it's valid #66

Merged
merged 1 commit into from
Feb 22, 2023
Merged
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
26 changes: 11 additions & 15 deletions src/rbperf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,22 +385,22 @@ impl<'a> Rbperf<'a> {
loop {
let read = recv.lock().unwrap().try_recv();
match read {
Ok(data) => {
Ok(recv_stack) => {
let mut read_frame_count = 0;
self.stats.total_events += 1;

if data.stack_status == ruby_stack_status_STACK_INCOMPLETE {
if recv_stack.stack_status == ruby_stack_status_STACK_INCOMPLETE {
// TODO: allow users to decide wether to discard incomplete stacks
debug!("incomplete stack");
self.stats.incomplete_stack_errors += 1;
continue;
}

if data.pid == 0 {
if recv_stack.pid == 0 {
panic!("pid is zero, this should never happen");
}

let comm_bytes: Vec<u8> = data.comm.iter().map(|&c| c as u8).collect();
let comm_bytes: Vec<u8> = recv_stack.comm.iter().map(|&c| c as u8).collect();
let comm = unsafe { str_from_u8_nul(&comm_bytes) };
if comm.is_err() {
self.stats.garbled_data_errors += 1;
Expand All @@ -409,13 +409,10 @@ impl<'a> Rbperf<'a> {
let comm = comm.expect("comm should be valid unicode").to_string();
let mut frames: Vec<(String, String, Option<u32>)> = Vec::new();

for frame_idx in &data.frames {
for frame_idx in &recv_stack.frames {
// Don't read past the last frame
if read_frame_count >= data.size {
continue;
}
if *frame_idx == 0 {
panic!("Frame id is zero, this should never happen");
if read_frame_count >= recv_stack.size {
break;
}

let frame_bytes =
Expand Down Expand Up @@ -461,26 +458,25 @@ impl<'a> Rbperf<'a> {
None
};
frames.push((method_name, path_name, lineno));

read_frame_count += 1;
}

// Add generated frames
if let RbperfEvent::Syscall(_) = self.event {
let syscall_number = syscalls::Sysno::from(data.syscall_id);
let syscall_number = syscalls::Sysno::from(recv_stack.syscall_id);
frames.push((
format!("{syscall_number}").to_string(),
"<syscall>".to_string(),
None,
));
}

if data.size == read_frame_count {
profile.add_sample(data.pid as Pid, comm, frames);
if recv_stack.size == read_frame_count {
profile.add_sample(recv_stack.pid as Pid, comm, frames);
} else {
error!(
"mismatched expected={} and received={} frame count",
data.size, read_frame_count
recv_stack.size, read_frame_count
);
}
}
Expand Down