[cpu-profiler] Ignore repeat source positions in the CPU profiler

We can get repeated positions from optimized code objects in some cases
but for our purposes of looking up a line number from a PC, we can only
return one line number so just use the first one that is reported in
the source position table on the code object.

Change-Id: I4c0e866fb1948f65bf6c988d992ef55f520dd874
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1724375
Reviewed-by: Alexei Filippov <alph@chromium.org>
Commit-Queue: Peter Marshall <petermarshall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#62972}
This commit is contained in:
Peter Marshall 2019-07-29 14:45:30 +02:00 committed by Commit Bot
parent 92ad6fcb2a
commit 2e74bec6a0
2 changed files with 17 additions and 0 deletions

View File

@ -19,6 +19,14 @@ void SourcePositionTable::SetPosition(int pc_offset, int line,
int inlining_id) {
DCHECK_GE(pc_offset, 0);
DCHECK_GT(line, 0); // The 1-based number of the source line.
// It's possible that we map multiple source positions to a pc_offset in
// optimized code. Usually these map to the same line, so there is no
// difference here as we only store line number and not line/col in the form
// of a script offset. Ignore any subsequent sets to the same offset.
if (!pc_offsets_to_lines_.empty() &&
pc_offsets_to_lines_.back().pc_offset == pc_offset) {
return;
}
// Check that we are inserting in ascending order, so that the vector remains
// sorted.
DCHECK(pc_offsets_to_lines_.empty() ||

View File

@ -2942,6 +2942,15 @@ TEST(SourcePositionTable) {
CHECK_EQ(SourcePosition::kNotInlined, info.GetInliningId(21));
CHECK_EQ(0, info.GetInliningId(100));
// Test that subsequent SetPosition calls with the same pc_offset are ignored.
info.SetPosition(25, 4, SourcePosition::kNotInlined);
CHECK_EQ(2, info.GetSourceLineNumber(21));
CHECK_EQ(3, info.GetSourceLineNumber(100));
CHECK_EQ(3, info.GetSourceLineNumber(std::numeric_limits<int>::max()));
CHECK_EQ(SourcePosition::kNotInlined, info.GetInliningId(21));
CHECK_EQ(0, info.GetInliningId(100));
}
TEST(MultipleProfilers) {