LLVM 23.0.0git
OnDiskCASLogger.h
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9/// \file
10/// This file declares interface for OnDiskCASLogger, an interface that can be
11/// used to log CAS events to help debugging CAS errors.
12///
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_CAS_ONDISKLOGGER_H
16#define LLVM_CAS_ONDISKLOGGER_H
17
19#include "llvm/Support/Error.h"
20#include <memory>
21
22namespace llvm {
23class raw_fd_ostream;
24class Twine;
25} // namespace llvm
26
27namespace llvm::cas::ondisk {
28
29/// Interface for logging low-level on-disk cas operations.
30///
31/// This log is intended to mirror the low-level details of the CAS in order to
32/// aid with debugging corruption or other issues with the on-disk format.
33class OnDiskCASLogger {
34public:
35 /// Create or append to a log file inside the given CAS directory \p Path.
36 ///
37 /// \param Path The parent directory of the log file.
38 /// \param LogAllocations Whether to log all low-level allocations. This is
39 /// on the order of twice as expensive to log.
41 open(const Twine &Path, bool LogAllocations);
42
43 /// Create or append to a log file inside the given CAS directory \p Path if
44 /// logging is enabled by the environment variable \c LLVM_CAS_LOG. If
45 /// LLVM_CAS_LOG is set >= 2 then also log allocations.
47 openIfEnabled(const Twine &Path);
48
50
51 /// An offset into an \c OnDiskTrieRawHashMap.
52 using TrieOffset = int64_t;
53
55 size_t SlotI, TrieOffset Expected,
56 TrieOffset New, TrieOffset Previous);
58 uint32_t StartBit, uint32_t NumBits);
63 size_t Before, size_t After);
65 void *Region, size_t Capacity,
66 size_t Size);
67 LLVM_ABI void logMappedFileRegionArenaOom(StringRef Path, size_t Capacity,
68 size_t Size, size_t AllocSize);
71 size_t Size);
74 StringRef Path, uint64_t BootTime, uint64_t ValidationTime,
75 bool CheckHash, bool AllowRecovery, bool Force,
76 std::optional<StringRef> LLVMCas, StringRef ValidationError, bool Skipped,
77 bool Recovered);
80 std::error_code EC);
81 LLVM_ABI void logTempFileRemove(StringRef TmpName, std::error_code EC);
82
83private:
84 OnDiskCASLogger(raw_fd_ostream &OS, bool LogAllocations);
85
87 bool LogAllocations;
88};
89
90} // namespace llvm::cas::ondisk
91
92#endif // LLVM_CAS_ONDISKLOGGER_H
#define LLVM_ABI
Definition Compiler.h:213
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
Tagged union holding either a T or a Error.
Definition Error.h:486
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition Twine.h:82
LLVM_ABI void logTempFileRemove(StringRef TmpName, std::error_code EC)
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.
@ Recovered
The data was invalid, but was recovered.
@ Skipped
Validation was skipped, as it was not needed.
This is an optimization pass for GlobalISel generic memory operations.
Definition Types.h:26