1 //===-- FormatCache.h ---------------------------------------------*- C++ 2 //-*-===// 3 // 4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 5 // See https://llvm.org/LICENSE.txt for license information. 6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 7 // 8 //===----------------------------------------------------------------------===// 9 10 #ifndef LLDB_DATAFORMATTERS_FORMATCACHE_H 11 #define LLDB_DATAFORMATTERS_FORMATCACHE_H 12 13 #include <map> 14 #include <mutex> 15 16 #include "lldb/Utility/ConstString.h" 17 #include "lldb/lldb-public.h" 18 19 namespace lldb_private { 20 class FormatCache { 21 private: 22 struct Entry { 23 private: 24 bool m_format_cached : 1; 25 bool m_summary_cached : 1; 26 bool m_synthetic_cached : 1; 27 28 lldb::TypeFormatImplSP m_format_sp; 29 lldb::TypeSummaryImplSP m_summary_sp; 30 lldb::SyntheticChildrenSP m_synthetic_sp; 31 32 public: 33 Entry(); 34 35 template<typename ImplSP> bool IsCached(); 36 bool IsFormatCached(); 37 bool IsSummaryCached(); 38 bool IsSyntheticCached(); 39 40 void Get(lldb::TypeFormatImplSP &); 41 void Get(lldb::TypeSummaryImplSP &); 42 void Get(lldb::SyntheticChildrenSP &); 43 44 void Set(lldb::TypeFormatImplSP); 45 void Set(lldb::TypeSummaryImplSP); 46 void Set(lldb::SyntheticChildrenSP); 47 }; 48 std::map<ConstString, Entry> m_entries; 49 std::recursive_mutex m_mutex; 50 51 uint64_t m_cache_hits = 0; 52 uint64_t m_cache_misses = 0; 53 54 public: 55 FormatCache() = default; 56 57 template <typename ImplSP> bool Get(ConstString type, ImplSP &format_impl_sp); 58 void Set(ConstString type, lldb::TypeFormatImplSP &format_sp); 59 void Set(ConstString type, lldb::TypeSummaryImplSP &summary_sp); 60 void Set(ConstString type, lldb::SyntheticChildrenSP &synthetic_sp); 61 62 void Clear(); 63 GetCacheHits()64 uint64_t GetCacheHits() { return m_cache_hits; } 65 GetCacheMisses()66 uint64_t GetCacheMisses() { return m_cache_misses; } 67 }; 68 69 } // namespace lldb_private 70 71 #endif // LLDB_DATAFORMATTERS_FORMATCACHE_H 72