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

Use targeted process to resolve library names #875

Merged
merged 3 commits into from
Jan 17, 2017

Conversation

pchaigno
Copy link
Contributor

@pchaigno pchaigno commented Dec 26, 2016

This pull request implements the first strategy discussed at #853 to improve the selection of libraries for attach_uprobe.

To resolve library names, bcc_procutils_which_so now leverages mapped libraries of the targeted process, if a PID is given. It uses the kernel's /proc/$pid/maps to extract mapped libraries.

Any other tests I should add?

/cc @vmg @goldshtn

@goldshtn
Copy link
Collaborator

Thanks, this looks good (haven't tested yet). Perhaps it would be good to add a test that actually verifies we're picking the right library if there are multiple options?

@pchaigno
Copy link
Contributor Author

Perhaps it would be good to add a test that actually verifies we're picking the right library if there are multiple options?

I'd like that too. Unless there's already a library (libc?) with multiple versions on all test environments, we'd need to change the environments' setup before.

@pchaigno
Copy link
Contributor Author

I just updated the pull request to fix an error.

load_mappings loads the mapped libraries of a given process in memory. When bcc_procutils_which_so is called a second time, it reads the mapped libraries directly from memory. I hadn't considered that the given PID can change, in which case we should reload mapped libraries in memory.

@goldshtn
Copy link
Collaborator

Not only can the given pid change, but even the same pid can be recycled for another process. I don't know if we want to cache the results at all, and if we do it would have to be careful caching that takes at least the process cmdline into account to try and avoid most recycling cases.

What do others think? @4ast @drzaeus77 @brendangregg @vmg

@4ast
Copy link
Member

4ast commented Jan 9, 2017

My understanding is bcc_procutils_which_so() will be called roughly once per script, so caching /proc/pid/maps doesn't help much and makes it error prone for cases when pid is recycled and libbcc is used in long running services. So I like the idea of reading /proc/pid/maps to discover specific .so of given pid, but caching is unnecessary.

@vmg
Copy link
Contributor

vmg commented Jan 10, 2017

I agree. We already have some quirky workarounds in the library to spot and prevent bugs related PID reuse (which is a real issue in busy production systems), so naively caching the output of maps based on PID sounds like a recipe for disaster. This is not performance critical code, so it should be perfectly fine to read maps on each call and skip the caching altogether.

@pchaigno pchaigno force-pushed the target-process-library branch 2 times, most recently from 873def8 to 280e118 Compare January 10, 2017 21:58
@pchaigno pchaigno force-pushed the target-process-library branch 4 times, most recently from bea043a to cfbc7e6 Compare January 14, 2017 14:38
To resolve library names, bcc_procutils_which_so leverages mapped
libraries of the targeted process, if one is given. Uses the kernel's
/proc/$pid/maps
We need the PID when detaching uprobes to resolve library names
to the same path as when attaching
@pchaigno pchaigno force-pushed the target-process-library branch 5 times, most recently from 01489fe to 6e2181a Compare January 15, 2017 11:00
@pchaigno
Copy link
Contributor Author

I updated the branch to remove the cached libraries 😇

@4ast
Copy link
Member

4ast commented Jan 16, 2017

lgtm
cc @goldshtn @vmg

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.

None yet

4 participants