|
PAPI
5.0.1.0
|


Go to the source code of this file.
| #define DEBUG_FILE_LEN 20 |
Definition at line 6 of file papi_memory.h.
| #define papi_calloc | ( | a, | |
| b | |||
| ) | _papi_calloc(__FILE__,__LINE__,a,b) |
Definition at line 37 of file papi_memory.h.
| #define papi_free | ( | a | ) | _papi_free(__FILE__,__LINE__, a) |
Definition at line 35 of file papi_memory.h.
| #define papi_malloc | ( | a | ) | _papi_malloc(__FILE__,__LINE__, a) |
Definition at line 34 of file papi_memory.h.
Definition at line 44 of file papi_memory.h.
Definition at line 40 of file papi_memory.h.
| #define PAPI_MEM_LIB_OVERHEAD 1 /* PAPI Library Overhead */ |
Definition at line 60 of file papi_memory.h.
| #define papi_mem_overhead | ( | a | ) | _papi_mem_overhead(a) |
Definition at line 43 of file papi_memory.h.
| #define PAPI_MEM_OVERHEAD 2 /* Memory Overhead */ |
Definition at line 61 of file papi_memory.h.
| #define papi_mem_print_info | ( | a | ) | _papi_mem_print_info(a) |
Definition at line 41 of file papi_memory.h.
Definition at line 42 of file papi_memory.h.
| #define papi_realloc | ( | a, | |
| b | |||
| ) | _papi_realloc(__FILE__,__LINE__,a,b) |
Definition at line 36 of file papi_memory.h.
| #define papi_strdup | ( | a | ) | _papi_strdup(__FILE__,__LINE__,a) |
Definition at line 39 of file papi_memory.h.
| #define papi_valid_free | ( | a | ) | _papi_valid_free(__FILE__,__LINE__,a) |
Definition at line 38 of file papi_memory.h.
| void* _papi_calloc | ( | char * | , |
| int | , | ||
| size_t | , | ||
| size_t | |||
| ) |
Definition at line 113 of file papi_memory.c.
{
void *ptr = _papi_malloc( file, line, size * nmemb );
if ( !ptr )
return ( NULL );
memset( ptr, 0, size * nmemb );
return ( ptr );
}

| void _papi_free | ( | char * | file, |
| int | line, | ||
| void * | ptr | ||
| ) |
Frees up the ptr
< Used with setting up array
< Used with setting up array
Definition at line 226 of file papi_memory.c.
{
pmem_t *mem_ptr = get_mem_ptr( ptr );
if ( !mem_ptr ) {
( void ) file;
( void ) line;
return;
}
MEMDBG( "%p: Freeing %d bytes from File: %s Line: %d\n", mem_ptr->ptr,
mem_ptr->size, file, line );
_papi_hwi_lock( MEMORY_LOCK );
remove_mem_ptr( mem_ptr );
_papi_mem_check_all_overflow( );
_papi_hwi_unlock( MEMORY_LOCK );
}

| void* _papi_malloc | ( | char * | , |
| int | , | ||
| size_t | |||
| ) |
< Used with setting up array
< Used with setting up array
Definition at line 124 of file papi_memory.c.
{
void *ptr;
void **tmp;
pmem_t *mem_ptr;
size_t nsize = size + MEM_PROLOG;
#ifdef DEBUG
nsize += MEM_EPILOG;
#endif
if ( size == 0 ) {
MEMDBG( "Attempting to allocate %lu bytes from File: %s Line: %d\n",
( unsigned long ) size, file, line );
return ( NULL );
}
ptr = ( void * ) malloc( nsize );
if ( !ptr )
return ( NULL );
else {
if ( ( mem_ptr =
init_mem_ptr( ( char * ) ptr + MEM_PROLOG, ( int ) size, file,
line ) ) == NULL ) {
free( ptr );
return ( NULL );
}
tmp = ptr;
*tmp = mem_ptr;
ptr = mem_ptr->ptr;
mem_ptr->ptr = ptr;
_papi_hwi_lock( MEMORY_LOCK );
insert_mem_ptr( mem_ptr );
set_epilog( mem_ptr );
_papi_hwi_unlock( MEMORY_LOCK );
MEMDBG( "%p: Allocated %lu bytes from File: %s Line: %d\n",
mem_ptr->ptr, ( unsigned long ) size, file, line );
return ( ptr );
}
return ( NULL );
}


| int _papi_mem_check_all_overflow | ( | ) |
Definition at line 470 of file papi_memory.c.
{
int fnd = 0;
#ifdef DEBUG
pmem_t *tmp;
for ( tmp = mem_head; tmp; tmp = tmp->next ) {
if ( _papi_mem_check_buf_overflow( tmp ) )
fnd++;
}
if ( fnd ) {
LEAKDBG( "%d Total Buffer overflows detected!\n", fnd );
}
#endif
return ( fnd );
}

| void _papi_mem_cleanup_all | ( | ) |
Clean all memory up and print out memory leak information to stderr
< Used with setting up array
< Used with setting up array
Definition at line 303 of file papi_memory.c.
{
pmem_t *ptr = NULL, *tmp = NULL;
#ifdef DEBUG
int cnt = 0;
#endif
_papi_hwi_lock( MEMORY_LOCK );
_papi_mem_check_all_overflow( );
for ( ptr = mem_head; ptr; ptr = tmp ) {
tmp = ptr->next;
#ifdef DEBUG
LEAKDBG( "MEMORY LEAK: %p of %d bytes, from File: %s Line: %d\n",
ptr->ptr, ptr->size, ptr->file, ptr->line );
cnt += ptr->size;
#endif
remove_mem_ptr( ptr );
}
_papi_hwi_unlock( MEMORY_LOCK );
#ifdef DEBUG
if ( 0 != cnt ) {
LEAKDBG( "TOTAL MEMORY LEAK: %d bytes.\n", cnt );
}
#endif
}


