diff options
| -rw-r--r-- | llvm/lib/XRay/FDRTraceWriter.cpp | 10 | ||||
| -rw-r--r-- | llvm/unittests/XRay/FDRTraceWriterTest.cpp | 9 |
2 files changed, 13 insertions, 6 deletions
diff --git a/llvm/lib/XRay/FDRTraceWriter.cpp b/llvm/lib/XRay/FDRTraceWriter.cpp index 0148c6b7f93..b9b71eb14a8 100644 --- a/llvm/lib/XRay/FDRTraceWriter.cpp +++ b/llvm/lib/XRay/FDRTraceWriter.cpp @@ -21,9 +21,8 @@ namespace { struct alignas(32) FileHeader { uint16_t Version; uint16_t Type; - bool ConstantTSC : 1; - bool NonstopTSC : 1; - alignas(8) uint64_t CycleFrequency; + uint32_t BitField; + uint64_t CycleFrequency; char FreeForm[16]; }; @@ -65,7 +64,7 @@ template <size_t Index> struct IndexedMemcpy { }; template <uint8_t Kind, class... Values> -Error writeMetadata(raw_ostream &OS, Values&&... Ds) { +Error writeMetadata(raw_ostream &OS, Values &&... Ds) { MetadataBlob B; B.Type = 1; B.RecordKind = Kind; @@ -85,8 +84,7 @@ FDRTraceWriter::FDRTraceWriter(raw_ostream &O, const XRayFileHeader &H) FileHeader Raw; Raw.Version = H.Version; Raw.Type = H.Type; - Raw.ConstantTSC = H.ConstantTSC; - Raw.NonstopTSC = H.NonstopTSC; + Raw.BitField = (H.ConstantTSC ? 0x01 : 0x0) | (H.NonstopTSC ? 0x02 : 0x0); Raw.CycleFrequency = H.CycleFrequency; memcpy(&Raw.FreeForm, H.FreeFormData, 16); OS.write(reinterpret_cast<const char *>(&Raw), sizeof(XRayFileHeader)); diff --git a/llvm/unittests/XRay/FDRTraceWriterTest.cpp b/llvm/unittests/XRay/FDRTraceWriterTest.cpp index 9d7da50f0ab..97a011977b1 100644 --- a/llvm/unittests/XRay/FDRTraceWriterTest.cpp +++ b/llvm/unittests/XRay/FDRTraceWriterTest.cpp @@ -135,6 +135,11 @@ TEST(FDRTraceWriterTest, WriteToStringBufferVersion1) { std::memcpy(H.FreeFormData, reinterpret_cast<const char *>(&BufferSize), sizeof(BufferSize)); FDRTraceWriter Writer(OS, H); + OS.flush(); + + // Ensure that at this point the Data buffer has the file header serialized + // size. + ASSERT_THAT(Data.size(), Eq(32u)); auto L = LogBuilder() .add<NewBufferRecord>(1) .add<WallclockRecord>(1, 1) @@ -150,6 +155,10 @@ TEST(FDRTraceWriterTest, WriteToStringBufferVersion1) { OS.write_zeros(4016); OS.flush(); + // For version 1 of the log, we need the whole buffer to be the size of the + // file header plus 32. + ASSERT_THAT(Data.size(), Eq(BufferSize + 32)); + // Then from here we load the Trace file. DataExtractor DE(Data, true, 8); auto TraceOrErr = loadTrace(DE, true); |

