Skip to content

Commit 41423b0

Browse files
authored
Fix memory pool size reporting (#541)
1 parent 2595288 commit 41423b0

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

src/caliper/MemoryPool.cpp

+11-12
Original file line numberDiff line numberDiff line change
@@ -27,29 +27,28 @@ struct MemoryPool::MemoryPoolImpl
2727

2828
static const ConfigSet::Entry s_configdata[];
2929

30-
template<typename T>
3130
struct Chunk {
32-
T* ptr;
31+
unsigned char* ptr;
3332
size_t wmark;
3433
size_t size;
3534
};
3635

37-
ConfigSet m_config;
36+
ConfigSet m_config;
3837

39-
util::spinlock m_lock;
38+
util::spinlock m_lock;
4039

41-
vector< Chunk<uint64_t> > m_chunks;
42-
bool m_can_expand;
40+
vector<Chunk> m_chunks;
41+
bool m_can_expand;
4342

44-
size_t m_total_reserved;
45-
size_t m_total_used;
43+
size_t m_total_reserved;
44+
size_t m_total_used;
4645

4746
// --- interface
4847

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

52-
uint64_t* ptr = new uint64_t[len];
51+
unsigned char* ptr = new unsigned char[len];
5352
std::fill_n(ptr, len, 0);
5453

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

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

6362
std::lock_guard<util::spinlock>
6463
g(m_lock);
@@ -126,7 +125,7 @@ struct MemoryPool::MemoryPoolImpl
126125

127126
const ConfigSet::Entry MemoryPool::MemoryPoolImpl::s_configdata[] = {
128127
// key, type, value, short description, long description
129-
{ "pool_size", CALI_TYPE_UINT, "2097152",
128+
{ "pool_size", CALI_TYPE_UINT, "1048576",
130129
"Initial size of the Caliper memory pool (in bytes)",
131130
"Initial size of the Caliper memory pool (in bytes)"
132131
},

src/caliper/MetadataTree.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,9 @@ MetadataTree::create_path(const Attribute& attr, size_t n, const Variant* data,
157157
const size_t align = 8;
158158
size_t data_size = 0;
159159

160-
bool copy = (attr.type() == CALI_TYPE_STRING || attr.type() == CALI_TYPE_USR);
161-
char* ptr = nullptr;
160+
cali_attr_type type = attr.type();
161+
bool copy = (type == CALI_TYPE_STRING || type == CALI_TYPE_USR);
162+
char* ptr = nullptr;
162163

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

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

195196
if (parent)
196197
parent->append(node);

0 commit comments

Comments
 (0)