[llvm] r345798 - [XRay] Add CPU ID in Custom Event FDR Records
Dean Michael Berris via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 31 17:18:53 PDT 2018
Author: dberris
Date: Wed Oct 31 17:18:52 2018
New Revision: 345798
URL: http://llvm.org/viewvc/llvm-project?rev=345798&view=rev
Log:
[XRay] Add CPU ID in Custom Event FDR Records
Summary:
This change cuts across compiler-rt and llvm, to increment the FDR log
version number to 4, and include the CPU ID in the custom event records.
This is a step towards allowing us to change the `llvm::xray::Trace`
object to start representing both custom and typed events in the stream
of records. Follow-on changes will allow us to change the kinds of
records we're presenting in the stream of traces, to incorporate the
data in custom/typed events.
A follow-on change will handle the typed event case, where it may not
fit within the 15-byte buffer for metadata records.
This work is part of the larger effort to enable writing analysis and
processing tools using a common in-memory representation of the events
found in traces. The work will focus on porting existing tools in LLVM
to use the common representation and informing the design of a
library/framework for expressing trace event analysis as C++ programs.
Reviewers: mboerger, eizan
Subscribers: hiraditya, mgrang, llvm-commits
Differential Revision: https://reviews.llvm.org/D53920
Modified:
llvm/trunk/include/llvm/XRay/FDRRecords.h
llvm/trunk/lib/XRay/FDRTraceWriter.cpp
llvm/trunk/lib/XRay/FileHeaderReader.cpp
llvm/trunk/lib/XRay/RecordInitializer.cpp
llvm/trunk/lib/XRay/RecordPrinter.cpp
llvm/trunk/lib/XRay/Trace.cpp
llvm/trunk/unittests/XRay/FDRProducerConsumerTest.cpp
llvm/trunk/unittests/XRay/FDRRecordPrinterTest.cpp
Modified: llvm/trunk/include/llvm/XRay/FDRRecords.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/XRay/FDRRecords.h?rev=345798&r1=345797&r2=345798&view=diff
==============================================================================
--- llvm/trunk/include/llvm/XRay/FDRRecords.h (original)
+++ llvm/trunk/include/llvm/XRay/FDRRecords.h Wed Oct 31 17:18:52 2018
@@ -153,13 +153,14 @@ public:
class CustomEventRecord : public MetadataRecord {
int32_t Size = 0;
uint64_t TSC = 0;
+ uint16_t CPU = 0;
std::string Data{};
friend class RecordInitializer;
public:
CustomEventRecord() = default;
- explicit CustomEventRecord(uint64_t S, uint64_t T, std::string D)
- : MetadataRecord(), Size(S), TSC(T), Data(std::move(D)) {}
+ explicit CustomEventRecord(uint64_t S, uint64_t T, uint16_t C, std::string D)
+ : MetadataRecord(), Size(S), TSC(T), CPU(C), Data(std::move(D)) {}
MetadataType metadataType() const override {
return MetadataType::CustomEvent;
@@ -167,6 +168,7 @@ public:
int32_t size() const { return Size; }
uint64_t tsc() const { return TSC; }
+ uint16_t cpu() const { return CPU; }
StringRef data() const { return Data; }
Error apply(RecordVisitor &V) override;
@@ -272,10 +274,16 @@ public:
class RecordInitializer : public RecordVisitor {
DataExtractor &E;
uint32_t &OffsetPtr;
+ uint16_t Version;
public:
+ static constexpr uint16_t DefaultVersion = 4u;
+
+ explicit RecordInitializer(DataExtractor &DE, uint32_t &OP, uint16_t V)
+ : RecordVisitor(), E(DE), OffsetPtr(OP), Version(V) {}
+
explicit RecordInitializer(DataExtractor &DE, uint32_t &OP)
- : RecordVisitor(), E(DE), OffsetPtr(OP) {}
+ : RecordInitializer(DE, OP, DefaultVersion) {}
Error visit(BufferExtents &) override;
Error visit(WallclockRecord &) override;
Modified: llvm/trunk/lib/XRay/FDRTraceWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/XRay/FDRTraceWriter.cpp?rev=345798&r1=345797&r2=345798&view=diff
==============================================================================
--- llvm/trunk/lib/XRay/FDRTraceWriter.cpp (original)
+++ llvm/trunk/lib/XRay/FDRTraceWriter.cpp Wed Oct 31 17:18:52 2018
@@ -94,9 +94,10 @@ Error FDRTraceWriter::visit(TSCWrapRecor
}
Error FDRTraceWriter::visit(CustomEventRecord &R) {
- if (auto E = writeMetadata<5u>(OS, R.size(), R.tsc()))
+ if (auto E = writeMetadata<5u>(OS, R.size(), R.tsc(), R.cpu()))
return E;
- ArrayRef<char> Bytes(R.data().data(), R.data().size());
+ auto D = R.data();
+ ArrayRef<char> Bytes(D.data(), D.size());
OS.write(Bytes);
return Error::success();
}
@@ -127,7 +128,7 @@ Error FDRTraceWriter::visit(FunctionReco
OS.write(TypeRecordFuncId);
OS.write(R.delta());
return Error::success();
-} // namespace xray
+}
} // namespace xray
} // namespace llvm
Modified: llvm/trunk/lib/XRay/FileHeaderReader.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/XRay/FileHeaderReader.cpp?rev=345798&r1=345797&r2=345798&view=diff
==============================================================================
--- llvm/trunk/lib/XRay/FileHeaderReader.cpp (original)
+++ llvm/trunk/lib/XRay/FileHeaderReader.cpp Wed Oct 31 17:18:52 2018
@@ -63,8 +63,7 @@ Expected<XRayFileHeader> readBinaryForma
// Manually advance the offset pointer 16 bytes, after getting a raw memcpy
// from the underlying data.
OffsetPtr += 16;
- if (FileHeader.Version != 1 && FileHeader.Version != 2 &&
- FileHeader.Version != 3)
+ if (FileHeader.Version < 1 || FileHeader.Version > 4)
return createStringError(std::make_error_code(std::errc::invalid_argument),
"Unsupported XRay file version: %d at offset %d",
FileHeader.Version, OffsetPtr);
Modified: llvm/trunk/lib/XRay/RecordInitializer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/XRay/RecordInitializer.cpp?rev=345798&r1=345797&r2=345798&view=diff
==============================================================================
--- llvm/trunk/lib/XRay/RecordInitializer.cpp (original)
+++ llvm/trunk/lib/XRay/RecordInitializer.cpp Wed Oct 31 17:18:52 2018
@@ -118,6 +118,19 @@ Error RecordInitializer::visit(CustomEve
std::make_error_code(std::errc::invalid_argument),
"Cannot read a custom event TSC field at offset %d.", OffsetPtr);
+ // For version 4 onwards, of the FDR log, we want to also capture the CPU ID
+ // of the custom event.
+ if (Version >= 4) {
+ PreReadOffset = OffsetPtr;
+ R.CPU = E.getU16(&OffsetPtr);
+ if (PreReadOffset == OffsetPtr)
+ return createStringError(
+ std::make_error_code(std::errc::invalid_argument),
+ "Missing CPU field at offset %d", OffsetPtr);
+ }
+
+ assert(OffsetPtr > BeginOffset &&
+ OffsetPtr - BeginOffset <= MetadataRecord::kMetadataBodySize);
OffsetPtr += MetadataRecord::kMetadataBodySize - (OffsetPtr - BeginOffset);
// Next we read in a fixed chunk of data from the given offset.
Modified: llvm/trunk/lib/XRay/RecordPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/XRay/RecordPrinter.cpp?rev=345798&r1=345797&r2=345798&view=diff
==============================================================================
--- llvm/trunk/lib/XRay/RecordPrinter.cpp (original)
+++ llvm/trunk/lib/XRay/RecordPrinter.cpp Wed Oct 31 17:18:52 2018
@@ -35,8 +35,9 @@ Error RecordPrinter::visit(TSCWrapRecord
}
Error RecordPrinter::visit(CustomEventRecord &R) {
- OS << formatv("<Custom Event: tsc = {0}, size = {1}, data = '{2}'>", R.tsc(),
- R.size(), R.data())
+ OS << formatv(
+ "<Custom Event: tsc = {0}, cpu = {1}, size = {2}, data = '{3}'>",
+ R.tsc(), R.cpu(), R.size(), R.data())
<< Delim;
return Error::success();
}
Modified: llvm/trunk/lib/XRay/Trace.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/XRay/Trace.cpp?rev=345798&r1=345797&r2=345798&view=diff
==============================================================================
--- llvm/trunk/lib/XRay/Trace.cpp (original)
+++ llvm/trunk/lib/XRay/Trace.cpp Wed Oct 31 17:18:52 2018
@@ -310,12 +310,11 @@ Error loadFDRLog(StringRef Data, bool Is
{
for (auto &PTB : Index) {
auto &Blocks = PTB.second;
- llvm::sort(
- Blocks,
- [](const BlockIndexer::Block &L, const BlockIndexer::Block &R) {
- return (L.WallclockTime->seconds() < R.WallclockTime->seconds() &&
- L.WallclockTime->nanos() < R.WallclockTime->nanos());
- });
+ llvm::sort(Blocks, [](const BlockIndexer::Block &L,
+ const BlockIndexer::Block &R) {
+ return (L.WallclockTime->seconds() < R.WallclockTime->seconds() &&
+ L.WallclockTime->nanos() < R.WallclockTime->nanos());
+ });
auto Adder = [&](const XRayRecord &R) { Records.push_back(R); };
TraceExpander Expander(Adder, FileHeader.Version);
for (auto &B : Blocks) {
@@ -435,7 +434,7 @@ Expected<Trace> llvm::xray::loadTrace(co
}
break;
case FLIGHT_DATA_RECORDER_FORMAT:
- if (Version == 1 || Version == 2 || Version == 3) {
+ if (Version >= 1 && Version <= 4) {
if (auto E = loadFDRLog(DE.getData(), DE.isLittleEndian(), T.FileHeader,
T.Records))
return std::move(E);
Modified: llvm/trunk/unittests/XRay/FDRProducerConsumerTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/XRay/FDRProducerConsumerTest.cpp?rev=345798&r1=345797&r2=345798&view=diff
==============================================================================
--- llvm/trunk/unittests/XRay/FDRProducerConsumerTest.cpp (original)
+++ llvm/trunk/unittests/XRay/FDRProducerConsumerTest.cpp Wed Oct 31 17:18:52 2018
@@ -54,7 +54,7 @@ template <> std::unique_ptr<Record> Make
}
template <> std::unique_ptr<Record> MakeRecord<CustomEventRecord>() {
- return make_unique<CustomEventRecord>(4, 1, "data");
+ return make_unique<CustomEventRecord>(4, 1, 2, "data");
}
template <> std::unique_ptr<Record> MakeRecord<CallArgRecord>() {
Modified: llvm/trunk/unittests/XRay/FDRRecordPrinterTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/XRay/FDRRecordPrinterTest.cpp?rev=345798&r1=345797&r2=345798&view=diff
==============================================================================
--- llvm/trunk/unittests/XRay/FDRRecordPrinterTest.cpp (original)
+++ llvm/trunk/unittests/XRay/FDRRecordPrinterTest.cpp Wed Oct 31 17:18:52 2018
@@ -55,11 +55,11 @@ template <> struct Helper<TSCWrapRecord>
template <> struct Helper<CustomEventRecord> {
static std::unique_ptr<Record> construct() {
- return make_unique<CustomEventRecord>(4, 1, "data");
+ return make_unique<CustomEventRecord>(4, 1, 2, "data");
}
static const char *expected() {
- return "<Custom Event: tsc = 1, size = 4, data = 'data'>";
+ return "<Custom Event: tsc = 1, cpu = 2, size = 4, data = 'data'>";
}
};
More information about the llvm-commits
mailing list