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 handling of perf maps #491

Merged
merged 7 commits into from
Jan 24, 2024
Merged

Support handling of perf maps #491

merged 7 commits into from
Jan 24, 2024

Conversation

danielocfb
Copy link
Collaborator

@danielocfb danielocfb commented Jan 19, 2024

Support handling of perf maps. Please see individual commits for descriptions.

A lot of our helper functionality works with PathMapsEntry objects, when
really all they need would be an EntryPath.
With this change we switch this functionality over to just requiring the
latter.

Signed-off-by: Daniel Müller <deso@posteo.net>
With an upcoming change we need to support /proc/<pid>/maps entries
without a path. We can already parse them, of course, but we ultimately
represent each entry as a PathMapsEntry object, which unconditionally
contains a path.
With this patch we remove this type and adjust the existing code to just
work with MapsEntry objects directly.

Signed-off-by: Daniel Müller <deso@posteo.net>
With an upcoming change we will need to be able to "resolve" the
symbolic process ID Pid::Slf to the actual number. This change adds a
helper method, Pid::resolve(), that accomplishes this feat.

Signed-off-by: Daniel Müller <deso@posteo.net>
This change introduces the PerfMap type, which can be used for working
with perf map files. These files enable generic profilers and
symbolization tools to gain insight into just-in-time compiled
languages, as long as their runtimes generate such a file. In Python,
for example, that is supported since version 3.12 and controlled, among
other things, by the value of the PYTHONPERFSUPPORT environment
variable.
Put in place is only the core infrastructure. Additional plumbings is
necessary to use it.

[0] https://docs.python.org/3/howto/perf_profiling.html

Signed-off-by: Daniel Müller <deso@posteo.net>
This change enables the usage of perf maps in the library when
using process based symbolization. When an address is not present in
/proc/<pid>/maps entry with a path, we attempt to parse a perf map file
expected at /tmp/perf-<pid>.map and use it to symbolize the address.
This functionality is not explicitly exposed as a separate symbolization
source. As such, user as well as blazecli will transparently make use of
it.

  $ cargo run -p blazecli -- symbolize process --pid 3477613 0x7fbf1fc2175c
  > 0x007fbf1fc2175c: py::_read_directory:<frozen zipimport> @ 0x7fbf1fc21759+0x3

Closes: #256

Signed-off-by: Daniel Müller <deso@posteo.net>
Copy link

codecov bot commented Jan 19, 2024

Codecov Report

Attention: 13 lines in your changes are missing coverage. Please review.

Comparison is base (ee2a2ce) 93.20% compared to head (abf9c9e) 93.37%.

Files Patch % Lines
src/symbolize/symbolizer.rs 89.65% 6 Missing ⚠️
src/symbolize/perf_map.rs 98.77% 3 Missing ⚠️
src/normalize/user.rs 92.85% 2 Missing ⚠️
src/mmap.rs 97.61% 1 Missing ⚠️
src/symbolize/mod.rs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #491      +/-   ##
==========================================
+ Coverage   93.20%   93.37%   +0.17%     
==========================================
  Files          45       46       +1     
  Lines        7710     8030     +320     
==========================================
+ Hits         7186     7498     +312     
- Misses        524      532       +8     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@danielocfb danielocfb marked this pull request as draft January 20, 2024 00:04
@d-e-s-o
Copy link
Collaborator

d-e-s-o commented Jan 22, 2024

I wanted to add an end-to-end test...and I did...it's just that I can't get it working in CI because the Python there doesn't come built with the necessary feature, which is very sad.

Mmap'ing zero sized files is not allowed by the kernel (cf. mmap(2)).
However, we do not want to special-case every client of the Mmap type to
take care of that. If a file is empty we can just fake its contents via
an empty slice.
This change adjusts the Mmap type to special case zero size files
internally.

Signed-off-by: Daniel Müller <deso@posteo.net>
@d-e-s-o
Copy link
Collaborator

d-e-s-o commented Jan 22, 2024

I wanted to add an end-to-end test...and I did...it's just that I can't get it working in CI because the Python there doesn't come built with the necessary feature, which is very sad.

Okay, so that was some environment SNAFU. Got it working now.

This change adds an end-to-end tests for the symbolization of addresses
of JITed code. Specifically, we spin up a Python instance, instruct it
to create a perf map, and then make sure that we can symbolize an
address from said map. We also test working against an empty perf map
file.

Signed-off-by: Daniel Müller <deso@posteo.net>
@d-e-s-o d-e-s-o changed the title Topic/perf maps Support handling of perf maps Jan 22, 2024
@d-e-s-o d-e-s-o marked this pull request as ready for review January 22, 2024 20:14
@d-e-s-o d-e-s-o linked an issue Jan 22, 2024 that may be closed by this pull request
@d-e-s-o d-e-s-o requested a review from anakryiko January 22, 2024 20:19
@d-e-s-o
Copy link
Collaborator

d-e-s-o commented Jan 22, 2024

Can you please take a look at the changes when you get a chance, @anakryiko?

Copy link
Member

@anakryiko anakryiko left a comment

Choose a reason for hiding this comment

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

LGTM, one API question, the rest is just language questions

@d-e-s-o d-e-s-o merged commit 10748f1 into libbpf:main Jan 24, 2024
31 checks passed
@d-e-s-o d-e-s-o deleted the topic/perf-maps branch January 24, 2024 17:31
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.

Use /tmp/perf-[pid].map
3 participants