34 std::vector<XRayRecord> &Records) {
37 "Not enough bytes for an XRay log.",
38 std::make_error_code(std::errc::invalid_argument));
40 if (
Data.size() - 32 == 0 ||
Data.size() % 32 != 0)
42 "Invalid-sized XRay data.",
43 std::make_error_code(std::errc::invalid_argument));
48 if (!FileHeaderOrError)
49 return FileHeaderOrError.takeError();
50 FileHeader = std::move(FileHeaderOrError.get());
53 Records.
reserve(NumReservations);
68 std::make_error_code(std::errc::executable_format_error),
69 "Not enough bytes to read a full record at offset %" PRId64
".",
71 auto PreReadOffset = OffsetPtr;
73 if (OffsetPtr == PreReadOffset)
75 std::make_error_code(std::errc::executable_format_error),
76 "Failed reading record type at offset %" PRId64
".", OffsetPtr);
84 PreReadOffset = OffsetPtr;
86 if (OffsetPtr == PreReadOffset)
88 std::make_error_code(std::errc::executable_format_error),
89 "Failed reading CPU field at offset %" PRId64
".", OffsetPtr);
91 PreReadOffset = OffsetPtr;
93 if (OffsetPtr == PreReadOffset)
95 std::make_error_code(std::errc::executable_format_error),
96 "Failed reading record type field at offset %" PRId64
".",
114 std::make_error_code(std::errc::executable_format_error),
115 "Unknown record type '%d' at offset %" PRId64
".",
Type, OffsetPtr);
118 PreReadOffset = OffsetPtr;
120 if (OffsetPtr == PreReadOffset)
122 std::make_error_code(std::errc::executable_format_error),
123 "Failed reading function id field at offset %" PRId64
".",
126 PreReadOffset = OffsetPtr;
128 if (OffsetPtr == PreReadOffset)
130 std::make_error_code(std::errc::executable_format_error),
131 "Failed reading TSC field at offset %" PRId64
".", OffsetPtr);
133 PreReadOffset = OffsetPtr;
135 if (OffsetPtr == PreReadOffset)
137 std::make_error_code(std::errc::executable_format_error),
138 "Failed reading thread id field at offset %" PRId64
".", OffsetPtr);
140 PreReadOffset = OffsetPtr;
142 if (OffsetPtr == PreReadOffset)
144 std::make_error_code(std::errc::executable_format_error),
145 "Failed reading process id at offset %" PRId64
".", OffsetPtr);
155 PreReadOffset = OffsetPtr;
156 int32_t FuncId = Reader.
getSigned(&OffsetPtr,
sizeof(int32_t));
157 if (OffsetPtr == PreReadOffset)
159 std::make_error_code(std::errc::executable_format_error),
160 "Failed reading function id field at offset %" PRId64
".",
163 PreReadOffset = OffsetPtr;
164 auto TId = Reader.
getU32(&OffsetPtr);
165 if (OffsetPtr == PreReadOffset)
167 std::make_error_code(std::errc::executable_format_error),
168 "Failed reading thread id field at offset %" PRId64
".", OffsetPtr);
170 PreReadOffset = OffsetPtr;
171 auto PId = Reader.
getU32(&OffsetPtr);
172 if (OffsetPtr == PreReadOffset)
174 std::make_error_code(std::errc::executable_format_error),
175 "Failed reading process id field at offset %" PRId64
".",
182 std::make_error_code(std::errc::executable_format_error),
183 "Corrupted log, found arg payload following non-matching "
184 "function+thread record. Record for function %d != %d at offset "
186 Record.FuncId, FuncId, OffsetPtr);
188 PreReadOffset = OffsetPtr;
189 auto Arg = Reader.
getU64(&OffsetPtr);
190 if (OffsetPtr == PreReadOffset)
192 std::make_error_code(std::errc::executable_format_error),
193 "Failed reading argument payload at offset %" PRId64
".",
196 Record.CallArgs.push_back(Arg);
201 std::make_error_code(std::errc::executable_format_error),
202 "Unknown record type '%d' at offset %" PRId64
".",
RecordType,
268 std::vector<XRayRecord> &Records) {
270 if (
Data.size() < 32)
272 "Not enough bytes for an XRay FDR log.");
277 if (!FileHeaderOrError)
278 return FileHeaderOrError.takeError();
279 FileHeader = std::move(FileHeaderOrError.get());
282 std::vector<std::unique_ptr<Record>> FDRRecords;
288 auto R =
P.produce();
290 return R.takeError();
291 if (
auto E =
C.consume(std::move(R.get())))
300 for (
auto &R : FDRRecords)
301 if (
auto E = R->apply(Indexer))
303 if (
auto E = Indexer.
flush())
309 for (
auto &PTB : Index) {
310 auto &Blocks = PTB.second;
311 for (
auto &
B : Blocks) {
313 for (
auto *R :
B.Records)
314 if (
auto E = R->apply(Verifier))
316 if (
auto E = Verifier.verify())
328 for (
auto &PTB : Index) {
329 auto &Blocks = PTB.second;
332 return (L.WallclockTime->seconds() < R.WallclockTime->seconds() &&
333 L.WallclockTime->nanos() < R.WallclockTime->nanos());
337 for (
auto &
B : Blocks) {
338 for (
auto *R :
B.Records)
339 if (
auto E = R->apply(Expander))
342 if (
auto E = Expander.
flush())
351 std::vector<XRayRecord> &Records) {
367 std::make_error_code(std::errc::invalid_argument));
372 return XRayRecord{R.RecordType, R.CPU, R.Type,
373 R.FuncId, R.TSC, R.TId,
374 R.PId, R.CallArgs, R.Data};
387 Twine(
"Cannot read log from '") + Filename +
"'", EC);
391 Twine(
"File '") + Filename +
"' too small for XRay.",
392 std::make_error_code(std::errc::executable_format_error));
403 Twine(
"Cannot read log from '") + Filename +
"'", EC);
409 auto TraceOrError =
loadTrace(LittleEndianDE, Sort);
413 TraceOrError =
loadTrace(BigEndianDE, Sort);
438 enum BinaryFormatType { NAIVE_FORMAT = 0, FLIGHT_DATA_RECORDER_FORMAT = 1 };
445 T.FileHeader,
T.Records))
449 Twine(
"Unsupported version for Basic/Naive Mode logging: ") +
451 std::make_error_code(std::errc::executable_format_error));
454 case FLIGHT_DATA_RECORDER_FORMAT:
462 std::make_error_code(std::errc::executable_format_error));
472 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
static Error loadFDRLog(StringRef Data, bool IsLittleEndian, XRayFileHeader &FileHeader, std::vector< XRayRecord > &Records)
Reads a log in FDR mode for version 1 of this binary format.
static Error loadNaiveFormatLog(StringRef Data, bool IsLittleEndian, XRayFileHeader &FileHeader, std::vector< XRayRecord > &Records)
static Error loadYAMLLog(StringRef Data, XRayFileHeader &FileHeader, std::vector< XRayRecord > &Records)
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
Error flush()
The flush() function will clear out the current state of the visitor, to allow for explicitly flushin...
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_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.