36 std::vector<XRayRecord> &Records) {
39 "Not enough bytes for an XRay log.",
40 std::make_error_code(std::errc::invalid_argument));
42 if (
Data.size() - 32 == 0 ||
Data.size() % 32 != 0)
44 "Invalid-sized XRay data.",
45 std::make_error_code(std::errc::invalid_argument));
50 if (!FileHeaderOrError)
51 return FileHeaderOrError.takeError();
52 FileHeader = std::move(FileHeaderOrError.get());
67 while (Reader.isValidOffset(OffsetPtr)) {
68 if (!Reader.isValidOffsetForDataOfSize(OffsetPtr, 32))
70 std::make_error_code(std::errc::executable_format_error),
71 "Not enough bytes to read a full record at offset %" PRId64
".",
73 auto PreReadOffset = OffsetPtr;
75 if (OffsetPtr == PreReadOffset)
77 std::make_error_code(std::errc::executable_format_error),
78 "Failed reading record type at offset %" PRId64
".", OffsetPtr);
86 PreReadOffset = OffsetPtr;
87 Record.CPU = Reader.getU8(&OffsetPtr);
88 if (OffsetPtr == PreReadOffset)
90 std::make_error_code(std::errc::executable_format_error),
91 "Failed reading CPU field at offset %" PRId64
".", OffsetPtr);
93 PreReadOffset = OffsetPtr;
94 auto Type = Reader.getU8(&OffsetPtr);
95 if (OffsetPtr == PreReadOffset)
97 std::make_error_code(std::errc::executable_format_error),
98 "Failed reading record type field at offset %" PRId64
".",
116 std::make_error_code(std::errc::executable_format_error),
117 "Unknown record type '%d' at offset %" PRId64
".",
Type, OffsetPtr);
120 PreReadOffset = OffsetPtr;
121 Record.FuncId = Reader.getSigned(&OffsetPtr,
sizeof(int32_t));
122 if (OffsetPtr == PreReadOffset)
124 std::make_error_code(std::errc::executable_format_error),
125 "Failed reading function id field at offset %" PRId64
".",
128 PreReadOffset = OffsetPtr;
129 Record.TSC = Reader.getU64(&OffsetPtr);
130 if (OffsetPtr == PreReadOffset)
132 std::make_error_code(std::errc::executable_format_error),
133 "Failed reading TSC field at offset %" PRId64
".", OffsetPtr);
135 PreReadOffset = OffsetPtr;
136 Record.TId = Reader.getU32(&OffsetPtr);
137 if (OffsetPtr == PreReadOffset)
139 std::make_error_code(std::errc::executable_format_error),
140 "Failed reading thread id field at offset %" PRId64
".", OffsetPtr);
142 PreReadOffset = OffsetPtr;
143 Record.PId = Reader.getU32(&OffsetPtr);
144 if (OffsetPtr == PreReadOffset)
146 std::make_error_code(std::errc::executable_format_error),
147 "Failed reading process id at offset %" PRId64
".", OffsetPtr);
157 PreReadOffset = OffsetPtr;
158 int32_t FuncId = Reader.getSigned(&OffsetPtr,
sizeof(int32_t));
159 if (OffsetPtr == PreReadOffset)
161 std::make_error_code(std::errc::executable_format_error),
162 "Failed reading function id field at offset %" PRId64
".",
165 PreReadOffset = OffsetPtr;
166 auto TId = Reader.getU32(&OffsetPtr);
167 if (OffsetPtr == PreReadOffset)
169 std::make_error_code(std::errc::executable_format_error),
170 "Failed reading thread id field at offset %" PRId64
".", OffsetPtr);
172 PreReadOffset = OffsetPtr;
173 auto PId = Reader.getU32(&OffsetPtr);
174 if (OffsetPtr == PreReadOffset)
176 std::make_error_code(std::errc::executable_format_error),
177 "Failed reading process id field at offset %" PRId64
".",
184 std::make_error_code(std::errc::executable_format_error),
185 "Corrupted log, found arg payload following non-matching "
186 "function+thread record. Record for function %d != %d at offset "
188 Record.FuncId, FuncId, OffsetPtr);
190 PreReadOffset = OffsetPtr;
191 auto Arg = Reader.getU64(&OffsetPtr);
192 if (OffsetPtr == PreReadOffset)
194 std::make_error_code(std::errc::executable_format_error),
195 "Failed reading argument payload at offset %" PRId64
".",
198 Record.CallArgs.push_back(Arg);
203 std::make_error_code(std::errc::executable_format_error),
204 "Unknown record type '%d' at offset %" PRId64
".",
RecordType,
271 if (
Data.size() < 32)
273 "Not enough bytes for an XRay FDR log.");
278 if (!FileHeaderOrError)
279 return FileHeaderOrError.takeError();
280 FileHeader = std::move(FileHeaderOrError.get());
283 std::vector<std::unique_ptr<Record>> FDRRecords;
288 while (DE.isValidOffsetForDataOfSize(OffsetPtr, 1)) {
289 auto R =
P.produce();
291 return R.takeError();
292 if (
auto E =
C.consume(std::move(
R.get())))
301 for (
auto &R : FDRRecords)
302 if (
auto E =
R->apply(Indexer))
304 if (
auto E = Indexer.flush())
310 for (
auto &PTB : Index) {
311 auto &Blocks = PTB.second;
312 for (
auto &
B : Blocks) {
314 for (
auto *R :
B.Records)
315 if (
auto E =
R->apply(Verifier))
317 if (
auto E = Verifier.verify())
329 for (
auto &PTB : Index) {
330 auto &Blocks = PTB.second;
333 return (
L.WallclockTime->seconds() <
R.WallclockTime->seconds() &&
334 L.WallclockTime->nanos() <
R.WallclockTime->nanos());
338 for (
auto &
B : Blocks) {
339 for (
auto *R :
B.Records)
340 if (
auto E =
R->apply(Expander))
343 if (
auto E = Expander.flush())
352 std::vector<XRayRecord> &Records) {
368 std::make_error_code(std::errc::invalid_argument));
373 return XRayRecord{R.RecordType, R.CPU, R.Type,
374 R.FuncId, R.TSC, R.TId,
375 R.PId, R.CallArgs, R.Data};
389 Twine(
"Cannot read log from '") + Filename +
"'", EC);
393 Twine(
"File '") + Filename +
"' too small for XRay.",
394 std::make_error_code(std::errc::executable_format_error));
405 Twine(
"Cannot read log from '") + Filename +
"'", EC);
411 auto TraceOrError =
loadTrace(LittleEndianDE, Sort);
415 TraceOrError =
loadTrace(BigEndianDE, Sort);
440 enum BinaryFormatType { NAIVE_FORMAT = 0, FLIGHT_DATA_RECORDER_FORMAT = 1 };
447 T.FileHeader,
T.Records))
451 Twine(
"Unsupported version for Basic/Naive Mode logging: ") +
453 std::make_error_code(std::errc::executable_format_error));
456 case FLIGHT_DATA_RECORDER_FORMAT:
464 std::make_error_code(std::errc::executable_format_error));
468 if (
auto E = loadYAMLLog(DE.
getData(),
T.FileHeader,
T.Records))
474 return L.TSC < R.TSC;
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
FunctionLoweringInfo::StatepointRelocationRecord RecordType
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
Tagged union holding either a T or a Error.
Error takeError()
Take ownership of the stored error.
reference emplace_back(ArgTypes &&... Args)
void reserve(size_type N)
void push_back(const T &Elt)
StringRef - Represent a constant reference to a string, i.e.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
The instances of the Type class are immutable: once they are created, they are never changed.
This class represents a memory mapped file.
LLVM_ABI size_t size() const
@ readonly
May only access map via const_data as read only.
LLVM_ABI char * data() const
DenseMap< std::pair< uint64_t, int32_t >, std::vector< Block > > Index
A Trace object represents the records that have been loaded from XRay log files generated by instrume...
@ C
The default llvm calling convention, compatible with C.
llvm::SmallVector< std::shared_ptr< RecordsSlice >, 4 > Records
LLVM_ABI std::error_code closeFile(file_t &F)
Close the file object.
LLVM_ABI Expected< file_t > openNativeFileForRead(const Twine &Name, OpenFlags Flags=OF_None, SmallVectorImpl< char > *RealPath=nullptr)
Opens the file with the given name in a read-only mode, returning its open file descriptor.
std::error_code file_size(const Twine &Path, uint64_t &Result)
Get file size.
LLVM_ABI Expected< Trace > loadTrace(const DataExtractor &Extractor, bool Sort=false)
This function will attempt to load XRay trace records from the provided DataExtractor.
LLVM_ABI Expected< XRayFileHeader > readBinaryFormatHeader(DataExtractor &HeaderExtractor, uint64_t &OffsetPtr)
Convenience function for loading the file header given a data extractor at a specified offset.
LLVM_ABI Expected< Trace > loadTraceFile(StringRef Filename, bool Sort=false)
This function will attempt to load XRay trace records from the provided |Filename|.
This is an optimization pass for GlobalISel generic memory operations.
void stable_sort(R &&Range)
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
FunctionAddr VTableAddr uintptr_t uintptr_t Version
void sort(IteratorTy Start, IteratorTy End)
Error make_error(ArgTs &&... Args)
Make a Error instance representing failure using the given error info type.
constexpr T divideCeil(U Numerator, V Denominator)
Returns the integer ceil(Numerator / Denominator).
FunctionAddr VTableAddr uintptr_t uintptr_t Data
void consumeError(Error Err)
Consume a Error without doing anything.
An XRayRecord is the denormalized view of data associated in a trace.