43OnDiskCASLogger::OnDiskCASLogger(
raw_fd_ostream &OS,
bool LogAllocations)
44 : OS(OS), LogAllocations(LogAllocations) {}
59Expected<std::unique_ptr<OnDiskCASLogger>>
61 const char *V = getenv(
"LLVM_CAS_LOG");
74 Path.toVector(FullPath);
86 return std::unique_ptr<OnDiskCASLogger>(
87 new OnDiskCASLogger{*OS.release(), LogAllocations});
95 return T.tv_sec * 1000 +
T.tv_usec / 1000;
97 auto Time = std::chrono::system_clock::now();
98 auto Millis = std::chrono::duration_cast<std::chrono::milliseconds>(
99 Time.time_since_epoch());
100 return Millis.count();
108class TextLogLine :
public raw_svector_ostream {
110 TextLogLine(raw_ostream &LogOS) : raw_svector_ostream(Buffer), LogOS(LogOS) {
116 LogOS.write(Buffer.data(), Buffer.size());
119 static void startLogMsg(raw_ostream &OS) {
121 OS <<
format(
"%lld.%0.3lld", Millis / 1000, Millis % 1000);
125 static void finishLogMsg(raw_ostream &OS) { OS <<
'\n'; }
129 SmallString<128> Buffer;
146 Log <<
"cmpxcgh subtrie region=" <<
Region <<
" offset=";
148 Log <<
" slot=" << SlotI <<
" expected=";
160 Log <<
"create subtrie region=" <<
Region <<
" offset=";
162 Log <<
" start-bit=" << StartBit <<
" num-bits=" << NumBits;
168 Log <<
"create record region=" <<
Region <<
" offset=";
170 Log <<
" hash=" <<
format_bytes(Hash, std::nullopt, 32, 32);
177 Log <<
"resize mapped file '" << Path <<
"' from=" << Before
186 std::error_code EC = status(FD, Stat);
189 Log <<
"mmap '" << Path <<
"' " <<
Region;
190 Log <<
" size=" <<
Size <<
" capacity=" << Capacity;
192 Log <<
" failed status with error: " << EC.message();
200 size_t Capacity,
size_t Size,
203 Log <<
"oom '" << Path <<
"' old-size=" <<
Size <<
" capacity=" << Capacity
204 <<
"alloc-size=" << AllocSize;
208 Log <<
"close mmap '" << Path <<
"'";
216 Log <<
"alloc " <<
Region <<
" offset=";
218 Log <<
" size=" <<
Size;
223 Log <<
"collect garbage '" << Path <<
"'";
228 bool AllowRecovery,
bool Force, std::optional<StringRef> LLVMCas,
231 Log <<
"validate-if-needed '" << Path <<
"'";
232 Log <<
" boot=" << BootTime <<
" last-valid=" << ValidationTime;
233 Log <<
" check-hash=" << CheckHash <<
" allow-recovery=" << AllowRecovery;
234 Log <<
" force=" << Force;
236 Log <<
" llvm-cas=" << *LLVMCas;
241 if (!ValidationError.
empty())
242 Log <<
" data was invalid " << ValidationError;
247 Log <<
"standalone file create '" << Name <<
"'";
251 std::error_code EC) {
253 Log <<
"standalone file rename '" << TmpName <<
"' to '" << Name <<
"'";
255 Log <<
" error: " << EC.message();
260 Log <<
"standalone file remove '" << TmpName <<
"'";
262 Log <<
" error: " << EC.message();
static void formatTrieOffset(raw_ostream &OS, int64_t Off)
static uint64_t getTimestampMillis()
static bool isDisabledEnv(StringRef V)
static constexpr StringLiteral Filename
This file declares interface for OnDiskCASLogger, an interface that can be used to log CAS events to ...
Provides a library for accessing information about this process and other processes on the operating ...
This file implements the StringSwitch template, which mimics a switch() statement whose cases are str...
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Tagged union holding either a T or a Error.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
A wrapper around a string literal that serves as a proxy for constructing global tables of StringRefs...
StringRef - Represent a constant reference to a string, i.e.
bool getAsInteger(unsigned Radix, T &Result) const
Parse the current string as an integer of the specified radix.
constexpr bool empty() const
empty - Check if the string is empty.
A switch()-like statement whose cases are string literals.
StringSwitch & CaseLower(StringLiteral S, T Value)
StringSwitch & Case(StringLiteral S, T Value)
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
LLVM_ABI void logTempFileRemove(StringRef TmpName, std::error_code EC)
LLVM_ABI ~OnDiskCASLogger()
LLVM_ABI void logSubtrieHandleCreate(void *Region, TrieOffset Trie, uint32_t StartBit, uint32_t NumBits)
int64_t TrieOffset
An offset into an OnDiskTrieRawHashMap.
LLVM_ABI void logMappedFileRegionArenaAllocate(void *Region, TrieOffset Off, size_t Size)
LLVM_ABI void logMappedFileRegionArenaResizeFile(StringRef Path, size_t Before, size_t After)
LLVM_ABI void logTempFileKeep(StringRef TmpName, StringRef Name, std::error_code EC)
LLVM_ABI void logUnifiedOnDiskCacheValidateIfNeeded(StringRef Path, uint64_t BootTime, uint64_t ValidationTime, bool CheckHash, bool AllowRecovery, bool Force, std::optional< StringRef > LLVMCas, StringRef ValidationError, bool Skipped, bool Recovered)
LLVM_ABI void logMappedFileRegionArenaCreate(StringRef Path, int FD, void *Region, size_t Capacity, size_t Size)
static LLVM_ABI Expected< std::unique_ptr< OnDiskCASLogger > > open(const Twine &Path, bool LogAllocations)
Create or append to a log file inside the given CAS directory Path.
static LLVM_ABI Expected< std::unique_ptr< OnDiskCASLogger > > openIfEnabled(const Twine &Path)
Create or append to a log file inside the given CAS directory Path if logging is enabled by the envir...
LLVM_ABI void logMappedFileRegionArenaClose(StringRef Path)
LLVM_ABI void logUnifiedOnDiskCacheCollectGarbage(StringRef Path)
LLVM_ABI void logTempFileCreate(StringRef Name)
LLVM_ABI void logMappedFileRegionArenaOom(StringRef Path, size_t Capacity, size_t Size, size_t AllocSize)
LLVM_ABI void logSubtrieHandleCmpXchg(void *Region, TrieOffset Trie, size_t SlotI, TrieOffset Expected, TrieOffset New, TrieOffset Previous)
LLVM_ABI void logHashMappedTrieHandleCreateRecord(void *Region, TrieOffset TrieOffset, ArrayRef< uint8_t > Hash)
A raw_ostream that writes to a file descriptor.
This class implements an extremely fast bulk output stream that can only output to a stream.
static LLVM_ABI Pid getProcessId()
Get the process's identifier.
uint64_t getDevice() const
Represents the result of a call to sys::fs::status().
LLVM_ABI UniqueID getUniqueID() const
@ Recovered
The data was invalid, but was recovered.
@ Skipped
Validation was skipped, as it was not needed.
@ OF_Append
The file should be opened in append mode.
@ CD_OpenAlways
CD_OpenAlways - When opening a file:
LLVM_ABI void append(SmallVectorImpl< char > &path, const Twine &a, const Twine &b="", const Twine &c="", const Twine &d="")
Append to path.
This is an optimization pass for GlobalISel generic memory operations.
Error createFileError(const Twine &F, Error E)
Concatenate a source file path and/or name with an Error.
FormattedNumber format_hex(uint64_t N, unsigned Width, bool Upper=false)
format_hex - Output N as a fixed width hexadecimal.
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
LLVM_ABI uint64_t get_threadid()
Return the current thread id, as used in various OS system calls.
FormattedBytes format_bytes(ArrayRef< uint8_t > Bytes, std::optional< uint64_t > FirstByteOffset=std::nullopt, uint32_t NumPerLine=16, uint8_t ByteGroupSize=4, uint32_t IndentLevel=0, bool Upper=false)