Index: llvm/include/llvm/XRay/FDRRecords.h =================================================================== --- llvm/include/llvm/XRay/FDRRecords.h +++ llvm/include/llvm/XRay/FDRRecords.h @@ -119,16 +119,19 @@ class NewCPUIDRecord : public MetadataRecord { uint16_t CPUId = 0; + uint64_t TSC = 0; friend class RecordInitializer; public: NewCPUIDRecord() = default; - explicit NewCPUIDRecord(uint16_t C) : MetadataRecord(), CPUId(C) {} + NewCPUIDRecord(uint16_t C, uint64_t T) : MetadataRecord(), CPUId(C), TSC(T) {} MetadataType metadataType() const override { return MetadataType::NewCPUId; } uint16_t cpuid() const { return CPUId; } + uint64_t tsc() const { return TSC; } + Error apply(RecordVisitor &V) override; }; Index: llvm/lib/XRay/RecordInitializer.cpp =================================================================== --- llvm/lib/XRay/RecordInitializer.cpp +++ llvm/lib/XRay/RecordInitializer.cpp @@ -61,13 +61,20 @@ return createStringError(std::make_error_code(std::errc::bad_address), "Invalid offset for a new cpu id record (%d).", OffsetPtr); + auto BeginOffset = OffsetPtr; auto PreReadOffset = OffsetPtr; R.CPUId = E.getU16(&OffsetPtr); if (OffsetPtr == PreReadOffset) return createStringError(std::make_error_code(std::errc::bad_message), "Cannot read CPU id at offset %d.", OffsetPtr); - OffsetPtr += MetadataRecord::kMetadataBodySize - (OffsetPtr - PreReadOffset); + PreReadOffset = OffsetPtr; + R.TSC = E.getU64(&OffsetPtr); + if (OffsetPtr == PreReadOffset) + return createStringError(std::make_error_code(std::errc::bad_message), + "Cannot read CPU TSC at offset %d.", OffsetPtr); + + OffsetPtr += MetadataRecord::kMetadataBodySize - (OffsetPtr - BeginOffset); return Error::success(); } Index: llvm/lib/XRay/RecordPrinter.cpp =================================================================== --- llvm/lib/XRay/RecordPrinter.cpp +++ llvm/lib/XRay/RecordPrinter.cpp @@ -25,7 +25,7 @@ } Error RecordPrinter::visit(NewCPUIDRecord &R) { - OS << formatv("", R.cpuid()) << Delim; + OS << formatv("", R.cpuid(), R.tsc()) << Delim; return Error::success(); } Index: llvm/test/tools/llvm-xray/X86/fdr-dump-arg1-version-3.txt =================================================================== --- llvm/test/tools/llvm-xray/X86/fdr-dump-arg1-version-3.txt +++ llvm/test/tools/llvm-xray/X86/fdr-dump-arg1-version-3.txt @@ -8,8 +8,8 @@ ; CHECK-NEXT: ; CHECK-EMPTY: ; CHECK-NEXT: Body: -; CHECK-NEXT: -; CHECK-NEXT: +; CHECK-NEXT: +; CHECK-NEXT: ; CHECK-NEXT: ; CHECK-EMPTY: ; CHECK-NEXT: - Index: llvm/test/tools/llvm-xray/X86/fdr-dump-arg1.txt =================================================================== --- llvm/test/tools/llvm-xray/X86/fdr-dump-arg1.txt +++ llvm/test/tools/llvm-xray/X86/fdr-dump-arg1.txt @@ -6,7 +6,7 @@ ; CHECK-NEXT: ; CHECK-EMPTY: ; CHECK-NEXT: Body: -; CHECK-NEXT: +; CHECK-NEXT: ; CHECK-NEXT: ; CHECK-EMPTY: ; CHECK-NEXT: - Index: llvm/unittests/XRay/FDRBlockIndexerTest.cpp =================================================================== --- llvm/unittests/XRay/FDRBlockIndexerTest.cpp +++ llvm/unittests/XRay/FDRBlockIndexerTest.cpp @@ -30,7 +30,7 @@ .add(1) .add(1, 2) .add(1) - .add(1) + .add(1, 2) .add(RecordTypes::ENTER, 1, 1) .add(RecordTypes::EXIT, 1, 100) .consume(); @@ -39,7 +39,7 @@ .add(1) .add(1, 2) .add(1) - .add(1) + .add(1, 2) .add(RecordTypes::ENTER, 1, 1) .add(RecordTypes::EXIT, 1, 100) .consume(); @@ -48,7 +48,7 @@ .add(2) .add(1, 2) .add(1) - .add(2) + .add(2, 2) .add(RecordTypes::ENTER, 1, 1) .add(RecordTypes::EXIT, 1, 100) .consume(); Index: llvm/unittests/XRay/FDRBlockVerifierTest.cpp =================================================================== --- llvm/unittests/XRay/FDRBlockVerifierTest.cpp +++ llvm/unittests/XRay/FDRBlockVerifierTest.cpp @@ -28,7 +28,7 @@ .add(1) .add(1, 2) .add(1) - .add(1) + .add(1, 2) .add(RecordTypes::ENTER, 1, 1) .add(RecordTypes::EXIT, 1, 100) .consume(); @@ -37,7 +37,7 @@ .add(1) .add(1, 2) .add(1) - .add(1) + .add(1, 2) .add(RecordTypes::ENTER, 1, 1) .add(RecordTypes::EXIT, 1, 100) .consume(); @@ -46,7 +46,7 @@ .add(2) .add(1, 2) .add(1) - .add(2) + .add(2, 2) .add(RecordTypes::ENTER, 1, 1) .add(RecordTypes::EXIT, 1, 100) .consume(); @@ -75,7 +75,7 @@ .add(20) .add(1) .add(1, 2) - .add(1) + .add(1, 2) .add(RecordTypes::ENTER, 1, 1) .add(RecordTypes::EXIT, 1, 100) .consume(); @@ -89,7 +89,7 @@ auto Block = LogBuilder() .add(1) .add(1, 2) - .add(1) + .add(1, 2) .add(RecordTypes::ENTER, 1, 1) .add(RecordTypes::EXIT, 1, 100) .consume(); @@ -103,7 +103,7 @@ auto Block = LogBuilder() .add(1) .add(1, 2) - .add(1) + .add(1, 2) .add() .add(RecordTypes::ENTER, 1, 1) .add(RecordTypes::EXIT, 1, 100) @@ -118,7 +118,7 @@ auto Block = LogBuilder() .add(1) .add(1, 2) - .add(1) + .add(1, 2) .add(RecordTypes::ENTER, 1, 1) .add(RecordTypes::EXIT, 1, 100) .add(2) Index: llvm/unittests/XRay/FDRProducerConsumerTest.cpp =================================================================== --- llvm/unittests/XRay/FDRProducerConsumerTest.cpp +++ llvm/unittests/XRay/FDRProducerConsumerTest.cpp @@ -42,7 +42,7 @@ } template <> std::unique_ptr MakeRecord() { - return make_unique(1); + return make_unique(1, 2); } template <> std::unique_ptr MakeRecord() { Index: llvm/unittests/XRay/FDRRecordPrinterTest.cpp =================================================================== --- llvm/unittests/XRay/FDRRecordPrinterTest.cpp +++ llvm/unittests/XRay/FDRRecordPrinterTest.cpp @@ -39,10 +39,10 @@ template <> struct Helper { static std::unique_ptr construct() { - return make_unique(1); + return make_unique(1, 2); } - static const char *expected() { return ""; } + static const char *expected() { return ""; } }; template <> struct Helper { Index: llvm/unittests/XRay/FDRRecordsTest.cpp =================================================================== --- llvm/unittests/XRay/FDRRecordsTest.cpp +++ llvm/unittests/XRay/FDRRecordsTest.cpp @@ -75,7 +75,7 @@ .add(1) .add(1, 1) .add(1) - .add(1) + .add(1, 2) .consume(); BlockVerifier Verifier; for (auto &R : Block) @@ -89,7 +89,7 @@ .add(1) .add(1, 1) .add(1) - .add(1) + .add(1, 2) .add(RecordTypes::ENTER, 1, 1) .add(RecordTypes::EXIT, 1, 100) .consume(); @@ -98,7 +98,7 @@ .add(1) .add(1, 1) .add(1) - .add(1) + .add(1, 2) .add(RecordTypes::ENTER, 1, 1) .add(RecordTypes::EXIT, 1, 100) .consume(); @@ -107,7 +107,7 @@ .add(1) .add(1, 1) .add(1) - .add(1) + .add(1, 2) .add(RecordTypes::ENTER, 1, 1) .add(RecordTypes::EXIT, 1, 100) .consume(); Index: llvm/unittests/XRay/FDRTraceWriterTest.cpp =================================================================== --- llvm/unittests/XRay/FDRTraceWriterTest.cpp +++ llvm/unittests/XRay/FDRTraceWriterTest.cpp @@ -47,7 +47,7 @@ .add(1) .add(1, 1) .add(1) - .add(1) + .add(1, 2) .add(RecordTypes::ENTER, 1, 1) .add(RecordTypes::EXIT, 1, 100) .consume(); @@ -92,7 +92,7 @@ .add(64) .add(1) .add(1, 1) - .add(1) + .add(1, 2) .add(RecordTypes::ENTER, 1, 1) .add(RecordTypes::EXIT, 1, 100) .consume(); @@ -143,7 +143,7 @@ auto L = LogBuilder() .add(1) .add(1, 1) - .add(1) + .add(1, 2) .add(RecordTypes::ENTER, 1, 1) .add(RecordTypes::EXIT, 1, 100) .add()