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

Improve unwind debugging #31

Merged
merged 28 commits into from
May 16, 2024
Merged

Improve unwind debugging #31

merged 28 commits into from
May 16, 2024

Conversation

gmarler
Copy link
Collaborator

@gmarler gmarler commented May 2, 2024

This improves unwind debugging to a degree:

  • implement Display trait for RawAggregatedSample

  • Implement Display trait for SymbolizedAggregatedSample

  • Since Linux PIDs are all actually threads, each folded stack should include both

    1. The process binary name (the comm field from /proc/<PGID>/stat)
    2. The thread name, defaulting to main_thread for any given PGID - eventually, for cases where all threads have the same comm, we should name the threads as <binary_name>_thread_X, where X could be abs(PGID - PID).

@gmarler gmarler requested a review from javierhonduco May 2, 2024 17:20
src/profiler.rs Outdated Show resolved Hide resolved
Copy link
Owner

@javierhonduco javierhonduco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! 🎉 Preemptively approving, I've left some small comments and nits.

As we discussed, we are going to move most of the thread name infrastructure to the metadata providers once we focus on that area. This will reduce the amount of reads from procfs.

As we don't have integration tests yet it would be super helpful if you could add some small "test plan" to the PR to show how this looks!

@@ -535,12 +593,11 @@ impl Profiler<'_> {
}

let raw_sample = RawAggregatedSample {
pid: key.task_id,
pid: key.pid,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix! We should probably pass both the pid and task_id but we can do this in another PR if you prefer!

let kstack_rep = format_symbolized_stack(&self.kstack);
let final_rep = write!(
f,
"SymbolizedAggregatedSample:\npid: {}\nustack: {}\nkstack: {}\ncount: {}",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is lovely! Some small improvement we could make here is to use the formatting facilities from fmt::Formatter, something like:

Suggested change
"SymbolizedAggregatedSample:\npid: {}\nustack: {}\nkstack: {}\ncount: {}",
f.debug_struct("SymbolizedAggregatedSample")
.field("pid", &pid)
.field("ustack", &ustack)
.finish()

src/profiler.rs Outdated Show resolved Hide resolved
let kstack_rep = format_native_stack(self.kstack);
let final_rep = write!(
f,
"RawAggregatedSample:\npid: {}\nustack: {}\nkstack: {}\ncount: {}",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as below, feel free to use the formatting helpers 😄

src/main.rs Show resolved Hide resolved
// Completely failed to look up the PID/TID in procfs
Err(_) => (
"<could not fetch proc comm>".to_string(),
"<could not fetch thread name>".to_string(),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: should we call them the same, either both name or comm?

@javierhonduco
Copy link
Owner

(oh and let's squash the commits when merging!)

@gmarler gmarler merged commit 554b7dd into javierhonduco:main May 16, 2024
4 checks passed
@javierhonduco
Copy link
Owner

Good stuff!! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants