15#include "llvm/ADT/StringRef.h"
16#include "llvm/Support/Errno.h"
17#include "llvm/Support/FileSystem.h"
18#include "llvm/Support/Format.h"
19#include "llvm/Support/Process.h"
20#include "llvm/Support/Threading.h"
35 return T.tv_sec * 1000 + T.tv_usec / 1000;
37 auto Time = std::chrono::system_clock::now();
38 auto Millis = std::chrono::duration_cast<std::chrono::milliseconds>(
39 Time.time_since_epoch());
40 return Millis.count();
49 ssize_t Written = llvm::sys::RetryAfterSignal(-1, write, FD,
Data, Size);
50 return Written >= 0 && (
static_cast<size_t>(Written) == Size);
52 (void)FD, (
void)
Data, (void)Size;
53 llvm_unreachable(
"Logging not supported on Windows!");
59 : FormattingOS(Buffer), FD(FD), DroppedLines(DroppedLines) {
61 *FormattingOS << llvm::format(
"[%lld.%0.3lld]", Millis / 1000, Millis % 1000);
62 *FormattingOS <<
' ' << llvm::sys::Process::getProcessId() <<
' '
63 << llvm::get_threadid() <<
": ";
68 DroppedLines(
Other.DroppedLines) {
69 if (
Other.FormattingOS)
70 FormattingOS.emplace(Buffer);
73 Other.FormattingOS.reset();
75 Other.DroppedLines =
nullptr;
81 *FormattingOS <<
"\n";
83 DroppedLines->fetch_add(1, std::memory_order_relaxed);
87 : LogPath(LogFilePath.str()) {
89 if (LogFilePath.empty())
92 std::error_code EC = llvm::sys::fs::openFileForWrite(
93 LogFilePath, FD, llvm::sys::fs::CD_OpenAlways, llvm::sys::fs::OF_Append);
95 llvm::errs() <<
"warning: unable to open log file '" << LogFilePath
96 <<
"': " << EC.message() <<
"\n";
107 return LogLine(FD, &DroppedLines);
114 if (uint64_t Dropped = DroppedLines.load(std::memory_order_relaxed))
115 llvm::errs() <<
"warning: log '" << LogPath
116 <<
"' is incomplete: " << Dropped
117 <<
" line(s) dropped due to write errors\n";
118 llvm::sys::Process::SafelyCloseFileDescriptor(FD);
static bool writeLineToFD(int FD, const char *Data, size_t Size)
static uint64_t getTimestampMillis()
Defines a logger where each line is written atomically to the file.
The JSON file list parser is used to communicate input to InstallAPI.
if(T->getSizeExpr()) TRY_TO(TraverseStmt(const_cast< Expr * >(T -> getSizeExpr())))
@ Other
Other implicit parameter.