21#include "pw_allocator/allocator.h"
22#include "pw_allocator/block/small_block.h"
23#include "pw_allocator/block_allocator.h"
24#include "pw_bloat/bloat_this_binary.h"
25#include "pw_bytes/span.h"
27namespace pw::allocator::size_report {
36 std::array<std::byte, 16> buffer;
44 Bar(
size_t number_) : number(number_) {
45 std::memset(foo.buffer.data(), 0, foo.buffer.size());
69template <
typename BlockType>
77template <
typename BucketType>
98template <
typename BlockType>
105 auto result = BlockType::Init(
GetBuffer());
109 std::byte* bytes = block->UsableSpace();
112 block = BlockType::FromUsableSpace(bytes);
114 if constexpr (is_allocatable_v<BlockType>) {
116 Layout foo = Layout::Of<Foo>();
117 auto block_result = BlockType::AllocFirst(std::move(block), foo);
118 if (!block_result.ok()) {
122 BlockType* first_block = block_result.block();
123 block = first_block->Next();
126 if constexpr (is_alignable_v<BlockType>) {
127 constexpr Layout kOverlyAligned(128, 64);
128 block_result = BlockType::AllocLast(std::move(block), kOverlyAligned);
130 Layout baz = Layout::Of<Baz>();
131 block_result = BlockType::AllocLast(std::move(block), baz);
133 if (!block_result.ok()) {
137 BlockType* last_block = block_result.block();
138 block = last_block->Prev();
141 block_result = block->Resize(
sizeof(
Bar));
142 if (!block_result.ok()) {
147 block_result = BlockType::Free(std::move(first_block));
148 return block_result.ok() ? 0 : 1;
152template <
typename BucketType>
157 if (
int rc = MeasureBlock<BlockType>(mask); rc != 0) {
161 auto result = BlockType::Init(
GetBuffer());
165 std::array<BlockType*, 4> blocks;
166 for (
size_t i = 0; i < blocks.size(); ++i) {
167 Layout layout(16 * (i + 1), 1);
168 auto block_result = BlockType::AllocFirst(std::move(unallocated), layout);
169 blocks[i] = block_result.block();
170 unallocated = blocks[i]->Next();
182 BlockType* any_block = bucket.RemoveAny();
188 return bucket.empty() ? 0 : 1;
Definition: allocator.h:36
Definition: block_allocator.h:106
Definition: small_block.h:30
int MeasureAllocator(Allocator &allocator, uint32_t mask)
int SetBaseline(uint32_t mask)
int MeasureBucket(BucketType &bucket, uint32_t mask)
Definition: size_report.h:153
ByteSpan GetBuffer()
Returns a view of a statically allocated array of bytes.
int MeasureBlock(uint32_t mask)
Definition: size_report.h:99
int MeasureBlockAllocator(BlockAllocator< BlockType > &allocator, uint32_t mask)
#define PW_BLOAT_EXPR(expr, mask)
Definition: bloat_this_binary.h:78
#define PW_BLOAT_COND(cond, mask)
Definition: bloat_this_binary.h:51
Type used for exercising an allocator.
Definition: size_report.h:40
Type used for exercising an allocator.
Definition: size_report.h:50
Type used for exercising an allocator.
Definition: size_report.h:35