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 #ifndef SRC_TRACE_PROCESSOR_IMPORTERS_ETM_ELF_TRACKER_H_ 18 #define SRC_TRACE_PROCESSOR_IMPORTERS_ETM_ELF_TRACKER_H_ 19 20 #include <optional> 21 22 #include "perfetto/ext/base/flat_hash_map.h" 23 #include "perfetto/trace_processor/trace_blob_view.h" 24 #include "src/trace_processor/tables/etm_tables_py.h" 25 #include "src/trace_processor/types/destructible.h" 26 #include "src/trace_processor/types/trace_processor_context.h" 27 #include "src/trace_processor/util/build_id.h" 28 29 namespace perfetto::trace_processor::etm { 30 31 class ElfTracker : public Destructible { 32 public: GetOrCreate(TraceProcessorContext * context)33 static ElfTracker* GetOrCreate(TraceProcessorContext* context) { 34 if (!context->elf_tracker) { 35 context->elf_tracker.reset(new ElfTracker(context)); 36 } 37 return static_cast<ElfTracker*>(context->elf_tracker.get()); 38 } 39 40 ~ElfTracker() override; 41 42 bool ProcessFile(tables::FileTable::Id file_id, const TraceBlobView& content); FindBuildId(const BuildId & build_id)43 std::optional<tables::ElfFileTable::Id> FindBuildId( 44 const BuildId& build_id) const { 45 auto it = files_by_build_id_.Find(build_id); 46 return it ? std::make_optional(*it) : std::nullopt; 47 } 48 49 private: ElfTracker(TraceProcessorContext * context)50 explicit ElfTracker(TraceProcessorContext* context) : context_(context) {} 51 TraceProcessorContext* context_; 52 base::FlatHashMap<BuildId, tables::ElfFileTable::Id> files_by_build_id_; 53 }; 54 55 } // namespace perfetto::trace_processor::etm 56 57 #endif // SRC_TRACE_PROCESSOR_IMPORTERS_ETM_ELF_TRACKER_H_ 58