1 /* 2 * Copyright (C) 2018 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_FILESYSTEM_LRU_INODE_CACHE_H_ 18 #define SRC_TRACED_PROBES_FILESYSTEM_LRU_INODE_CACHE_H_ 19 20 #include <list> 21 #include <map> 22 #include <string> 23 #include <tuple> 24 25 #include "perfetto/traced/data_source_types.h" 26 27 namespace perfetto { 28 29 // LRUInodeCache keeps up to |capacity| entries in a mapping from InodeKey 30 // to InodeMapValue. This is used to map <block device, inode> tuples to file 31 // paths. 32 class LRUInodeCache { 33 public: 34 using InodeKey = std::pair<BlockDeviceID, Inode>; 35 LRUInodeCache(size_t capacity)36 explicit LRUInodeCache(size_t capacity) : capacity_(capacity) {} 37 38 InodeMapValue* Get(const InodeKey& k); 39 void Insert(InodeKey k, InodeMapValue v); 40 41 private: 42 using ItemType = std::pair<const InodeKey, InodeMapValue>; 43 using ListIteratorType = std::list<ItemType>::iterator; 44 using MapType = std::map<const InodeKey, ListIteratorType>; 45 46 void Insert(MapType::iterator map_it, InodeKey k, InodeMapValue v); 47 48 const size_t capacity_; 49 MapType map_; 50 std::list<ItemType> list_; 51 }; 52 53 } // namespace perfetto 54 55 #endif // SRC_TRACED_PROBES_FILESYSTEM_LRU_INODE_CACHE_H_ 56