[XRay] Add TSC to NewCPUId Records

Summary:
This more correctly reflects the data written by the FDR mode runtime.

This is a continuation of the work in D50441.

Reviewers: mboerger, eizan

Subscribers: hiraditya, llvm-commits

Differential Revision: https://reviews.llvm.org/D51911

llvm-svn: 341905
This commit is contained in:
Dean Michael Berris 2018-09-11 06:36:51 +00:00
parent 9aacaffd98
commit d2c50408d4
11 changed files with 36 additions and 26 deletions

View File

@ -119,16 +119,19 @@ public:
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;
};

View File

@ -61,13 +61,20 @@ Error RecordInitializer::visit(NewCPUIDRecord &R) {
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();
}

View File

@ -25,7 +25,7 @@ Error RecordPrinter::visit(WallclockRecord &R) {
}
Error RecordPrinter::visit(NewCPUIDRecord &R) {
OS << formatv("<CPU ID: {0}>", R.cpuid()) << Delim;
OS << formatv("<CPU: id = {0}, tsc = {1}>", R.cpuid(), R.tsc()) << Delim;
return Error::success();
}

View File

@ -8,8 +8,8 @@
; CHECK-NEXT: <PID: 2631>
; CHECK-EMPTY:
; CHECK-NEXT: Body:
; CHECK-NEXT: <CPU ID: 6>
; CHECK-NEXT: <CPU ID: 6>
; CHECK-NEXT: <CPU: id = 6, tsc = 2034042117104344>
; CHECK-NEXT: <CPU: id = 6, tsc = 2034042117104344>
; CHECK-NEXT: <TSC Wrap: base = 2034042117104344>
; CHECK-EMPTY:
; CHECK-NEXT: - <Function Enter: #3 delta = +3>

View File

@ -6,7 +6,7 @@
; CHECK-NEXT: <Wall Time: seconds = 1452786.250689>
; CHECK-EMPTY:
; CHECK-NEXT: Body:
; CHECK-NEXT: <CPU ID: 49>
; CHECK-NEXT: <CPU: id = 49, tsc = 18828908666540172>
; CHECK-NEXT: <TSC Wrap: base = 18828908666540172>
; CHECK-EMPTY:
; CHECK-NEXT: - <Function Enter: #1 delta = +1>

View File

