1 /* 2 * Copyright (C) 2022 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_COMMON_SLICE_TRANSLATION_TABLE_H_ 18 #define SRC_TRACE_PROCESSOR_IMPORTERS_COMMON_SLICE_TRANSLATION_TABLE_H_ 19 20 #include <cstdint> 21 22 #include "perfetto/ext/base/flat_hash_map.h" 23 #include "perfetto/ext/base/string_view.h" 24 #include "src/trace_processor/storage/trace_storage.h" 25 26 namespace perfetto { 27 namespace trace_processor { 28 29 // Tracks and stores slice translation rules. It allows Trace Processor 30 // to for example deobfuscate slice names. 31 class SliceTranslationTable { 32 public: 33 SliceTranslationTable(TraceStorage* storage); 34 35 // If the name is not mapped to anything, assumes that no translation is 36 // necessry, and returns the raw_name. TranslateName(StringId raw_name)37 StringId TranslateName(StringId raw_name) const { 38 const auto* mapped_name = raw_to_deobfuscated_name_.Find(raw_name); 39 return mapped_name ? *mapped_name : raw_name; 40 } 41 AddNameTranslationRule(base::StringView raw,base::StringView deobfuscated)42 void AddNameTranslationRule(base::StringView raw, 43 base::StringView deobfuscated) { 44 const StringId raw_id = storage_->InternString(raw); 45 const StringId deobfuscated_id = storage_->InternString(deobfuscated); 46 raw_to_deobfuscated_name_[raw_id] = deobfuscated_id; 47 } 48 49 private: 50 TraceStorage* storage_; 51 base::FlatHashMap<StringId, StringId> raw_to_deobfuscated_name_; 52 }; 53 54 } // namespace trace_processor 55 } // namespace perfetto 56 57 #endif // SRC_TRACE_PROCESSOR_IMPORTERS_COMMON_SLICE_TRANSLATION_TABLE_H_ 58