[clang-tools-extra] [compiler-rt] [lldb] [llvm] [Memprof] Adds the option to collect AccessCountHistograms for memprof. (PR #94264)
Teresa Johnson via cfe-commits
cfe-commits at lists.llvm.org
Mon Jun 24 16:34:20 PDT 2024
================
@@ -96,19 +102,63 @@ llvm::SmallVector<SegmentEntry> readSegmentEntries(const char *Ptr) {
}
llvm::SmallVector<std::pair<uint64_t, MemInfoBlock>>
-readMemInfoBlocks(const char *Ptr) {
+readMemInfoBlocksV3(const char *Ptr) {
using namespace support;
const uint64_t NumItemsToRead =
- endian::readNext<uint64_t, llvm::endianness::little>(Ptr);
+ endian::readNext<uint64_t, llvm::endianness::little, unaligned>(Ptr);
+
llvm::SmallVector<std::pair<uint64_t, MemInfoBlock>> Items;
for (uint64_t I = 0; I < NumItemsToRead; I++) {
const uint64_t Id =
- endian::readNext<uint64_t, llvm::endianness::little>(Ptr);
- const MemInfoBlock MIB = *reinterpret_cast<const MemInfoBlock *>(Ptr);
+ endian::readNext<uint64_t, llvm::endianness::little, unaligned>(Ptr);
+
+ // We cheat a bit here and remove the const from cast to set the
+ // Histogram Pointer to newly allocated buffer. We also cheat, since V3 and
+ // V4 do not have the same fields. V3 is missing AccessHistogramSize and
+ // AccessHistogram. This means we read "dirty" data in here, but it should
+ // not segfault, since there will be callstack data placed after this in the
+ // binary format.
+ MemInfoBlock MIB = *reinterpret_cast<const MemInfoBlock *>(Ptr);
+ // Overwrite dirty data.
----------------
teresajohnson wrote:
Oh yes you are right, I missed the first `*` which means it is making a copy of what was in the memory pointed to by Ptr.
https://github.com/llvm/llvm-project/pull/94264
More information about the cfe-commits
mailing list