30using llvm::yaml::Input;
36 std::vector<XRayRecord> &Records) {
38 return make_error<StringError>(
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)
43 return make_error<StringError>(
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());
64 while (Reader.isValidOffset(OffsetPtr)) {
65 if (!Reader.isValidOffsetForDataOfSize(OffsetPtr, 32))
67 std::make_error_code(std::errc::executable_format_error),
68 "Not enough bytes to read a full record at offset %" PRId64
".",
70 auto PreReadOffset = OffsetPtr;
72 if (OffsetPtr == PreReadOffset)
74 std::make_error_code(std::errc::executable_format_error),
75 "Failed reading record type at offset %" PRId64
".", OffsetPtr);
79 Records.emplace_back();
80 auto &
Record = Records.back();
83 PreReadOffset = OffsetPtr;
84 Record.CPU = Reader.getU8(&OffsetPtr);
85 if (OffsetPtr == PreReadOffset)
87 std::make_error_code(std::errc::executable_format_error),
88 "Failed reading CPU field at offset %" PRId64
".", OffsetPtr);
90 PreReadOffset = OffsetPtr;
91 auto Type = Reader.getU8(&OffsetPtr);
92 if (OffsetPtr == PreReadOffset)
94 std::make_error_code(std::errc::executable_format_error),
95 "Failed reading record type field at offset %" PRId64
".",
100 Record.Type = RecordTypes::ENTER;
103 Record.Type = RecordTypes::EXIT;
106 Record.Type = RecordTypes::TAIL_EXIT;
109 Record.Type = RecordTypes::ENTER_ARG;
113 std::make_error_code(std::errc::executable_format_error),
114 "Unknown record type '%d' at offset %" PRId64
".",
Type, OffsetPtr);
117 PreReadOffset = OffsetPtr;
118 Record.FuncId = Reader.getSigned(&OffsetPtr,
sizeof(int32_t));
119 if (OffsetPtr == PreReadOffset)
121 std::make_error_code(std::errc::executable_format_error),
122 "Failed reading function id field at offset %" PRId64
".",
125 PreReadOffset = OffsetPtr;
126 Record.TSC = Reader.getU64(&OffsetPtr);
127 if (OffsetPtr == PreReadOffset)
129 std::make_error_code(std::errc::executable_format_error),
130 "Failed reading TSC field at offset %" PRId64
".", OffsetPtr);
132 PreReadOffset = OffsetPtr;
133 Record.TId = Reader.getU32(&OffsetPtr);
134 if (OffsetPtr == PreReadOffset)
136 std::make_error_code(std::errc::executable_format_error),
137 "Failed reading thread id field at offset %" PRId64
".", OffsetPtr);
139 PreReadOffset = OffsetPtr;
140 Record.PId = Reader.getU32(&OffsetPtr);
141 if (OffsetPtr == PreReadOffset)
143 std::make_error_code(std::errc::executable_format_error),
144 "Failed reading process id at offset %" PRId64
".", OffsetPtr);
149 auto &
Record = Records.back();
154 PreReadOffset = OffsetPtr;
155 int32_t
FuncId = Reader.getSigned(&OffsetPtr,
sizeof(int32_t));
156 if (OffsetPtr == PreReadOffset)
158 std::make_error_code(std::errc::executable_format_error),
159 "Failed reading function id field at offset %" PRId64
".",
162 PreReadOffset = OffsetPtr;
163 auto TId = Reader.getU32(&OffsetPtr);
164 if (OffsetPtr == PreReadOffset)
166 std::make_error_code(std::errc::executable_format_error),
167 "Failed reading thread id field at offset %" PRId64
".", OffsetPtr);
169 PreReadOffset = OffsetPtr;
170 auto PId = Reader.getU32(&OffsetPtr);
171 if (OffsetPtr == PreReadOffset)
173 std::make_error_code(std::errc::executable_format_error),
174 "Failed reading process id field at offset %" PRId64
".",
181 std::make_error_code(std::errc::executable_format_error),
182 "Corrupted log, found arg payload following non-matching "
183 "function+thread record. Record for function %d != %d at offset "
187 PreReadOffset = OffsetPtr;
188 auto Arg = Reader.getU64(&OffsetPtr);
189 if (OffsetPtr == PreReadOffset)
191 std::make_error_code(std::errc::executable_format_error),
192 "Failed reading argument payload at offset %" PRId64
".",
195 Record.CallArgs.push_back(Arg);
200 std::make_error_code(std::errc::executable_format_error),
201 "Unknown record type '%d' at offset %" PRId64
".",
RecordType,
268 if (Data.size() < 32)
270 "Not enough bytes for an XRay FDR log.");
275 if (!FileHeaderOrError)
276 return FileHeaderOrError.takeError();
277 FileHeader = std::move(FileHeaderOrError.get());
280 std::vector<std::unique_ptr<Record>> FDRRecords;
285 while (DE.isValidOffsetForDataOfSize(OffsetPtr, 1)) {
286 auto R =
P.produce();
288 return R.takeError();
289 if (
auto E =
C.consume(std::move(
R.get())))
298 for (
auto &R : FDRRecords)
299 if (
auto E =
R->apply(Indexer))
301 if (
auto E = Indexer.flush())
307 for (
auto &PTB :
Index) {
308 auto &
Blocks = PTB.second;
311 for (
auto *R :
B.Records)
312 if (
auto E =
R->apply(Verifier))
326 for (
auto &PTB :
Index) {
327 auto &
Blocks = PTB.second;
330 return (
L.WallclockTime->seconds() <
R.WallclockTime->seconds() &&
331 L.WallclockTime->nanos() <
R.WallclockTime->nanos());
333 auto Adder = [&](
const XRayRecord &
R) { Records.push_back(R); };
336 for (
auto *R :
B.Records)
337 if (
auto E =
R->apply(Expander))
340 if (
auto E = Expander.flush())
349 std::vector<XRayRecord> &Records) {
354 return make_error<StringError>(
"Failed loading YAML Data.",
In.error());
363 return make_error<StringError>(
365 std::make_error_code(std::errc::invalid_argument));
370 return XRayRecord{R.RecordType, R.CPU, R.Type,
371 R.FuncId, R.TSC, R.TId,
372 R.PId, R.CallArgs, R.Data};
385 return make_error<StringError>(
386 Twine(
"Cannot read log from '") + Filename +
"'", EC);
389 return make_error<StringError>(
390 Twine(
"File '") + Filename +
"' too small for XRay.",
391 std::make_error_code(std::errc::executable_format_error));
397 *FdOrErr, sys::fs::mapped_file_region::mapmode::readonly, FileSize, 0,
401 return make_error<StringError>(
402 Twine(
"Cannot read log from '") + Filename +
"'", EC);
408 auto TraceOrError =
loadTrace(LittleEndianDE, Sort);
412 TraceOrError =
loadTrace(BigEndianDE, Sort);
437 enum BinaryFormatType { NAIVE_FORMAT = 0, FLIGHT_DATA_RECORDER_FORMAT = 1 };
442 if (Version == 1 || Version == 2 || Version == 3) {
444 T.FileHeader,
T.Records))
447 return make_error<StringError>(
448 Twine(
"Unsupported version for Basic/Naive Mode logging: ") +
450 std::make_error_code(std::errc::executable_format_error));
453 case FLIGHT_DATA_RECORDER_FORMAT:
454 if (Version >= 1 && Version <= 5) {
459 return make_error<StringError>(
460 Twine(
"Unsupported version for FDR Mode logging: ") +
Twine(Version),
461 std::make_error_code(std::errc::executable_format_error));
465 if (
auto E = loadYAMLLog(DE.
getData(),
T.FileHeader,
T.Records))
471 return L.TSC < R.TSC;
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
DenseMap< Block *, BlockRelaxAux > Blocks
verify safepoint Safepoint IR Verifier
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.
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.
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.
std::error_code closeFile(file_t &F)
Close the file object.
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.
Expected< Trace > loadTrace(const DataExtractor &Extractor, bool Sort=false)
This function will attempt to load XRay trace records from the provided DataExtractor.
Expected< XRayFileHeader > readBinaryFormatHeader(DataExtractor &HeaderExtractor, uint64_t &OffsetPtr)
Convenience function for loading the file header given a data extractor at a specified offset.
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.
void sort(IteratorTy Start, IteratorTy End)
void consumeError(Error Err)
Consume a Error without doing anything.
Helper object to track which of three possible relocation mechanisms are used for a particular value ...
An XRayRecord is the denormalized view of data associated in a trace.