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());
55 Records.reserve(NumReservations);
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
".",
103 Record.Type = RecordTypes::ENTER;
106 Record.Type = RecordTypes::EXIT;
109 Record.Type = RecordTypes::TAIL_EXIT;
112 Record.Type = RecordTypes::ENTER_ARG;
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 "
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;
314 for (
auto *R :
B.Records)
315 if (
auto E =
R->apply(Verifier))
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());
339 for (
auto *R :
B.Records)
340 if (
auto E =
R->apply(Expander))
343 if (
auto E = Expander.flush())
352 std::vector<XRayRecord> &Records) {
357 return make_error<StringError>(
"Failed loading YAML Data.",
In.error());
366 return make_error<StringError>(
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};
388 return make_error<StringError>(
389 Twine(
"Cannot read log from '") + Filename +
"'", EC);
392 return make_error<StringError>(
393 Twine(
"File '") + Filename +
"' too small for XRay.",
394 std::make_error_code(std::errc::executable_format_error));
400 *FdOrErr, sys::fs::mapped_file_region::mapmode::readonly, FileSize, 0,
404 return make_error<StringError>(
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 };
445 if (Version == 1 || Version == 2 || Version == 3) {
447 T.FileHeader,
T.Records))
450 return make_error<StringError>(
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:
457 if (Version >= 1 && Version <= 5) {
462 return make_error<StringError>(
463 Twine(
"Unsupported version for FDR Mode logging: ") +
Twine(Version),
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< OcamlGC > B("ocaml", "ocaml 3.10-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.
llvm::SmallVector< std::shared_ptr< RecordsSlice >, 4 > Records
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)
constexpr T divideCeil(U Numerator, V Denominator)
Returns the integer ceil(Numerator / Denominator).
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.