| int _papi_mem_overhead | ( | int | type | ) |
Return the amount of memory overhead of the PAPI library and the memory system PAPI_MEM_LIB_OVERHEAD is the library overhead PAPI_MEM_OVERHEAD is the memory overhead They both can be | together This only includes "malloc'd memory"
< Used with setting up array
< Used with setting up array
Definition at line 280 of file papi_memory.c.
{
pmem_t *ptr = NULL;
int size = 0;
_papi_hwi_lock( MEMORY_LOCK );
for ( ptr = mem_head; ptr; ptr = ptr->next ) {
if ( type & PAPI_MEM_LIB_OVERHEAD )
size += ptr->size;
if ( type & PAPI_MEM_OVERHEAD ) {
size += ( int ) sizeof ( pmem_t );
size += ( int ) MEM_PROLOG;
#ifdef DEBUG
size += ( int ) MEM_EPILOG;
#endif
}
}
_papi_hwi_unlock( MEMORY_LOCK );
return size;
}

| void _papi_mem_print_info | ( | void * | ptr | ) |
Print information about the memory including file and location it came from
Definition at line 247 of file papi_memory.c.
{
pmem_t *mem_ptr = get_mem_ptr( ptr );
#ifdef DEBUG
fprintf( stderr, "%p: Allocated %d bytes from File: %s Line: %d\n", ptr,
mem_ptr->size, mem_ptr->file, mem_ptr->line );
#else
fprintf( stderr, "%p: Allocated %d bytes\n", ptr, mem_ptr->size );
#endif
return;
}


| void _papi_mem_print_stats | ( | ) |
Print out all memory information
< Used with setting up array
< Used with setting up array
Definition at line 262 of file papi_memory.c.
{
pmem_t *tmp = NULL;
_papi_hwi_lock( MEMORY_LOCK );
for ( tmp = mem_head; tmp; tmp = tmp->next ) {
_papi_mem_print_info( tmp->ptr );
}
_papi_hwi_unlock( MEMORY_LOCK );
}

| void* _papi_realloc | ( | char * | file, |
| int | line, | ||
| void * | ptr, | ||
| size_t | size | ||
| ) |
_papi_realloc -- given a pointer returned by _papi_malloc, returns a pointer to the related pmem_t structure describing this pointer. Checks for NULL pointers and returns NULL if error.
Definition at line 77 of file papi_memory.c.
{
size_t nsize = size + MEM_PROLOG;
pmem_t *mem_ptr;
void *nptr;
#ifdef DEBUG
nsize += MEM_EPILOG;
_papi_hwi_lock( MEMORY_LOCK );
_papi_mem_check_all_overflow( );
#endif
if ( !ptr )
return ( _papi_malloc( file, line, size ) );
mem_ptr = get_mem_ptr( ptr );
nptr = ( pmem_t * ) realloc( ( ( char * ) ptr - MEM_PROLOG ), nsize );
if ( !nptr )
return ( NULL );
mem_ptr->size = ( int ) size;
mem_ptr->ptr = ( char * ) nptr + MEM_PROLOG;
#ifdef DEBUG
strncpy( mem_ptr->file, file, DEBUG_FILE_LEN );
mem_ptr->file[DEBUG_FILE_LEN - 1] = '\0';
mem_ptr->line = line;
set_epilog( mem_ptr );
_papi_hwi_unlock( MEMORY_LOCK );
#endif
MEMDBG( "%p: Re-allocated: %lu bytes from File: %s Line: %d\n",
mem_ptr->ptr, ( unsigned long ) size, file, line );
return ( mem_ptr->ptr );
}

| char* _papi_strdup | ( | char * | , |
| int | , | ||
| const char * | s | ||
| ) |
Definition at line 169 of file papi_memory.c.
{
size_t size;
char *ptr;
if ( !s )
return ( NULL );
/* String Length +1 for \0 */
size = strlen( s ) + 1;
ptr = ( char * ) _papi_malloc( file, line, size );
if ( !ptr )
return ( NULL );
memcpy( ptr, s, size );
return ( ptr );
}

| int _papi_valid_free | ( | char * | file, |
| int | line, | ||
| void * | ptr | ||
| ) |
Only frees the memory if PAPI malloced it returns 1 if pointer was valid; 0 if not
< Used with setting up array
< Used with setting up array
Definition at line 191 of file papi_memory.c.
{
pmem_t *tmp;
int valid = 0;
if ( !ptr ) {
( void ) file;
( void ) line;
return ( 0 );
}
_papi_hwi_lock( MEMORY_LOCK );
for ( tmp = mem_head; tmp; tmp = tmp->next ) {
if ( ptr == tmp->ptr ) {
pmem_t *mem_ptr = get_mem_ptr( ptr );
if ( mem_ptr ) {
MEMDBG( "%p: Freeing %d bytes from File: %s Line: %d\n",
mem_ptr->ptr, mem_ptr->size, file, line );
remove_mem_ptr( mem_ptr );
_papi_mem_check_all_overflow( );
}
valid = 1;
break;
}
}
_papi_hwi_unlock( MEMORY_LOCK );
return ( valid );
}
