003 File Manager
Current Path:
/usr/src/contrib/llvm-project/llvm/lib/Support
usr
/
src
/
contrib
/
llvm-project
/
llvm
/
lib
/
Support
/
📁
..
📄
AArch64TargetParser.cpp
(8 KB)
📄
ABIBreak.cpp
(811 B)
📄
AMDGPUMetadata.cpp
(9.37 KB)
📄
APFloat.cpp
(155.26 KB)
📄
APInt.cpp
(98.08 KB)
📄
APSInt.cpp
(1.44 KB)
📄
ARMAttributeParser.cpp
(13.94 KB)
📄
ARMBuildAttrs.cpp
(3.45 KB)
📄
ARMTargetParser.cpp
(18.09 KB)
📄
ARMWinEH.cpp
(1.08 KB)
📄
Allocator.cpp
(1.35 KB)
📄
Atomic.cpp
(1.6 KB)
📄
BinaryStreamError.cpp
(1.76 KB)
📄
BinaryStreamReader.cpp
(5.24 KB)
📄
BinaryStreamRef.cpp
(4.76 KB)
📄
BinaryStreamWriter.cpp
(3.36 KB)
📄
BlockFrequency.cpp
(2.12 KB)
📄
BranchProbability.cpp
(3.44 KB)
📄
BuryPointer.cpp
(1.11 KB)
📄
COM.cpp
(737 B)
📄
COPYRIGHT.regex
(2.65 KB)
📄
CRC.cpp
(5.23 KB)
📄
CachePruning.cpp
(10.33 KB)
📄
Chrono.cpp
(3.17 KB)
📄
CodeGenCoverage.cpp
(3.61 KB)
📄
CommandLine.cpp
(89.06 KB)
📄
Compression.cpp
(3.84 KB)
📄
ConvertUTF.cpp
(27.27 KB)
📄
ConvertUTFWrapper.cpp
(8.66 KB)
📄
CrashRecoveryContext.cpp
(15.45 KB)
📄
DAGDeltaAlgorithm.cpp
(12.47 KB)
📄
DJB.cpp
(2.71 KB)
📄
DataExtractor.cpp
(7.25 KB)
📄
Debug.cpp
(5.64 KB)
📄
DebugCounter.cpp
(4.95 KB)
📄
DeltaAlgorithm.cpp
(3.41 KB)
📄
DynamicLibrary.cpp
(6.25 KB)
📄
ELFAttributeParser.cpp
(7.27 KB)
📄
ELFAttributes.cpp
(1.27 KB)
📄
Errno.cpp
(2.18 KB)
📄
Error.cpp
(4.72 KB)
📄
ErrorHandling.cpp
(11.08 KB)
📄
ExtensibleRTTI.cpp
(446 B)
📄
FileCheck.cpp
(95.77 KB)
📄
FileCheckImpl.h
(34.14 KB)
📄
FileCollector.cpp
(9.01 KB)
📄
FileOutputBuffer.cpp
(6.62 KB)
📄
FileUtilities.cpp
(10.81 KB)
📄
FoldingSet.cpp
(15.89 KB)
📄
FormatVariadic.cpp
(5.17 KB)
📄
FormattedStream.cpp
(5.29 KB)
📄
GlobPattern.cpp
(5 KB)
📄
GraphWriter.cpp
(9.21 KB)
📄
Hashing.cpp
(1.16 KB)
📄
Host.cpp
(51.63 KB)
📄
InitLLVM.cpp
(1.92 KB)
📄
IntEqClasses.cpp
(2.18 KB)
📄
IntervalMap.cpp
(4.4 KB)
📄
ItaniumManglingCanonicalizer.cpp
(10.77 KB)
📄
JSON.cpp
(19.1 KB)
📄
KnownBits.cpp
(3.78 KB)
📄
LEB128.cpp
(1.19 KB)
📄
LineIterator.cpp
(2.61 KB)
📄
Locale.cpp
(377 B)
📄
LockFileManager.cpp
(10.64 KB)
📄
LowLevelType.cpp
(2.09 KB)
📄
MD5.cpp
(8.99 KB)
📄
ManagedStatic.cpp
(2.37 KB)
📄
MathExtras.cpp
(913 B)
📄
MemAlloc.cpp
(1.01 KB)
📄
Memory.cpp
(1.57 KB)
📄
MemoryBuffer.cpp
(18.99 KB)
📄
NativeFormatting.cpp
(7.54 KB)
📄
OptimizedStructLayout.cpp
(16.7 KB)
📄
Optional.cpp
(530 B)
📄
Parallel.cpp
(5.08 KB)
📄
Path.cpp
(36.52 KB)
📄
PluginLoader.cpp
(1.63 KB)
📄
PrettyStackTrace.cpp
(10.33 KB)
📄
Process.cpp
(3.27 KB)
📄
Program.cpp
(3.54 KB)
📄
RISCVAttributeParser.cpp
(2.06 KB)
📄
RISCVAttributes.cpp
(970 B)
📄
RWMutex.cpp
(3.23 KB)
📄
RandomNumberGenerator.cpp
(2.86 KB)
📄
Regex.cpp
(6.38 KB)
📄
SHA1.cpp
(10.43 KB)
📄
ScaledNumber.cpp
(9.09 KB)
📄
ScopedPrinter.cpp
(1.19 KB)
📄
Signals.cpp
(8.35 KB)
📄
Signposts.cpp
(3.24 KB)
📄
SmallPtrSet.cpp
(9.21 KB)
📄
SmallVector.cpp
(3.99 KB)
📄
SourceMgr.cpp
(20.08 KB)
📄
SpecialCaseList.cpp
(7.48 KB)
📄
Statistic.cpp
(8.85 KB)
📄
StringExtras.cpp
(4.34 KB)
📄
StringMap.cpp
(9.31 KB)
📄
StringRef.cpp
(17.41 KB)
📄
StringSaver.cpp
(882 B)
📄
SuffixTree.cpp
(7.23 KB)
📄
SymbolRemappingReader.cpp
(2.94 KB)
📄
SystemUtils.cpp
(1.06 KB)
📄
TarWriter.cpp
(7.23 KB)
📄
TargetParser.cpp
(9.86 KB)
📄
TargetRegistry.cpp
(4.6 KB)
📄
ThreadLocal.cpp
(1.68 KB)
📄
ThreadPool.cpp
(4.4 KB)
📄
Threading.cpp
(4.55 KB)
📄
TimeProfiler.cpp
(11.63 KB)
📄
Timer.cpp
(14.14 KB)
📄
ToolOutputFile.cpp
(1.83 KB)
📄
TrigramIndex.cpp
(3.24 KB)
📄
Triple.cpp
(53.17 KB)
📄
Twine.cpp
(4.6 KB)
📄
Unicode.cpp
(20.14 KB)
📄
UnicodeCaseFold.cpp
(15.32 KB)
📁
Unix
📄
Valgrind.cpp
(1.6 KB)
📄
VersionTuple.cpp
(2.74 KB)
📄
VirtualFileSystem.cpp
(74.17 KB)
📄
Watchdog.cpp
(738 B)
📁
Windows
📄
WithColor.cpp
(4.35 KB)
📄
X86TargetParser.cpp
(27.21 KB)
📄
YAMLParser.cpp
(68.53 KB)
📄
YAMLTraits.cpp
(28.37 KB)
📄
Z3Solver.cpp
(31.44 KB)
📄
circular_raw_ostream.cpp
(1.3 KB)
📄
raw_os_ostream.cpp
(995 B)
📄
raw_ostream.cpp
(28.97 KB)
📄
regcomp.c
(39.42 KB)
📄
regengine.inc
(26.49 KB)
📄
regerror.c
(4.42 KB)
📄
regex2.h
(6.82 KB)
📄
regex_impl.h
(3.63 KB)
📄
regexec.c
(5.71 KB)
📄
regfree.c
(2.49 KB)
📄
regstrlcpy.c
(1.56 KB)
📄
regutils.h
(2.25 KB)
📄
xxhash.cpp
(4.07 KB)
Editing: CachePruning.cpp
//===-CachePruning.cpp - LLVM Cache Directory Pruning ---------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // // This file implements the pruning of a directory based on least recently used. // //===----------------------------------------------------------------------===// #include "llvm/Support/CachePruning.h" #include "llvm/ADT/StringRef.h" #include "llvm/Support/Debug.h" #include "llvm/Support/Errc.h" #include "llvm/Support/Error.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/Path.h" #include "llvm/Support/raw_ostream.h" #define DEBUG_TYPE "cache-pruning" #include <set> #include <system_error> using namespace llvm; namespace { struct FileInfo { sys::TimePoint<> Time; uint64_t Size; std::string Path; /// Used to determine which files to prune first. Also used to determine /// set membership, so must take into account all fields. bool operator<(const FileInfo &Other) const { return std::tie(Time, Other.Size, Path) < std::tie(Other.Time, Size, Other.Path); } }; } // anonymous namespace /// Write a new timestamp file with the given path. This is used for the pruning /// interval option. static void writeTimestampFile(StringRef TimestampFile) { std::error_code EC; raw_fd_ostream Out(TimestampFile.str(), EC, sys::fs::OF_None); } static Expected<std::chrono::seconds> parseDuration(StringRef Duration) { if (Duration.empty()) return make_error<StringError>("Duration must not be empty", inconvertibleErrorCode()); StringRef NumStr = Duration.slice(0, Duration.size()-1); uint64_t Num; if (NumStr.getAsInteger(0, Num)) return make_error<StringError>("'" + NumStr + "' not an integer", inconvertibleErrorCode()); switch (Duration.back()) { case 's': return std::chrono::seconds(Num); case 'm': return std::chrono::minutes(Num); case 'h': return std::chrono::hours(Num); default: return make_error<StringError>("'" + Duration + "' must end with one of 's', 'm' or 'h'", inconvertibleErrorCode()); } } Expected<CachePruningPolicy> llvm::parseCachePruningPolicy(StringRef PolicyStr) { CachePruningPolicy Policy; std::pair<StringRef, StringRef> P = {"", PolicyStr}; while (!P.second.empty()) { P = P.second.split(':'); StringRef Key, Value; std::tie(Key, Value) = P.first.split('='); if (Key == "prune_interval") { auto DurationOrErr = parseDuration(Value); if (!DurationOrErr) return DurationOrErr.takeError(); Policy.Interval = *DurationOrErr; } else if (Key == "prune_after") { auto DurationOrErr = parseDuration(Value); if (!DurationOrErr) return DurationOrErr.takeError(); Policy.Expiration = *DurationOrErr; } else if (Key == "cache_size") { if (Value.back() != '%') return make_error<StringError>("'" + Value + "' must be a percentage", inconvertibleErrorCode()); StringRef SizeStr = Value.drop_back(); uint64_t Size; if (SizeStr.getAsInteger(0, Size)) return make_error<StringError>("'" + SizeStr + "' not an integer", inconvertibleErrorCode()); if (Size > 100) return make_error<StringError>("'" + SizeStr + "' must be between 0 and 100", inconvertibleErrorCode()); Policy.MaxSizePercentageOfAvailableSpace = Size; } else if (Key == "cache_size_bytes") { uint64_t Mult = 1; switch (tolower(Value.back())) { case 'k': Mult = 1024; Value = Value.drop_back(); break; case 'm': Mult = 1024 * 1024; Value = Value.drop_back(); break; case 'g': Mult = 1024 * 1024 * 1024; Value = Value.drop_back(); break; } uint64_t Size; if (Value.getAsInteger(0, Size)) return make_error<StringError>("'" + Value + "' not an integer", inconvertibleErrorCode()); Policy.MaxSizeBytes = Size * Mult; } else if (Key == "cache_size_files") { if (Value.getAsInteger(0, Policy.MaxSizeFiles)) return make_error<StringError>("'" + Value + "' not an integer", inconvertibleErrorCode()); } else { return make_error<StringError>("Unknown key: '" + Key + "'", inconvertibleErrorCode()); } } return Policy; } /// Prune the cache of files that haven't been accessed in a long time. bool llvm::pruneCache(StringRef Path, CachePruningPolicy Policy) { using namespace std::chrono; if (Path.empty()) return false; bool isPathDir; if (sys::fs::is_directory(Path, isPathDir)) return false; if (!isPathDir) return false; Policy.MaxSizePercentageOfAvailableSpace = std::min(Policy.MaxSizePercentageOfAvailableSpace, 100u); if (Policy.Expiration == seconds(0) && Policy.MaxSizePercentageOfAvailableSpace == 0 && Policy.MaxSizeBytes == 0 && Policy.MaxSizeFiles == 0) { LLVM_DEBUG(dbgs() << "No pruning settings set, exit early\n"); // Nothing will be pruned, early exit return false; } // Try to stat() the timestamp file. SmallString<128> TimestampFile(Path); sys::path::append(TimestampFile, "llvmcache.timestamp"); sys::fs::file_status FileStatus; const auto CurrentTime = system_clock::now(); if (auto EC = sys::fs::status(TimestampFile, FileStatus)) { if (EC == errc::no_such_file_or_directory) { // If the timestamp file wasn't there, create one now. writeTimestampFile(TimestampFile); } else { // Unknown error? return false; } } else { if (!Policy.Interval) return false; if (Policy.Interval != seconds(0)) { // Check whether the time stamp is older than our pruning interval. // If not, do nothing. const auto TimeStampModTime = FileStatus.getLastModificationTime(); auto TimeStampAge = CurrentTime - TimeStampModTime; if (TimeStampAge <= *Policy.Interval) { LLVM_DEBUG(dbgs() << "Timestamp file too recent (" << duration_cast<seconds>(TimeStampAge).count() << "s old), do not prune.\n"); return false; } } // Write a new timestamp file so that nobody else attempts to prune. // There is a benign race condition here, if two processes happen to // notice at the same time that the timestamp is out-of-date. writeTimestampFile(TimestampFile); } // Keep track of files to delete to get below the size limit. // Order by time of last use so that recently used files are preserved. std::set<FileInfo> FileInfos; uint64_t TotalSize = 0; // Walk the entire directory cache, looking for unused files. std::error_code EC; SmallString<128> CachePathNative; sys::path::native(Path, CachePathNative); // Walk all of the files within this directory. for (sys::fs::directory_iterator File(CachePathNative, EC), FileEnd; File != FileEnd && !EC; File.increment(EC)) { // Ignore any files not beginning with the string "llvmcache-". This // includes the timestamp file as well as any files created by the user. // This acts as a safeguard against data loss if the user specifies the // wrong directory as their cache directory. if (!sys::path::filename(File->path()).startswith("llvmcache-")) continue; // Look at this file. If we can't stat it, there's nothing interesting // there. ErrorOr<sys::fs::basic_file_status> StatusOrErr = File->status(); if (!StatusOrErr) { LLVM_DEBUG(dbgs() << "Ignore " << File->path() << " (can't stat)\n"); continue; } // If the file hasn't been used recently enough, delete it const auto FileAccessTime = StatusOrErr->getLastAccessedTime(); auto FileAge = CurrentTime - FileAccessTime; if (Policy.Expiration != seconds(0) && FileAge > Policy.Expiration) { LLVM_DEBUG(dbgs() << "Remove " << File->path() << " (" << duration_cast<seconds>(FileAge).count() << "s old)\n"); sys::fs::remove(File->path()); continue; } // Leave it here for now, but add it to the list of size-based pruning. TotalSize += StatusOrErr->getSize(); FileInfos.insert({FileAccessTime, StatusOrErr->getSize(), File->path()}); } auto FileInfo = FileInfos.begin(); size_t NumFiles = FileInfos.size(); auto RemoveCacheFile = [&]() { // Remove the file. sys::fs::remove(FileInfo->Path); // Update size TotalSize -= FileInfo->Size; NumFiles--; LLVM_DEBUG(dbgs() << " - Remove " << FileInfo->Path << " (size " << FileInfo->Size << "), new occupancy is " << TotalSize << "%\n"); ++FileInfo; }; // Prune for number of files. if (Policy.MaxSizeFiles) while (NumFiles > Policy.MaxSizeFiles) RemoveCacheFile(); // Prune for size now if needed if (Policy.MaxSizePercentageOfAvailableSpace > 0 || Policy.MaxSizeBytes > 0) { auto ErrOrSpaceInfo = sys::fs::disk_space(Path); if (!ErrOrSpaceInfo) { report_fatal_error("Can't get available size"); } sys::fs::space_info SpaceInfo = ErrOrSpaceInfo.get(); auto AvailableSpace = TotalSize + SpaceInfo.free; if (Policy.MaxSizePercentageOfAvailableSpace == 0) Policy.MaxSizePercentageOfAvailableSpace = 100; if (Policy.MaxSizeBytes == 0) Policy.MaxSizeBytes = AvailableSpace; auto TotalSizeTarget = std::min<uint64_t>( AvailableSpace * Policy.MaxSizePercentageOfAvailableSpace / 100ull, Policy.MaxSizeBytes); LLVM_DEBUG(dbgs() << "Occupancy: " << ((100 * TotalSize) / AvailableSpace) << "% target is: " << Policy.MaxSizePercentageOfAvailableSpace << "%, " << Policy.MaxSizeBytes << " bytes\n"); // Remove the oldest accessed files first, till we get below the threshold. while (TotalSize > TotalSizeTarget && FileInfo != FileInfos.end()) RemoveCacheFile(); } return true; }
Upload File
Create Folder