1 /* 2 * Copyright (C) 2024 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #include "src/trace_processor/importers/etm/elf_tracker.h" 18 19 #include <optional> 20 21 #include "src/trace_processor/importers/elf/binary_info.h" 22 #include "src/trace_processor/storage/trace_storage.h" 23 #include "src/trace_processor/types/trace_processor_context.h" 24 #include "src/trace_processor/util/build_id.h" 25 26 namespace perfetto::trace_processor::etm { 27 28 ElfTracker::~ElfTracker() = default; 29 ProcessFile(tables::FileTable::Id file_id,const TraceBlobView & content)30bool ElfTracker::ProcessFile(tables::FileTable::Id file_id, 31 const TraceBlobView& content) { 32 auto bin_info = elf::GetBinaryInfo(content.data(), content.size()); 33 if (!bin_info) { 34 return false; 35 } 36 std::optional<BuildId> build_id; 37 if (bin_info->build_id) { 38 build_id = BuildId::FromRaw(*bin_info->build_id); 39 } 40 41 tables::ElfFileTable::Row row; 42 row.file_id = file_id; 43 row.load_bias = static_cast<int64_t>(bin_info->load_bias); 44 45 if (build_id) { 46 row.build_id = context_->storage->InternString( 47 BuildId::FromRaw(*bin_info->build_id).ToHex()); 48 } 49 50 auto id = context_->storage->mutable_elf_file_table()->Insert(row).id; 51 52 if (build_id) { 53 files_by_build_id_.Insert(*build_id, id); 54 } 55 56 return true; 57 } 58 59 } // namespace perfetto::trace_processor::etm 60