This revision was automatically updated to reflect the committed changes. Closed by commit rGc6c5944d05e8: [lldb] Allow DataFileCache to be constructed with a different policy (authored by augusto2112).
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D131531/new/ https://reviews.llvm.org/D131531 Files: lldb/include/lldb/Core/DataFileCache.h lldb/source/Core/DataFileCache.cpp Index: lldb/source/Core/DataFileCache.cpp =================================================================== --- lldb/source/Core/DataFileCache.cpp +++ lldb/source/Core/DataFileCache.cpp @@ -19,26 +19,34 @@ 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 @@ -311,3 +319,4 @@ return llvm::StringRef(); return llvm::StringRef(m_data.data() + offset); } + Index: lldb/include/lldb/Core/DataFileCache.h =================================================================== --- lldb/include/lldb/Core/DataFileCache.h +++ lldb/include/lldb/Core/DataFileCache.h @@ -14,6 +14,7 @@ #include "lldb/Utility/UUID.h" #include "lldb/lldb-forward.h" #include "llvm/ADT/DenseMap.h" +#include "llvm/Support/CachePruning.h" #include "llvm/Support/Caching.h" #include <mutex> @@ -40,11 +41,18 @@ class DataFileCache { public: - /// Create a data file cache in the directory path that is specified. + /// Create a data file cache in the directory path that is specified, using + /// the specified policy. /// /// Data will be cached in files created in this directory when clients call /// DataFileCache::SetCacheData. - DataFileCache(llvm::StringRef path); + DataFileCache(llvm::StringRef path, + llvm::CachePruningPolicy policy = + DataFileCache::GetLLDBIndexCachePolicy()); + + /// Gets the default LLDB index cache policy, which is controlled by the + /// "LLDBIndexCache" family of settings. + static llvm::CachePruningPolicy GetLLDBIndexCachePolicy(); /// Get cached data from the cache directory for the specified key. ///
Index: lldb/source/Core/DataFileCache.cpp =================================================================== --- lldb/source/Core/DataFileCache.cpp +++ lldb/source/Core/DataFileCache.cpp @@ -19,26 +19,34 @@ 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 @@ -311,3 +319,4 @@ return llvm::StringRef(); return llvm::StringRef(m_data.data() + offset); } + Index: lldb/include/lldb/Core/DataFileCache.h =================================================================== --- lldb/include/lldb/Core/DataFileCache.h +++ lldb/include/lldb/Core/DataFileCache.h @@ -14,6 +14,7 @@ #include "lldb/Utility/UUID.h" #include "lldb/lldb-forward.h" #include "llvm/ADT/DenseMap.h" +#include "llvm/Support/CachePruning.h" #include "llvm/Support/Caching.h" #include <mutex> @@ -40,11 +41,18 @@ class DataFileCache { public: - /// Create a data file cache in the directory path that is specified. + /// Create a data file cache in the directory path that is specified, using + /// the specified policy. /// /// Data will be cached in files created in this directory when clients call /// DataFileCache::SetCacheData. - DataFileCache(llvm::StringRef path); + DataFileCache(llvm::StringRef path, + llvm::CachePruningPolicy policy = + DataFileCache::GetLLDBIndexCachePolicy()); + + /// Gets the default LLDB index cache policy, which is controlled by the + /// "LLDBIndexCache" family of settings. + static llvm::CachePruningPolicy GetLLDBIndexCachePolicy(); /// Get cached data from the cache directory for the specified key. ///
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits