-
Notifications
You must be signed in to change notification settings - Fork 12
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
Add extra checks to select the right mapping and filter samples within it. #266
Open
virajbshah
wants to merge
3
commits into
google:main
Choose a base branch
from
virajbshah:annotating-importer-sample-checks
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -73,17 +73,26 @@ absl::StatusOr<const quipper::PerfDataProto *> AnnotatingImporter::LoadPerfData( | |
return &perf_reader_.proto(); | ||
} | ||
|
||
namespace { | ||
|
||
std::string GetFileNameFromPath(const std::string &path) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: This is usually called "Basename" in the unix world. |
||
int idx = path.find_last_of('/'); | ||
if (idx == std::string::npos) { | ||
return path; | ||
} | ||
return path.substr(idx + 1); | ||
} | ||
|
||
} // namespace | ||
|
||
absl::StatusOr<const quipper::PerfDataProto_MMapEvent *> | ||
AnnotatingImporter::GetMainMapping( | ||
const llvm::object::ELFObjectFileBase *elf_object, | ||
const quipper::PerfDataProto *perf_data) { | ||
// Find the relevant mapping. | ||
// TODO(virajbshah): Make sure the mapping was found. (Use num_mmap_events) | ||
std::string file_name = GetFileNameFromPath(elf_object->getFileName().str()); | ||
for (const auto &event : perf_data->events()) { | ||
// TODO(virajbshah): Not sure if this always works, i.e. does the main | ||
// binary always correspond to the first MMapEvent. Implement BuildID or | ||
// name based checking. | ||
if (event.has_mmap_event() && | ||
GetFileNameFromPath(event.mmap_event().filename()) == file_name && | ||
event.mmap_event().prot() & 0b001 /* PROT_READ */ && | ||
event.mmap_event().prot() & 0b100 /* PROT_EXEC */) { | ||
return &event.mmap_event(); | ||
|
@@ -199,8 +208,8 @@ AnnotatingImporter::GetBlocksFromELF( | |
for (const llvm::object::BBAddrMap::BBRangeEntry &bb_range : | ||
map.getBBRanges()) { | ||
for (const llvm::object::BBAddrMap::BBEntry &bb : bb_range.BBEntries) { | ||
uint64_t begin_idx = function_addr + bb.Offset, | ||
end_idx = begin_idx + bb.Size; | ||
uint64_t begin_idx = function_addr + bb.Offset; | ||
uint64_t end_idx = begin_idx + bb.Size; | ||
if (begin_idx == end_idx) { | ||
continue; // Skip any empty basic blocks. | ||
} | ||
|
@@ -258,6 +267,9 @@ AnnotatingImporter::GetSamples( | |
} | ||
|
||
// Filter out sample events from outside the profiled binary. | ||
if (!event.sample_event().has_pid() || | ||
!(event.sample_event().pid() == mapping->pid())) | ||
continue; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Very nit: Please put braces around this statement, for consistency with the rest of the code. |
||
uint64_t sample_ip = event.sample_event().ip(); | ||
if (sample_ip < mmap_begin_addr || sample_ip >= mmap_end_addr) continue; | ||
|
||
|
@@ -320,6 +332,13 @@ AnnotatingImporter::GetLBRBlocksWithLatency( | |
!event.sample_event().branch_stack_size()) { | ||
continue; | ||
} | ||
|
||
// Check if the sample PID matches that of the relevant mapping. | ||
if (!event.sample_event().has_pid() || | ||
!(event.sample_event().pid() == mapping->pid())) { | ||
continue; | ||
} | ||
|
||
const auto &branch_stack = event.sample_event().branch_stack(); | ||
for (int branch_idx = branch_stack.size() - 2; branch_idx >= 0; | ||
--branch_idx) { | ||
|
@@ -336,9 +355,6 @@ AnnotatingImporter::GetLBRBlocksWithLatency( | |
|
||
// Remove blocks not belonging to the binary we are importing from. | ||
if (block_begin < mmap_begin_addr || mmap_end_addr < block_end) continue; | ||
if (block_begin < main_header->p_offset || | ||
main_header->p_offset + main_header->p_filesz < block_end) | ||
continue; | ||
|
||
uint32_t block_latency = next_branch_entry.cycles(); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could work with
llvm::StringRef
and save some copying. This would also save thellvm::StringRef
->std::string
conversion on line 92.