Correctly handle multiple mappings for symbols
Test: trace_processor_shell ~/Downloads/8506142608917942063-13279965147515891286.pb
no stats errors
Bug: 142543113
Change-Id: I76497ef6b13be154d99f8b122891c7d1d1d82fa4
diff --git a/src/trace_processor/proto_trace_parser.cc b/src/trace_processor/proto_trace_parser.cc
index 8bc2fc9..73a9c8a 100644
--- a/src/trace_processor/proto_trace_parser.cc
+++ b/src/trace_processor/proto_trace_parser.cc
@@ -2686,25 +2686,28 @@
protos::pbzero::ModuleSymbols::Decoder module_symbols(blob.data, blob.size);
std::string hex_build_id = base::ToHex(module_symbols.build_id().data,
module_symbols.build_id().size);
- ssize_t mapping_row =
+ auto mapping_rows =
context_->storage->stack_profile_mappings().FindMappingRow(
context_->storage->InternString(module_symbols.path()),
context_->storage->InternString(base::StringView(hex_build_id)));
- if (mapping_row == -1) {
- PERFETTO_LOG("Could not find mapping %s (%s).",
- base::StringView(module_symbols.path()).ToStdString().c_str(),
- hex_build_id.c_str());
+ if (mapping_rows.empty()) {
+ context_->storage->IncrementStats(stats::stackprofile_invalid_mapping_id);
return;
}
for (auto addr_it = module_symbols.address_symbols(); addr_it; ++addr_it) {
protos::pbzero::AddressSymbols::Decoder address_symbols(addr_it->data(),
addr_it->size());
- ssize_t frame_row = context_->storage->stack_profile_frames().FindFrameRow(
- static_cast<size_t>(mapping_row), address_symbols.address());
+ ssize_t frame_row = -1;
+ for (int64_t mapping_row : mapping_rows) {
+ frame_row = context_->storage->stack_profile_frames().FindFrameRow(
+ static_cast<size_t>(mapping_row), address_symbols.address());
+ if (frame_row != -1)
+ break;
+ }
if (frame_row == -1) {
- PERFETTO_DFATAL_OR_ELOG("Could not find frame.");
- return;
+ context_->storage->IncrementStats(stats::stackprofile_invalid_frame_id);
+ continue;
}
uint32_t symbol_set_id = context_->storage->symbol_table().size();
context_->storage->mutable_stack_profile_frames()->SetSymbolSetId(
diff --git a/src/trace_processor/trace_storage.h b/src/trace_processor/trace_storage.h
index 2f6f77e..26b97c3 100644
--- a/src/trace_processor/trace_storage.h
+++ b/src/trace_processor/trace_storage.h
@@ -937,15 +937,17 @@
names_.emplace_back(row.name_id);
size_t row_number = build_ids_.size() - 1;
- index_.emplace(std::make_pair(row.name_id, row.build_id), row_number);
+ index_[std::make_pair(row.name_id, row.build_id)].emplace_back(
+ row_number);
return static_cast<int64_t>(row_number);
}
- ssize_t FindMappingRow(StringId name, StringId build_id) const {
+ std::vector<int64_t> FindMappingRow(StringId name,
+ StringId build_id) const {
auto it = index_.find(std::make_pair(name, build_id));
if (it == index_.end())
- return -1;
- return static_cast<ssize_t>(it->second);
+ return {};
+ return it->second;
}
const std::deque<StringId>& build_ids() const { return build_ids_; }
@@ -965,7 +967,8 @@
std::deque<int64_t> load_biases_;
std::deque<StringId> names_;
- std::map<std::pair<StringId /* name */, StringId /* build id */>, size_t>
+ std::map<std::pair<StringId /* name */, StringId /* build id */>,
+ std::vector<int64_t>>
index_;
};