llvm.org GIT mirror llvm / 0224d5c
Add debugging to the cache pruning From: Mehdi Amini <mehdi.amini@apple.com> git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@266686 91177308-0d34-0410-b5e6-96231b3b80d8 Mehdi Amini 4 years ago
1 changed file(s) with 23 addition(s) and 4 deletion(s). Raw diff Collapse all Expand all
1212
1313 #include "llvm/Support/CachePruning.h"
1414
15 #include "llvm/Support/Debug.h"
1516 #include "llvm/Support/FileSystem.h"
1617 #include "llvm/Support/Path.h"
1718 #include "llvm/Support/raw_ostream.h"
19
20 #define DEBUG_TYPE "cache-pruning"
1821
1922 #include
2023
3235 SmallString<128> TimestampFile(Path);
3336 sys::path::append(TimestampFile, "llvmcache.timestamp");
3437
35 if (Expiration == 0 && PercentageOfAvailableSpace == 0)
38 if (Expiration == 0 && PercentageOfAvailableSpace == 0) {
39 DEBUG(dbgs() << "No pruning settings set, exit early\n");
3640 // Nothing will be pruned, early exit
3741 return false;
42 }
3843
3944 // Try to stat() the timestamp file.
4045 sys::fs::file_status FileStatus;
5358 // If not, do nothing.
5459 sys::TimeValue TimeStampModTime = FileStatus.getLastModificationTime();
5560 auto TimeInterval = sys::TimeValue(sys::TimeValue::SecondsType(Interval));
56 if (CurrentTime - TimeStampModTime <= TimeInterval)
61 auto TimeStampAge = CurrentTime - TimeStampModTime;
62 if (TimeStampAge <= TimeInterval) {
63 DEBUG(dbgs() << "Timestamp file too recent (" << TimeStampAge.seconds()
64 << "s old), do not prune.\n");
5765 return false;
66 }
5867 }
5968 // Write a new timestamp file so that nobody else attempts to prune.
6069 // There is a benign race condition here, if two processes happen to
92101
93102 // Look at this file. If we can't stat it, there's nothing interesting
94103 // there.
95 if (sys::fs::status(File->path(), FileStatus))
104 if (sys::fs::status(File->path(), FileStatus)) {
105 DEBUG(dbgs() << "Ignore " << File->path() << " (can't stat)\n");
96106 continue;
107 }
97108
98109 // If the file hasn't been used recently enough, delete it
99110 sys::TimeValue FileAccessTime = FileStatus.getLastAccessedTime();
100 if (CurrentTime - FileAccessTime > TimeExpiration) {
111 auto FileAge = CurrentTime - FileAccessTime;
112 if (FileAge > TimeExpiration) {
113 DEBUG(dbgs() << "Remove " << File->path() << " (" << FileAge.seconds()
114 << "s old)\n");
101115 sys::fs::remove(File->path());
102116 continue;
103117 }
115129 sys::fs::space_info SpaceInfo = ErrOrSpaceInfo.get();
116130 auto AvailableSpace = TotalSize + SpaceInfo.free;
117131 auto FileAndSize = FileSizes.rbegin();
132 DEBUG(dbgs() << "Occupancy: " << ((100 * TotalSize) / AvailableSpace)
133 << "% target is: " << PercentageOfAvailableSpace << "\n");
118134 // Remove the oldest accessed files first, till we get below the threshold
119135 while (((100 * TotalSize) / AvailableSpace) > PercentageOfAvailableSpace &&
120136 FileAndSize != FileSizes.rend()) {
122138 sys::fs::remove(FileAndSize->second);
123139 // Update size
124140 TotalSize -= FileAndSize->first;
141 DEBUG(dbgs() << " - Remove " << FileAndSize->second << " (size "
142 << FileAndSize->first << "), new occupancy is " << TotalSize
143 << "%\n");
125144 ++FileAndSize;
126145 }
127146 }