Go to the documentation of this file.
22 #define DEBUG_TYPE "cache-pruning"
25 #include <system_error>
38 return std::tie(Time,
Other.Size, Path) <
53 return make_error<StringError>(
"Duration must not be empty",
59 return make_error<StringError>(
"'" + NumStr +
"' not an integer",
64 return std::chrono::seconds(Num);
66 return std::chrono::minutes(Num);
68 return std::chrono::hours(Num);
70 return make_error<StringError>(
"'" +
Duration +
71 "' must end with one of 's', 'm' or 'h'",
79 std::pair<StringRef, StringRef>
P = {
"", PolicyStr};
80 while (!
P.second.empty()) {
81 P =
P.second.split(
':');
84 std::tie(
Key,
Value) =
P.first.split(
'=');
85 if (
Key ==
"prune_interval") {
88 return DurationOrErr.takeError();
90 }
else if (
Key ==
"prune_after") {
93 return DurationOrErr.takeError();
95 }
else if (
Key ==
"cache_size") {
96 if (
Value.back() !=
'%')
97 return make_error<StringError>(
"'" +
Value +
"' must be a percentage",
102 return make_error<StringError>(
"'" + SizeStr +
"' not an integer",
105 return make_error<StringError>(
"'" + SizeStr +
106 "' must be between 0 and 100",
109 }
else if (
Key ==
"cache_size_bytes") {
111 switch (tolower(
Value.back())) {
121 Mult = 1024 * 1024 * 1024;
126 if (
Value.getAsInteger(0, Size))
127 return make_error<StringError>(
"'" +
Value +
"' not an integer",
130 }
else if (
Key ==
"cache_size_files") {
132 return make_error<StringError>(
"'" +
Value +
"' not an integer",
135 return make_error<StringError>(
"Unknown key: '" +
Key +
"'",
145 using namespace std::chrono;
184 if (Policy.
Interval != seconds(0)) {
188 auto TimeStampAge = CurrentTime - TimeStampModTime;
189 if (TimeStampAge <= *Policy.
Interval) {
191 << duration_cast<seconds>(TimeStampAge).
count()
192 <<
"s old), do not prune.\n");
204 std::set<FileInfo> FileInfos;
213 File != FileEnd && !EC; File.increment(EC)) {
226 LLVM_DEBUG(
dbgs() <<
"Ignore " << File->path() <<
" (can't stat)\n");
231 const auto FileAccessTime = StatusOrErr->getLastAccessedTime();
232 auto FileAge = CurrentTime - FileAccessTime;
235 << duration_cast<seconds>(FileAge).count()
242 TotalSize += StatusOrErr->getSize();
243 FileInfos.insert({FileAccessTime, StatusOrErr->getSize(), File->path()});
246 auto FileInfo = FileInfos.begin();
247 size_t NumFiles = FileInfos.size();
249 auto RemoveCacheFile = [&]() {
253 TotalSize -= FileInfo->Size;
256 << FileInfo->Size <<
"), new occupancy is " << TotalSize
269 if (!ErrOrSpaceInfo) {
273 auto AvailableSpace = TotalSize + SpaceInfo.
free;
279 auto TotalSizeTarget = std::min<uint64_t>(
283 LLVM_DEBUG(
dbgs() <<
"Occupancy: " << ((100 * TotalSize) / AvailableSpace)
289 while (TotalSize > TotalSizeTarget && FileInfo != FileInfos.end())
LLVM_NODISCARD bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
This is an optimization pass for GlobalISel generic memory operations.
space_info - Self explanatory.
This currently compiles esp xmm0 movsd esp eax eax esp ret We should use not the dag combiner This is because dagcombine2 needs to be able to see through the X86ISD::Wrapper which DAGCombine can t really do The code for turning x load into a single vector load is target independent and should be moved to the dag combiner The code for turning x load into a vector load can only handle a direct load from a global or a direct load from the stack It should be generalized to handle any load from P
void native(const Twine &path, SmallVectorImpl< char > &result, Style style=Style::native)
Convert path to the native form.
@ no_such_file_or_directory
Tagged union holding either a T or a Error.
std::chrono::time_point< std::chrono::system_clock, D > TimePoint
A time point on the system clock.
void append(SmallVectorImpl< char > &path, const Twine &a, const Twine &b="", const Twine &c="", const Twine &d="")
Append to path.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
uint64_t MaxSizeBytes
The maximum size for the cache directory in bytes.
std::chrono::seconds Expiration
The expiration for a file.
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
LLVM_NODISCARD std::string str() const
str - Get the contents as an std::string.
std::enable_if_t< std::numeric_limits< T >::is_signed, bool > getAsInteger(unsigned Radix, T &Result) const
Parse the current string as an integer of the specified radix.
static sys::TimePoint< std::chrono::seconds > now(bool Deterministic)
static void writeTimestampFile(StringRef TimestampFile)
Write a new timestamp file with the given path.
Represents the result of a call to sys::fs::status().
auto count(R &&Range, const E &Element)
Wrapper function around std::count to count the number of times an element Element occurs in the give...
bool operator<(int64_t V1, const APSInt &V2)
std::error_code remove(const Twine &path, bool IgnoreNonExisting=true)
Remove path.
Expected< ExpressionValue > min(const ExpressionValue &Lhs, const ExpressionValue &Rhs)
StringRef - Represent a constant reference to a string, i.e.
unsigned MaxSizePercentageOfAvailableSpace
The maximum size for the cache directory, in terms of percentage of the available space on the disk.
Policy for the pruneCache() function.
A raw_ostream that writes to a file descriptor.
uint64_t MaxSizeFiles
The maximum number of files in the cache directory.
std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
llvm::Optional< std::chrono::seconds > Interval
The pruning interval.
bool is_directory(const basic_file_status &status)
Does status represent a directory?
directory_iterator - Iterates through the entries in path.
StringRef filename(StringRef path, Style style=Style::native)
Get filename.
std::error_code status(const Twine &path, file_status &result, bool follow=true)
Get file status as if by POSIX stat().
Represents either an error or a value T.
bool pruneCache(StringRef Path, CachePruningPolicy Policy)
Peform pruning using the supplied policy, returns true if pruning occurred, i.e.
static Expected< std::chrono::seconds > parseDuration(StringRef Duration)
TimePoint getLastModificationTime() const
The file modification time as reported from the underlying file system.
Expected< CachePruningPolicy > parseCachePruningPolicy(StringRef PolicyStr)
Parse the given string as a cache pruning policy.
LLVM Value Representation.
ErrorOr< space_info > disk_space(const Twine &Path)
Get disk space usage information.
Optional< std::vector< StOtherPiece > > Other