mirror of
https://github.com/paboyle/Grid.git
synced 2025-04-09 21:50:45 +01:00
memory profiler improvement
This commit is contained in:
parent
9e31307963
commit
e78794688a
@ -3,7 +3,8 @@
|
|||||||
|
|
||||||
namespace Grid {
|
namespace Grid {
|
||||||
|
|
||||||
MemoryStats *MemoryProfiler::stats = nullptr;
|
MemoryStats *MemoryProfiler::stats = nullptr;
|
||||||
|
bool MemoryProfiler::debug = false;
|
||||||
|
|
||||||
int PointerCache::victim;
|
int PointerCache::victim;
|
||||||
|
|
||||||
|
@ -74,8 +74,47 @@ namespace Grid {
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static MemoryStats *stats;
|
static MemoryStats *stats;
|
||||||
|
static bool debug;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#define profilerDebugPrint \
|
||||||
|
if (MemoryProfiler::stats)\
|
||||||
|
{\
|
||||||
|
auto s = MemoryProfiler::stats;\
|
||||||
|
std::cout << "[Memory debug] Stats " << MemoryProfiler::stats << std::endl;\
|
||||||
|
std::cout << "[Memory debug] Total : " << s->totalAllocated << "B" << std::endl;\
|
||||||
|
std::cout << "[Memory debug] Max : " << s->maxAllocated << "B" << std::endl;\
|
||||||
|
std::cout << "[Memory debug] Current: " << s->totalAllocated << "B" << std::endl;\
|
||||||
|
std::cout << "[Memory debug] Freed : " << s->totalFreed << "B" << std::endl;\
|
||||||
|
}
|
||||||
|
|
||||||
|
#define profilerAllocate(bytes)\
|
||||||
|
if (MemoryProfiler::stats)\
|
||||||
|
{\
|
||||||
|
auto s = MemoryProfiler::stats;\
|
||||||
|
s->totalAllocated += (bytes);\
|
||||||
|
s->currentlyAllocated += (bytes);\
|
||||||
|
s->maxAllocated = std::max(s->maxAllocated, s->currentlyAllocated);\
|
||||||
|
}\
|
||||||
|
if (MemoryProfiler::debug)\
|
||||||
|
{\
|
||||||
|
std::cout << "[Memory debug] allocating " << bytes << "B" << std::endl;\
|
||||||
|
profilerDebugPrint;\
|
||||||
|
}
|
||||||
|
|
||||||
|
#define profilerFree(bytes)\
|
||||||
|
if (MemoryProfiler::stats)\
|
||||||
|
{\
|
||||||
|
auto s = MemoryProfiler::stats;\
|
||||||
|
s->totalFreed += (bytes);\
|
||||||
|
s->currentlyAllocated -= (bytes);\
|
||||||
|
}\
|
||||||
|
if (MemoryProfiler::debug)\
|
||||||
|
{\
|
||||||
|
std::cout << "[Memory debug] freeing " << bytes << "B" << std::endl;\
|
||||||
|
profilerDebugPrint;\
|
||||||
|
}
|
||||||
|
|
||||||
void check_huge_pages(void *Buf,uint64_t BYTES);
|
void check_huge_pages(void *Buf,uint64_t BYTES);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
@ -104,13 +143,7 @@ public:
|
|||||||
pointer allocate(size_type __n, const void* _p= 0)
|
pointer allocate(size_type __n, const void* _p= 0)
|
||||||
{
|
{
|
||||||
size_type bytes = __n*sizeof(_Tp);
|
size_type bytes = __n*sizeof(_Tp);
|
||||||
|
profilerAllocate(bytes);
|
||||||
if (auto s = MemoryProfiler::stats)
|
|
||||||
{
|
|
||||||
s->totalAllocated += bytes;
|
|
||||||
s->currentlyAllocated += bytes;
|
|
||||||
s->maxAllocated = std::max(s->maxAllocated, s->currentlyAllocated);
|
|
||||||
}
|
|
||||||
|
|
||||||
_Tp *ptr = (_Tp *) PointerCache::Lookup(bytes);
|
_Tp *ptr = (_Tp *) PointerCache::Lookup(bytes);
|
||||||
// if ( ptr != NULL )
|
// if ( ptr != NULL )
|
||||||
@ -141,11 +174,7 @@ public:
|
|||||||
void deallocate(pointer __p, size_type __n) {
|
void deallocate(pointer __p, size_type __n) {
|
||||||
size_type bytes = __n * sizeof(_Tp);
|
size_type bytes = __n * sizeof(_Tp);
|
||||||
|
|
||||||
if (auto s = MemoryProfiler::stats)
|
profilerFree(bytes);
|
||||||
{
|
|
||||||
s->totalFreed += bytes;
|
|
||||||
s->currentlyAllocated -= bytes;
|
|
||||||
}
|
|
||||||
|
|
||||||
pointer __freeme = (pointer)PointerCache::Insert((void *)__p,bytes);
|
pointer __freeme = (pointer)PointerCache::Insert((void *)__p,bytes);
|
||||||
|
|
||||||
@ -199,12 +228,7 @@ public:
|
|||||||
{
|
{
|
||||||
size_type bytes = __n*sizeof(_Tp);
|
size_type bytes = __n*sizeof(_Tp);
|
||||||
|
|
||||||
if (auto s = MemoryProfiler::stats)
|
profilerAllocate(bytes);
|
||||||
{
|
|
||||||
s->totalAllocated += bytes;
|
|
||||||
s->currentlyAllocated += bytes;
|
|
||||||
s->maxAllocated = std::max(s->maxAllocated, s->currentlyAllocated);
|
|
||||||
}
|
|
||||||
#ifdef CRAY
|
#ifdef CRAY
|
||||||
_Tp *ptr = (_Tp *) shmem_align(bytes,64);
|
_Tp *ptr = (_Tp *) shmem_align(bytes,64);
|
||||||
#else
|
#else
|
||||||
@ -229,11 +253,7 @@ public:
|
|||||||
void deallocate(pointer __p, size_type __n) {
|
void deallocate(pointer __p, size_type __n) {
|
||||||
size_type bytes = __n*sizeof(_Tp);
|
size_type bytes = __n*sizeof(_Tp);
|
||||||
|
|
||||||
if (auto s = MemoryProfiler::stats)
|
profilerFree(bytes);
|
||||||
{
|
|
||||||
s->totalFreed += bytes;
|
|
||||||
s->currentlyAllocated -= bytes;
|
|
||||||
}
|
|
||||||
shmem_free((void *)__p);
|
shmem_free((void *)__p);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
@ -241,12 +261,7 @@ public:
|
|||||||
{
|
{
|
||||||
size_type bytes = __n*sizeof(_Tp);
|
size_type bytes = __n*sizeof(_Tp);
|
||||||
|
|
||||||
if (auto s = MemoryProfiler::stats)
|
profilerAllocate(bytes);
|
||||||
{
|
|
||||||
s->totalAllocated += bytes;
|
|
||||||
s->currentlyAllocated += bytes;
|
|
||||||
s->maxAllocated = std::max(s->maxAllocated, s->currentlyAllocated);
|
|
||||||
}
|
|
||||||
#ifdef HAVE_MM_MALLOC_H
|
#ifdef HAVE_MM_MALLOC_H
|
||||||
_Tp * ptr = (_Tp *) _mm_malloc(bytes, GRID_ALLOC_ALIGN);
|
_Tp * ptr = (_Tp *) _mm_malloc(bytes, GRID_ALLOC_ALIGN);
|
||||||
#else
|
#else
|
||||||
@ -265,11 +280,7 @@ public:
|
|||||||
void deallocate(pointer __p, size_type __n) {
|
void deallocate(pointer __p, size_type __n) {
|
||||||
size_type bytes = __n*sizeof(_Tp);
|
size_type bytes = __n*sizeof(_Tp);
|
||||||
|
|
||||||
if (auto s = MemoryProfiler::stats)
|
profilerFree(bytes);
|
||||||
{
|
|
||||||
s->totalFreed += bytes;
|
|
||||||
s->currentlyAllocated -= bytes;
|
|
||||||
}
|
|
||||||
#ifdef HAVE_MM_MALLOC_H
|
#ifdef HAVE_MM_MALLOC_H
|
||||||
_mm_free((void *)__p);
|
_mm_free((void *)__p);
|
||||||
#else
|
#else
|
||||||
|
Loading…
x
Reference in New Issue
Block a user