Skip to content

Commit

Permalink
Fix memory pool size reporting (#541)
Browse files Browse the repository at this point in the history
  • Loading branch information
daboehme authored Mar 12, 2024
1 parent 2595288 commit 41423b0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
23 changes: 11 additions & 12 deletions src/caliper/MemoryPool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,29 +27,28 @@ struct MemoryPool::MemoryPoolImpl

static const ConfigSet::Entry s_configdata[];

template<typename T>
struct Chunk {
T* ptr;
unsigned char* ptr;
size_t wmark;
size_t size;
};

ConfigSet m_config;
ConfigSet m_config;

util::spinlock m_lock;
util::spinlock m_lock;

vector< Chunk<uint64_t> > m_chunks;
bool m_can_expand;
vector<Chunk> m_chunks;
bool m_can_expand;

size_t m_total_reserved;
size_t m_total_used;
size_t m_total_reserved;
size_t m_total_used;

// --- interface

void expand(size_t bytes) {
size_t len = max((bytes+sizeof(uint64_t)-1)/sizeof(uint64_t), chunksize);
size_t len = max(bytes, chunksize);

uint64_t* ptr = new uint64_t[len];
unsigned char* ptr = new unsigned char[len];
std::fill_n(ptr, len, 0);

m_chunks.push_back( { ptr, 0, len } );
Expand All @@ -58,7 +57,7 @@ struct MemoryPool::MemoryPoolImpl
}

void* allocate(size_t bytes, bool can_expand) {
size_t n = (bytes+sizeof(uint64_t)-1)/sizeof(uint64_t);
size_t n = bytes + ((bytes+7)%8);

std::lock_guard<util::spinlock>
g(m_lock);
Expand Down Expand Up @@ -126,7 +125,7 @@ struct MemoryPool::MemoryPoolImpl

const ConfigSet::Entry MemoryPool::MemoryPoolImpl::s_configdata[] = {
// key, type, value, short description, long description
{ "pool_size", CALI_TYPE_UINT, "2097152",
{ "pool_size", CALI_TYPE_UINT, "1048576",
"Initial size of the Caliper memory pool (in bytes)",
"Initial size of the Caliper memory pool (in bytes)"
},
Expand Down
7 changes: 4 additions & 3 deletions src/caliper/MetadataTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,9 @@ MetadataTree::create_path(const Attribute& attr, size_t n, const Variant* data,
const size_t align = 8;
size_t data_size = 0;

bool copy = (attr.type() == CALI_TYPE_STRING || attr.type() == CALI_TYPE_USR);
char* ptr = nullptr;
cali_attr_type type = attr.type();
bool copy = (type == CALI_TYPE_STRING || type == CALI_TYPE_USR);
char* ptr = nullptr;

if (copy) {
for (size_t i = 0; i < n; ++i) {
Expand Down Expand Up @@ -190,7 +191,7 @@ MetadataTree::create_path(const Attribute& attr, size_t n, const Variant* data,
size_t index = m_nodeblock->index++;

node = new(m_nodeblock->chunk + index)
Node((m_nodeblock - g->node_blocks) * g->nodes_per_block + index, attr.id(), Variant(attr.type(), dptr, size));
Node((m_nodeblock - g->node_blocks) * g->nodes_per_block + index, attr.id(), Variant(type, dptr, size));

if (parent)
parent->append(node);
Expand Down

0 comments on commit 41423b0

Please sign in to comment.