[llvm] [CAS] Add OnDiskCASLogger to help logging/debugging CAS (PR #174462)
Paul Kirth via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 5 13:49:40 PST 2026
================
@@ -0,0 +1,89 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+//
+/// \file
+/// This file declares interface for OnDiskCASLogger, an interface that can be
+/// used to log CAS events to help debugging CAS errors.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CAS_ONDISKLOGGER_H
+#define LLVM_CAS_ONDISKLOGGER_H
+
+#include "llvm/Support/Error.h"
+#include <memory>
+
+namespace llvm {
+class raw_fd_ostream;
+class Twine;
+} // namespace llvm
+
+namespace llvm::cas::ondisk {
+
+/// Interface for logging low-level on-disk cas operations.
+///
+/// This log is intended to mirror the low-level details of the CAS in order to
+/// aid with debugging corruption or other issues with the on-disk format.
+class OnDiskCASLogger {
+public:
+ /// Create or append to a log file inside the given CAS directory \p Path.
+ ///
+ /// \param Path The parent directory of the log file.
+ /// \param LogAllocations Whether to log all low-level allocations. This is
+ /// on the order of twice as expensive to log.
+ static Expected<std::unique_ptr<OnDiskCASLogger>> open(const Twine &Path,
+ bool LogAllocations);
+
+ /// Create or append to a log file inside the given CAS directory \p Path if
+ /// logging is enabled by the environment variable \c LLVM_CAS_LOG. If
+ /// LLVM_CAS_LOG is set >= 2 then also log allocations.
+ static Expected<std::unique_ptr<OnDiskCASLogger>>
+ openIfEnabled(const Twine &Path);
+
+ ~OnDiskCASLogger();
+
+ /// An offset into an \c OnDiskTrieRawHashMap.
+ using TrieOffset = int64_t;
+
+ void log_compare_exchange_strong(void *Region, TrieOffset Trie, size_t SlotI,
+ TrieOffset Expected, TrieOffset New,
+ TrieOffset Previous);
+ void log_SubtrieHandle_create(void *Region, TrieOffset Trie,
----------------
ilovepi wrote:
The mixed case w/ underscores seems quite odd for LLVM. Is this an existing convention? I think we typically just follow the style guide.
https://github.com/llvm/llvm-project/pull/174462
More information about the llvm-commits
mailing list