1 /* 2 * Copyright (C) 2020 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_TRACED_PROBES_FTRACE_PRINTK_FORMATS_PARSER_H_ 18 #define SRC_TRACED_PROBES_FTRACE_PRINTK_FORMATS_PARSER_H_ 19 20 #include <string> 21 22 #include "perfetto/base/flat_set.h" 23 #include "perfetto/ext/base/string_view.h" 24 25 namespace perfetto { 26 27 struct PrintkEntry { 28 uint64_t address; 29 std::string name; 30 PrintkEntryPrintkEntry31 PrintkEntry(uint64_t _address) : PrintkEntry(_address, "") {} 32 PrintkEntryPrintkEntry33 PrintkEntry(uint64_t _address, std::string _name) 34 : address(_address), name(_name) {} 35 36 bool operator<(const PrintkEntry& other) const { 37 return address < other.address; 38 } 39 40 bool operator==(const PrintkEntry& other) const { 41 return address == other.address; 42 } 43 }; 44 45 class PrintkMap { 46 public: insert(uint64_t address,std::string name)47 void insert(uint64_t address, std::string name) { 48 set_.insert(PrintkEntry(address, name)); 49 } 50 at(uint64_t address)51 base::StringView at(uint64_t address) const { 52 auto it = set_.find(address); 53 if (it == set_.end()) { 54 return base::StringView(); 55 } 56 return base::StringView(it->name); 57 } 58 size()59 size_t size() const { return set_.size(); } 60 empty()61 size_t empty() const { return set_.empty(); } 62 63 base::FlatSet<PrintkEntry> set_; 64 }; 65 66 PrintkMap ParsePrintkFormats(const std::string& format); 67 68 } // namespace perfetto 69 70 #endif // SRC_TRACED_PROBES_FTRACE_PRINTK_FORMATS_PARSER_H_ 71