clang 24.0.0git
AtomicLineLogger.h
Go to the documentation of this file.
1//===- AtomicLineLogger.h ---------------------------------------*- C++ -*-===//
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/// Defines a logger where each line is written atomically to the file. It is
11/// safe to share a logger instance across threads.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_CLANG_BASIC_ATOMICLINELOGGER_H
16#define LLVM_CLANG_BASIC_ATOMICLINELOGGER_H
17
18#include "clang/Basic/LLVM.h"
19#include "llvm/ADT/SmallString.h"
20#include "llvm/Support/raw_ostream.h"
21#include <atomic>
22#include <optional>
23#include <string>
24
25namespace clang {
26
27class LogLine {
28 SmallString<128> Buffer;
29 std::optional<llvm::raw_svector_ostream> FormattingOS;
30 int FD = -1;
31 std::atomic<uint64_t> *DroppedLines = nullptr;
32
33 explicit LogLine(int FD, std::atomic<uint64_t> *DroppedLines);
34
35public:
38 LogLine(const LogLine &) = delete;
39 LogLine &operator=(const LogLine &) = delete;
40 LogLine &operator=(LogLine &&) = delete;
41
42 ~LogLine();
43
44 template <typename T> LogLine &operator<<(const T &Val) {
45 if (FormattingOS)
46 *FormattingOS << Val;
47 return *this;
48 }
49
50 template <typename RangeT>
51 void logArray(StringRef Prefix, StringRef Sep, const RangeT &Arr) {
52 if (FormattingOS) {
53 *FormattingOS << Prefix;
54 for (const auto &C : Arr)
55 *FormattingOS << Sep << C;
56 }
57 }
58
59 friend class AtomicLineLogger;
60};
61
63 int FD = -1;
64 std::string LogPath;
65 std::atomic<uint64_t> DroppedLines{0};
66
67public:
69 AtomicLineLogger(StringRef LogFilePath);
70
71 // AtomicLineLogger is non-movable because LogLines have pointers to the
72 // atomic member DroppedLines.
75
77
78 LogLine log();
79};
80
81} // namespace clang
82
83#endif
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
AtomicLineLogger(AtomicLineLogger &&)=delete
AtomicLineLogger & operator=(AtomicLineLogger &&)=delete
LogLine(const LogLine &)=delete
LogLine & operator<<(const T &Val)
void logArray(StringRef Prefix, StringRef Sep, const RangeT &Arr)
friend class AtomicLineLogger
LogLine & operator=(const LogLine &)=delete
LogLine & operator=(LogLine &&)=delete
The JSON file list parser is used to communicate input to InstallAPI.
const FunctionProtoType * T
@ Other
Other implicit parameter.
Definition Decl.h:1774