@ -30,7 +30,7 @@ TEST(FDRBlockIndexerTest, IndexBlocksV3) {
.add<NewBufferRecord>(1)
.add<WallclockRecord>(1, 2)
.add<PIDRecord>(1)
.add<NewCPUIDRecord>(1)
.add<NewCPUIDRecord>(1, 2)
.add<FunctionRecord>(RecordTypes::ENTER, 1, 1)
.add<FunctionRecord>(RecordTypes::EXIT, 1, 100)
.consume();
@ -39,7 +39,7 @@ TEST(FDRBlockIndexerTest, IndexBlocksV3) {
.add<NewBufferRecord>(1)
.add<WallclockRecord>(1, 2)
.add<PIDRecord>(1)
.add<NewCPUIDRecord>(1)
.add<NewCPUIDRecord>(1, 2)
.add<FunctionRecord>(RecordTypes::ENTER, 1, 1)
.add<FunctionRecord>(RecordTypes::EXIT, 1, 100)
.consume();
@ -48,7 +48,7 @@ TEST(FDRBlockIndexerTest, IndexBlocksV3) {
.add<NewBufferRecord>(2)
.add<WallclockRecord>(1, 2)
.add<PIDRecord>(1)
.add<NewCPUIDRecord>(2)
.add<NewCPUIDRecord>(2, 2)
.add<FunctionRecord>(RecordTypes::ENTER, 1, 1)
.add<FunctionRecord>(RecordTypes::EXIT, 1, 100)
.consume();

View File

@ -28,7 +28,7 @@ TEST(FDRBlockVerifierTest, ValidBlocksV3) {
.add<NewBufferRecord>(1)
.add<WallclockRecord>(1, 2)
.add<PIDRecord>(1)
.add<NewCPUIDRecord>(1)
.add<NewCPUIDRecord>(1, 2)
.add<FunctionRecord>(RecordTypes::ENTER, 1, 1)
.add<FunctionRecord>(RecordTypes::EXIT, 1, 100)
.consume();
@ -37,7 +37,7 @@ TEST(FDRBlockVerifierTest, ValidBlocksV3) {
.add<NewBufferRecord>(1)
.add<WallclockRecord>(1, 2)
.add<PIDRecord>(1)
.add<NewCPUIDRecord>(1)
.add<NewCPUIDRecord>(1, 2)
.add<FunctionRecord>(RecordTypes::ENTER, 1, 1)
.add<FunctionRecord>(RecordTypes::EXIT, 1, 100)
.consume();
@ -46,7 +46,7 @@ TEST(FDRBlockVerifierTest, ValidBlocksV3) {
.add<NewBufferRecord>(2)
.add<WallclockRecord>(1, 2)
.add<PIDRecord>(1)
.add<NewCPUIDRecord>(2)
.add<NewCPUIDRecord>(2, 2)
.add<FunctionRecord>(RecordTypes::ENTER, 1, 1)
.add<FunctionRecord>(RecordTypes::EXIT, 1, 100)
.consume();
@ -75,7 +75,7 @@ TEST(FDRBlockVerifierTest, MissingPIDRecord) {
.add<BufferExtents>(20)
.add<NewBufferRecord>(1)
.add<WallclockRecord>(1, 2)
.add<NewCPUIDRecord>(1)
.add<NewCPUIDRecord>(1, 2)
.add<FunctionRecord>(RecordTypes::ENTER, 1, 1)
.add<FunctionRecord>(RecordTypes::EXIT, 1, 100)
.consume();
@ -89,7 +89,7 @@ TEST(FDRBlockVerifierTest, MissingBufferExtents) {
auto Block = LogBuilder()
.add<NewBufferRecord>(1)
.add<WallclockRecord>(1, 2)
.add<NewCPUIDRecord>(1)
.add<NewCPUIDRecord>(1, 2)
.add<FunctionRecord>(RecordTypes::ENTER, 1, 1)
.add<FunctionRecord>(RecordTypes::EXIT, 1, 100)
.consume();
@ -103,7 +103,7 @@ TEST(FDRBlockVerifierTest, IgnoreRecordsAfterEOB) {
auto Block = LogBuilder()
.add<NewBufferRecord>(1)
.add<WallclockRecord>(1, 2)
.add<NewCPUIDRecord>(1)
.add<NewCPUIDRecord>(1, 2)
.add<EndBufferRecord>()
.add<FunctionRecord>(RecordTypes::ENTER, 1, 1)
.add<FunctionRecord>(RecordTypes::EXIT, 1, 100)
@ -118,7 +118,7 @@ TEST(FDRBlockVerifierTest, MalformedV2) {
auto Block = LogBuilder()
.add<NewBufferRecord>(1)
.add<WallclockRecord>(1, 2)
.add<NewCPUIDRecord>(1)
.add<NewCPUIDRecord>(1, 2)
.add<FunctionRecord>(RecordTypes::ENTER, 1, 1)
.add<FunctionRecord>(RecordTypes::EXIT, 1, 100)
.add<NewBufferRecord>(2)

View File

@ -42,7 +42,7 @@ template <> std::unique_ptr<Record> MakeRecord<NewBufferRecord>() {
}
template <> std::unique_ptr<Record> MakeRecord<NewCPUIDRecord>() {
return make_unique<NewCPUIDRecord>(1);
return make_unique<NewCPUIDRecord>(1, 2);
}
template <> std::unique_ptr<Record> MakeRecord<TSCWrapRecord>() {

View File

@ -39,10 +39,10 @@ template <> struct Helper<WallclockRecord> {
template <> struct Helper<NewCPUIDRecord> {
static std::unique_ptr<Record> construct() {
return make_unique<NewCPUIDRecord>(1);
return make_unique<NewCPUIDRecord>(1, 2);
}
static const char *expected() { return "<CPU ID: 1>"; }
static const char *expected() { return "<CPU: id = 1, tsc = 2>"; }
};
template <> struct Helper<TSCWrapRecord> {

View File

@ -75,7 +75,7 @@ TEST(XRayFDRTest, BuilderAndBlockVerifier) {
.add<NewBufferRecord>(1)
.add<WallclockRecord>(1, 1)
.add<PIDRecord>(1)
.add<NewCPUIDRecord>(1)
.add<NewCPUIDRecord>(1, 2)
.consume();
BlockVerifier Verifier;
for (auto &R : Block)
@ -89,7 +89,7 @@ TEST(XRayFDRTest, IndexAndVerifyBlocks) {
.add<NewBufferRecord>(1)
.add<WallclockRecord>(1, 1)
.add<PIDRecord>(1)
.add<NewCPUIDRecord>(1)
.add<NewCPUIDRecord>(1, 2)
.add<FunctionRecord>(RecordTypes::ENTER, 1, 1)
.add<FunctionRecord>(RecordTypes::EXIT, 1, 100)
.consume();
@ -98,7 +98,7 @@ TEST(XRayFDRTest, IndexAndVerifyBlocks) {
.add<NewBufferRecord>(1)
.add<WallclockRecord>(1, 1)
.add<PIDRecord>(1)
.add<NewCPUIDRecord>(1)
.add<NewCPUIDRecord>(1, 2)
.add<FunctionRecord>(RecordTypes::ENTER, 1, 1)
.add<FunctionRecord>(RecordTypes::EXIT, 1, 100)
.consume();
@ -107,7 +107,7 @@ TEST(XRayFDRTest, IndexAndVerifyBlocks) {
.add<NewBufferRecord>(1)
.add<WallclockRecord>(1, 1)
.add<PIDRecord>(1)
.add<NewCPUIDRecord>(1)
.add<NewCPUIDRecord>(1, 2)
.add<FunctionRecord>(RecordTypes::ENTER, 1, 1)
.add<FunctionRecord>(RecordTypes::EXIT, 1, 100)
.consume();

View File

@ -47,7 +47,7 @@ TEST(FDRTraceWriterTest, WriteToStringBufferVersion3) {
.add<NewBufferRecord>(1)
.add<WallclockRecord>(1, 1)
.add<PIDRecord>(1)
.add<NewCPUIDRecord>(1)
.add<NewCPUIDRecord>(1, 2)
.add<FunctionRecord>(RecordTypes::ENTER, 1, 1)
.add<FunctionRecord>(RecordTypes::EXIT, 1, 100)
.consume();
@ -92,7 +92,7 @@ TEST(FDRTraceWriterTest, WriteToStringBufferVersion2) {
.add<BufferExtents>(64)
.add<NewBufferRecord>(1)
.add<WallclockRecord>(1, 1)
.add<NewCPUIDRecord>(1)
.add<NewCPUIDRecord>(1, 2)
.add<FunctionRecord>(RecordTypes::ENTER, 1, 1)
.add<FunctionRecord>(RecordTypes::EXIT, 1, 100)
.consume();
@ -143,7 +143,7 @@ TEST(FDRTraceWriterTest, WriteToStringBufferVersion1) {
auto L = LogBuilder()
.add<NewBufferRecord>(1)
.add<WallclockRecord>(1, 1)
.add<NewCPUIDRecord>(1)
.add<NewCPUIDRecord>(1, 2)
.add<FunctionRecord>(RecordTypes::ENTER, 1, 1)
.add<FunctionRecord>(RecordTypes::EXIT, 1, 100)
.add<EndBufferRecord>()