LLDB  mainline
FormatCache.h
Go to the documentation of this file.
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 
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;
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  typedef std::map<ConstString, Entry> CacheMap;
50  std::recursive_mutex m_mutex;
51 
52  uint64_t m_cache_hits = 0;
53  uint64_t m_cache_misses = 0;
54 
55  Entry &GetEntry(ConstString type);
56 
57 public:
58  FormatCache() = default;
59 
60  template <typename ImplSP> bool Get(ConstString type, ImplSP &format_impl_sp);
61  void Set(ConstString type, lldb::TypeFormatImplSP &format_sp);
62  void Set(ConstString type, lldb::TypeSummaryImplSP &summary_sp);
63  void Set(ConstString type, lldb::SyntheticChildrenSP &synthetic_sp);
64 
65  void Clear();
66 
67  uint64_t GetCacheHits() { return m_cache_hits; }
68 
69  uint64_t GetCacheMisses() { return m_cache_misses; }
70 };
71 
72 } // namespace lldb_private
73 
74 #endif // LLDB_DATAFORMATTERS_FORMATCACHE_H
lldb_private::FormatCache::CacheMap
std::map< ConstString, Entry > CacheMap
Definition: FormatCache.h:48
lldb_private::FormatCache::Set
void Set(ConstString type, lldb::TypeFormatImplSP &format_sp)
Definition: FormatCache.cpp:102
lldb-public.h
lldb_private::FormatCache::Entry::m_summary_sp
lldb::TypeSummaryImplSP m_summary_sp
Definition: FormatCache.h:29
lldb_private::FormatCache::m_map
CacheMap m_map
Definition: FormatCache.h:49
lldb_private::FormatCache
Definition: FormatCache.h:20
lldb_private::FormatCache::m_cache_misses
uint64_t m_cache_misses
Definition: FormatCache.h:53
lldb_private::FormatCache::Get
bool Get(ConstString type, ImplSP &format_impl_sp)
Definition: FormatCache.cpp:77
lldb_private::FormatCache::Entry::Set
void Set(lldb::TypeFormatImplSP)
Definition: FormatCache.cpp:39
lldb_private::FormatCache::Entry::m_summary_cached
bool m_summary_cached
Definition: FormatCache.h:25
lldb_private::FormatCache::Entry::IsCached
bool IsCached()
lldb_private::FormatCache::Entry::Entry
Entry()
Definition: FormatCache.cpp:17
lldb_private::FormatCache::GetCacheMisses
uint64_t GetCacheMisses()
Definition: FormatCache.h:69
lldb_private::FormatCache::Entry::IsSummaryCached
bool IsSummaryCached()
Definition: FormatCache.cpp:23
lldb_private::ConstString
Definition: ConstString.h:40
lldb_private::FormatCache::GetCacheHits
uint64_t GetCacheHits()
Definition: FormatCache.h:67
lldb_private::FormatCache::Entry::m_synthetic_sp
lldb::SyntheticChildrenSP m_synthetic_sp
Definition: FormatCache.h:30
lldb_private::FormatCache::FormatCache
FormatCache()=default
lldb_private::FormatCache::m_mutex
std::recursive_mutex m_mutex
Definition: FormatCache.h:50
lldb_private::FormatCache::Entry::m_format_sp
lldb::TypeFormatImplSP m_format_sp
Definition: FormatCache.h:28
lldb_private::FormatCache::m_cache_hits
uint64_t m_cache_hits
Definition: FormatCache.h:52
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::FormatCache::GetEntry
Entry & GetEntry(ConstString type)
Definition: FormatCache.cpp:54
lldb_private::FormatCache::Clear
void Clear()
Definition: FormatCache.cpp:118
ConstString.h
lldb_private::FormatCache::Entry::IsSyntheticCached
bool IsSyntheticCached()
Definition: FormatCache.cpp:25
lldb_private::FormatCache::Entry
Definition: FormatCache.h:22
lldb_private::FormatCache::Entry::m_format_cached
bool m_format_cached
Definition: FormatCache.h:24
lldb_private::FormatCache::Entry::Get
void Get(lldb::TypeFormatImplSP &)
Definition: FormatCache.cpp:27
lldb_private::FormatCache::Entry::m_synthetic_cached
bool m_synthetic_cached
Definition: FormatCache.h:26
lldb_private::FormatCache::Entry::IsFormatCached
bool IsFormatCached()
Definition: FormatCache.cpp:21