Skip to content

Commit

Permalink
Omit the size for deallocators (except munmap)
Browse files Browse the repository at this point in the history
Since simple deallocators always free the entire allocation, we don't
need to record the size.

Signed-off-by: Matt Wozniski <mwozniski@bloomberg.net>
  • Loading branch information
godlygeek authored and pablogsal committed May 6, 2022
1 parent afa0fb8 commit 182e3b5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
11 changes: 9 additions & 2 deletions src/memray/_memray/record_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,15 @@ bool
RecordReader::parseAllocationRecord(AllocationRecord* record, unsigned int flags)
{
record->allocator = static_cast<hooks::Allocator>(flags);
return d_input->read(reinterpret_cast<char*>(&record->address), sizeof(record->address))
&& readVarint(&record->size);
if (!d_input->read(reinterpret_cast<char*>(&record->address), sizeof(record->address))) {
return false;
}
if (hooks::allocatorKind(record->allocator) == hooks::AllocatorKind::SIMPLE_DEALLOCATOR) {
record->size = 0;
} else if (!readVarint(&record->size)) {
return false;
}
return true;
}

bool
Expand Down
4 changes: 3 additions & 1 deletion src/memray/_memray/record_writer.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,9 @@ bool inline RecordWriter::writeRecordUnsafe(const AllocationRecord& record)
{
d_stats.n_allocations += 1;
RecordTypeAndFlags token{RecordType::ALLOCATION, static_cast<unsigned char>(record.allocator)};
return writeSimpleType(token) && writeSimpleType(record.address) && writeVarint(record.size);
return writeSimpleType(token) && writeSimpleType(record.address)
&& (hooks::allocatorKind(record.allocator) == hooks::AllocatorKind::SIMPLE_DEALLOCATOR
|| writeVarint(record.size));
}

bool inline RecordWriter::writeRecordUnsafe(const NativeAllocationRecord& record)
Expand Down

0 comments on commit 182e3b5

Please sign in to comment.