Skip to content

Commit c6c5944

Browse files
committed
[lldb] Allow DataFileCache to be constructed with a different policy
Differential Revision: https://reviews.llvm.org/D131531
1 parent d4a4864 commit c6c5944

File tree

2 files changed

+38
-21
lines changed

2 files changed

+38
-21
lines changed

lldb/include/lldb/Core/DataFileCache.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "lldb/Utility/UUID.h"
1515
#include "lldb/lldb-forward.h"
1616
#include "llvm/ADT/DenseMap.h"
17+
#include "llvm/Support/CachePruning.h"
1718
#include "llvm/Support/Caching.h"
1819
#include <mutex>
1920

@@ -40,11 +41,18 @@ namespace lldb_private {
4041

4142
class DataFileCache {
4243
public:
43-
/// Create a data file cache in the directory path that is specified.
44+
/// Create a data file cache in the directory path that is specified, using
45+
/// the specified policy.
4446
///
4547
/// Data will be cached in files created in this directory when clients call
4648
/// DataFileCache::SetCacheData.
47-
DataFileCache(llvm::StringRef path);
49+
DataFileCache(llvm::StringRef path,
50+
llvm::CachePruningPolicy policy =
51+
DataFileCache::GetLLDBIndexCachePolicy());
52+
53+
/// Gets the default LLDB index cache policy, which is controlled by the
54+
/// "LLDBIndexCache" family of settings.
55+
static llvm::CachePruningPolicy GetLLDBIndexCachePolicy();
4856

4957
/// Get cached data from the cache directory for the specified key.
5058
///

lldb/source/Core/DataFileCache.cpp

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,26 +19,34 @@
1919

2020
using namespace lldb_private;
2121

22-
DataFileCache::DataFileCache(llvm::StringRef path) {
23-
m_cache_dir.SetPath(path);
2422

25-
// Prune the cache based off of the LLDB settings each time we create a cache
26-
// object.
27-
ModuleListProperties &properties =
28-
ModuleList::GetGlobalModuleListProperties();
29-
llvm::CachePruningPolicy policy;
30-
// Only scan once an hour. If we have lots of debug sessions we don't want
31-
// to scan this directory too often. A timestamp file is written to the
32-
// directory to ensure different processes don't scan the directory too often.
33-
// This setting doesn't mean that a thread will continually scan the cache
34-
// directory within this process.
35-
policy.Interval = std::chrono::hours(1);
36-
// Get the user settings for pruning.
37-
policy.MaxSizeBytes = properties.GetLLDBIndexCacheMaxByteSize();
38-
policy.MaxSizePercentageOfAvailableSpace =
39-
properties.GetLLDBIndexCacheMaxPercent();
40-
policy.Expiration =
41-
std::chrono::hours(properties.GetLLDBIndexCacheExpirationDays() * 24);
23+
llvm::CachePruningPolicy DataFileCache::GetLLDBIndexCachePolicy() {
24+
static llvm::CachePruningPolicy policy;
25+
static llvm::once_flag once_flag;
26+
27+
llvm::call_once(once_flag, []() {
28+
// Prune the cache based off of the LLDB settings each time we create a
29+
// cache object.
30+
ModuleListProperties &properties =
31+
ModuleList::GetGlobalModuleListProperties();
32+
// Only scan once an hour. If we have lots of debug sessions we don't want
33+
// to scan this directory too often. A timestamp file is written to the
34+
// directory to ensure different processes don't scan the directory too
35+
// often. This setting doesn't mean that a thread will continually scan the
36+
// cache directory within this process.
37+
policy.Interval = std::chrono::hours(1);
38+
// Get the user settings for pruning.
39+
policy.MaxSizeBytes = properties.GetLLDBIndexCacheMaxByteSize();
40+
policy.MaxSizePercentageOfAvailableSpace =
41+
properties.GetLLDBIndexCacheMaxPercent();
42+
policy.Expiration =
43+
std::chrono::hours(properties.GetLLDBIndexCacheExpirationDays() * 24);
44+
});
45+
return policy;
46+
}
47+
48+
DataFileCache::DataFileCache(llvm::StringRef path, llvm::CachePruningPolicy policy) {
49+
m_cache_dir.SetPath(path);
4250
pruneCache(path, policy);
4351

4452
// This lambda will get called when the data is gotten from the cache and
@@ -311,3 +319,4 @@ llvm::StringRef StringTableReader::Get(uint32_t offset) const {
311319
return llvm::StringRef();
312320
return llvm::StringRef(m_data.data() + offset);
313321
}
322+

0 commit comments

Comments
 (0)