Skip to content

Add extra checks to select the right mapping and filter samples within it. #266

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

Merged
merged 7 commits into from
Feb 17, 2025

Conversation

virajbshah
Copy link
Collaborator

  • Add a binary name check while identifying the main mapping.
  • A new check of the sample PID against the main mapping PID.
  • Remove the check for whether the block's code was within the bounds
    of the executable segment in terms of file addresses, this is
    redundant as long as the mapping is valid.

 * Pass pointers to the perf profile proto and the main memory mapping
   instead of storing them as class members.
 * The `PerfParser` also does not need to be held on to - it is used
   only once.
 * The `PerfReader` must be held on to since it owns all of the perf
   related data.
@virajbshah virajbshah requested a review from ondrasej January 19, 2025 22:34
Comment on lines 52 to 55
// Memory mapping protection flag bits on Linux, from `sys/mman.h`.
constexpr int kProtRead = 0b001; /* PROT_READ */
constexpr int kProtWrite = 0b010; /* PROT_WRITE */
constexpr int kProtExec = 0b100; /* PROT_EXEC */
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we use PROT_READ, PROT_WRITE, and PROT_EXEC directly in our code?

Normally, they should be provided by sys/mman.h - and if they are, I'd go for the system definitions rather than define our own.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

They are indeed provided by sys/mman.h, but I opted to define them here with the comment pointing to sys/mman.h so that it doesn't stop this from being built on Windows. I could use a __has_include(<sys/mman.h>) with a preprocessor macro at the top to use sys/mman.h whenever possible and just define PROT_{READ,WRITE,EXEC} otherwise. Or would simply dropping Windows compatibility make more sense?

Copy link
Collaborator

Choose a reason for hiding this comment

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

We already have a Linux-only (POSIX maybe) dependency with finding accessed addresses, so I'm not too worried about that.

But we could do the __has_include check and include it if defined, otherwise take our own definitions.

…bject.

 * A new check of the sample PID against the main mapping PID.
 * Remove the check for whether the block's code was within the bounds
   of the executable segment in terms of file addresses, this is
   redundant as long as the mapping is valid.
@virajbshah virajbshah force-pushed the annotating-importer-sample-checks branch from be2c757 to 93b3cdf Compare February 8, 2025 11:31
@virajbshah virajbshah merged commit ee89d1a into google:main Feb 17, 2025
6 of 7 checks passed
@virajbshah virajbshah deleted the annotating-importer-sample-checks branch February 17, 2025 18:30
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