Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,11 @@ include(CMakeParseArguments)
include(ExternalProject)
include(FindPackageHandleStandardArgs)

option(ENABLE_MEM_POOL_STATS "Enable Memory Pool Statistics" ON)
if(ENABLE_MEM_POOL_STATS)
add_definitions(-DENABLE_MEMORY_POOL_STATS)
endif()

include(GNUInstallDirs)
if(IS_ABSOLUTE "${CMAKE_INSTALL_BINDIR}")
set(ARROW_PKG_CONFIG_BINDIR "${CMAKE_INSTALL_BINDIR}")
Expand Down
11 changes: 10 additions & 1 deletion cpp/src/arrow/acero/plan_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1761,31 +1761,40 @@ TEST(ExecPlanExecution, UnalignedInput) {
Declaration plan = Declaration::Sequence({
{"exec_batch_source", ExecBatchSourceNodeOptions(data.schema, data.batches)},
});

#ifdef ENABLE_MEMORY_POOL_STATS
int64_t initial_bytes_allocated = default_memory_pool()->total_bytes_allocated();
#endif

// By default we should warn and so the plan should finish ok
ASSERT_OK(DeclarationToStatus(plan));
#ifdef ENABLE_MEMORY_POOL_STATS
ASSERT_EQ(initial_bytes_allocated, default_memory_pool()->total_bytes_allocated());
#endif

QueryOptions query_options;

#ifndef ARROW_UBSAN
// Nothing should happen if we ignore alignment
query_options.unaligned_buffer_handling = UnalignedBufferHandling::kIgnore;
ASSERT_OK(DeclarationToStatus(plan, query_options));
# ifdef ENABLE_MEMORY_POOL_STATS
ASSERT_EQ(initial_bytes_allocated, default_memory_pool()->total_bytes_allocated());
# endif
#endif

query_options.unaligned_buffer_handling = UnalignedBufferHandling::kError;
ASSERT_THAT(DeclarationToStatus(plan, query_options),
Raises(StatusCode::Invalid,
testing::HasSubstr("An input buffer was poorly aligned")));
#ifdef ENABLE_MEMORY_POOL_STATS
ASSERT_EQ(initial_bytes_allocated, default_memory_pool()->total_bytes_allocated());
#endif

query_options.unaligned_buffer_handling = UnalignedBufferHandling::kReallocate;
ASSERT_OK(DeclarationToStatus(plan, query_options));
#ifdef ENABLE_MEMORY_POOL_STATS
ASSERT_LT(initial_bytes_allocated, default_memory_pool()->total_bytes_allocated());
#endif
}

} // namespace acero
Expand Down
9 changes: 8 additions & 1 deletion cpp/src/arrow/buffer_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -676,25 +676,32 @@ TEST(TestAllocateResizableBuffer, ZeroSize) {

TEST(TestAllocateResizableBuffer, ZeroResize) {
MemoryPool* pool = default_memory_pool();
#ifdef ENABLE_MEMORY_POOL_STATS
auto allocated_bytes = pool->bytes_allocated();
#endif
{
std::shared_ptr<ResizableBuffer> buffer;

ASSERT_OK_AND_ASSIGN(buffer, AllocateResizableBuffer(1000, pool));
ASSERT_EQ(buffer->size(), 1000);
ASSERT_NE(buffer->data(), nullptr);
ASSERT_EQ(buffer->mutable_data(), buffer->data());

#ifdef ENABLE_MEMORY_POOL_STATS
ASSERT_GE(pool->bytes_allocated(), allocated_bytes + 1000);
#endif

ASSERT_OK(buffer->Resize(0));
ASSERT_NE(buffer->data(), nullptr);
ASSERT_EQ(buffer->mutable_data(), buffer->data());

#ifdef ENABLE_MEMORY_POOL_STATS
ASSERT_GE(pool->bytes_allocated(), allocated_bytes);
ASSERT_LT(pool->bytes_allocated(), allocated_bytes + 1000);
#endif
}
#ifdef ENABLE_MEMORY_POOL_STATS
ASSERT_EQ(pool->bytes_allocated(), allocated_bytes);
#endif
}

TEST(TestBufferBuilder, ResizeReserve) {
Expand Down
Loading