diff options
| author | Dimitry Andric <dim@FreeBSD.org> | 2023-02-11 12:38:04 +0000 |
|---|---|---|
| committer | Dimitry Andric <dim@FreeBSD.org> | 2023-02-11 12:38:11 +0000 |
| commit | e3b557809604d036af6e00c60f012c2025b59a5e (patch) | |
| tree | 8a11ba2269a3b669601e2fd41145b174008f4da8 /lldb/source/Core/DataFileCache.cpp | |
| parent | 08e8dd7b9db7bb4a9de26d44c1cbfd24e869c014 (diff) | |
Diffstat (limited to 'lldb/source/Core/DataFileCache.cpp')
| -rw-r--r-- | lldb/source/Core/DataFileCache.cpp | 59 |
1 files changed, 34 insertions, 25 deletions
diff --git a/lldb/source/Core/DataFileCache.cpp b/lldb/source/Core/DataFileCache.cpp index b38adfda169a..b29327db5ca3 100644 --- a/lldb/source/Core/DataFileCache.cpp +++ b/lldb/source/Core/DataFileCache.cpp @@ -15,30 +15,37 @@ #include "lldb/Utility/LLDBLog.h" #include "lldb/Utility/Log.h" #include "llvm/Support/CachePruning.h" -#include "llvm/Support/MemoryBuffer.h" using namespace lldb_private; -DataFileCache::DataFileCache(llvm::StringRef path) { - m_cache_dir.SetPath(path); - // Prune the cache based off of the LLDB settings each time we create a cache - // object. - ModuleListProperties &properties = - ModuleList::GetGlobalModuleListProperties(); - llvm::CachePruningPolicy policy; - // Only scan once an hour. If we have lots of debug sessions we don't want - // to scan this directory too often. A timestamp file is written to the - // directory to ensure different processes don't scan the directory too often. - // This setting doesn't mean that a thread will continually scan the cache - // directory within this process. - policy.Interval = std::chrono::hours(1); - // Get the user settings for pruning. - policy.MaxSizeBytes = properties.GetLLDBIndexCacheMaxByteSize(); - policy.MaxSizePercentageOfAvailableSpace = - properties.GetLLDBIndexCacheMaxPercent(); - policy.Expiration = - std::chrono::hours(properties.GetLLDBIndexCacheExpirationDays() * 24); +llvm::CachePruningPolicy DataFileCache::GetLLDBIndexCachePolicy() { + static llvm::CachePruningPolicy policy; + static llvm::once_flag once_flag; + + llvm::call_once(once_flag, []() { + // Prune the cache based off of the LLDB settings each time we create a + // cache object. + ModuleListProperties &properties = + ModuleList::GetGlobalModuleListProperties(); + // Only scan once an hour. If we have lots of debug sessions we don't want + // to scan this directory too often. A timestamp file is written to the + // directory to ensure different processes don't scan the directory too + // often. This setting doesn't mean that a thread will continually scan the + // cache directory within this process. + policy.Interval = std::chrono::hours(1); + // Get the user settings for pruning. + policy.MaxSizeBytes = properties.GetLLDBIndexCacheMaxByteSize(); + policy.MaxSizePercentageOfAvailableSpace = + properties.GetLLDBIndexCacheMaxPercent(); + policy.Expiration = + std::chrono::hours(properties.GetLLDBIndexCacheExpirationDays() * 24); + }); + return policy; +} + +DataFileCache::DataFileCache(llvm::StringRef path, llvm::CachePruningPolicy policy) { + m_cache_dir.SetPath(path); pruneCache(path, policy); // This lambda will get called when the data is gotten from the cache and @@ -47,7 +54,8 @@ DataFileCache::DataFileCache(llvm::StringRef path) { // m_take_ownership member variable to indicate if we need to take // ownership. - auto add_buffer = [this](unsigned task, std::unique_ptr<llvm::MemoryBuffer> m) { + auto add_buffer = [this](unsigned task, const llvm::Twine &moduleName, + std::unique_ptr<llvm::MemoryBuffer> m) { if (m_take_ownership) m_mem_buff_up = std::move(m); }; @@ -73,7 +81,7 @@ DataFileCache::GetCachedData(llvm::StringRef key) { // turn take ownership of the member buffer that is passed to the callback and // put it into a member variable. llvm::Expected<llvm::AddStreamFn> add_stream_or_err = - m_cache_callback(task, key); + m_cache_callback(task, key, ""); m_take_ownership = false; // At this point we either already called the "add_buffer" lambda with // the data or we haven't. We can tell if we got the cached data by checking @@ -105,7 +113,7 @@ bool DataFileCache::SetCachedData(llvm::StringRef key, // add_buffer lambda function from the constructor which will ignore the // data. llvm::Expected<llvm::AddStreamFn> add_stream_or_err = - m_cache_callback(task, key); + m_cache_callback(task, key, ""); // If we reach this code then we either already called the callback with // the data or we haven't. We can tell if we had the cached data by checking // the CacheAddStream function pointer value below. @@ -120,7 +128,7 @@ bool DataFileCache::SetCachedData(llvm::StringRef key, // want to write the data. if (add_stream) { llvm::Expected<std::unique_ptr<llvm::CachedFileStream>> file_or_err = - add_stream(task); + add_stream(task, ""); if (file_or_err) { llvm::CachedFileStream *cfs = file_or_err->get(); cfs->OS->write((const char *)data.data(), data.size()); @@ -230,7 +238,7 @@ bool CacheSignature::Decode(const lldb_private::DataExtractor &data, const uint8_t length = data.GetU8(offset_ptr); const uint8_t *bytes = (const uint8_t *)data.GetData(offset_ptr, length); if (bytes != nullptr && length > 0) - m_uuid = UUID::fromData(llvm::ArrayRef<uint8_t>(bytes, length)); + m_uuid = UUID(llvm::ArrayRef<uint8_t>(bytes, length)); } break; case eSignatureModTime: { uint32_t mod_time = data.GetU32(offset_ptr); @@ -311,3 +319,4 @@ llvm::StringRef StringTableReader::Get(uint32_t offset) const { return llvm::StringRef(); return llvm::StringRef(m_data.data() + offset); } + |
