PAPI  5.3.2.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
papi_memory.h File Reference
Include dependency graph for papi_memory.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  pmem_t
 

Macros

#define DEBUG_FILE_LEN   20
 
#define papi_malloc(a)   _papi_malloc(__FILE__,__LINE__, a)
 
#define papi_free(a)   _papi_free(__FILE__,__LINE__, a)
 
#define papi_realloc(a, b)   _papi_realloc(__FILE__,__LINE__,a,b)
 
#define papi_calloc(a, b)   _papi_calloc(__FILE__,__LINE__,a,b)
 
#define papi_valid_free(a)   _papi_valid_free(__FILE__,__LINE__,a)
 
#define papi_strdup(a)   _papi_strdup(__FILE__,__LINE__,a)
 
#define papi_mem_cleanup_all   _papi_mem_cleanup_all
 
#define papi_mem_print_info(a)   _papi_mem_print_info(a)
 
#define papi_mem_print_stats   _papi_mem_print_stats
 
#define papi_mem_overhead(a)   _papi_mem_overhead(a)
 
#define papi_mem_check_all_overflow   _papi_mem_check_all_overflow
 
#define PAPI_MEM_LIB_OVERHEAD   1 /* PAPI Library Overhead */
 
#define PAPI_MEM_OVERHEAD   2 /* Memory Overhead */
 

Functions

void_papi_malloc (char *, int, size_t)
 
void _papi_free (char *, int, void *)
 
void_papi_realloc (char *, int, void *, size_t)
 
void_papi_calloc (char *, int, size_t, size_t)
 
int _papi_valid_free (char *, int, void *)
 
char * _papi_strdup (char *, int, const char *s)
 
void _papi_mem_cleanup_all ()
 
void _papi_mem_print_info (void *ptr)
 
void _papi_mem_print_stats ()
 
int _papi_mem_overhead (int)
 
int _papi_mem_check_all_overflow ()
 

Macro Definition Documentation

#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.

#define papi_mem_check_all_overflow   _papi_mem_check_all_overflow

Definition at line 44 of file papi_memory.h.

#define papi_mem_cleanup_all   _papi_mem_cleanup_all

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.

#define papi_mem_print_stats   _papi_mem_print_stats

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.

Function Documentation

void* _papi_calloc ( char *  ,
int  ,
size_t  ,
size_t   
)

Definition at line 113 of file papi_memory.c.

114 {
115  void *ptr = _papi_malloc( file, line, size * nmemb );
116 
117  if ( !ptr )
118  return ( NULL );
119  memset( ptr, 0, size * nmemb );
120  return ( ptr );
121 }
memset(eventId, 0, size)
char *long long size
Definition: iozone.c:12023
void * _papi_malloc(char *file, int line, size_t size)
Definition: papi_memory.c:124
char * ptr
Definition: iozone.c:23586

Here is the call graph for this function:

void _papi_free ( char *  file,
int  line,
void ptr 
)

Frees up the ptr

Definition at line 226 of file papi_memory.c.

227 {
228  pmem_t *mem_ptr = get_mem_ptr( ptr );
229 
230  if ( !mem_ptr ) {
231  ( void ) file;
232  ( void ) line;
233  return;
234  }
235 
236  MEMDBG( "%p: Freeing %d bytes from File: %s Line: %d\n", mem_ptr->ptr,
237  mem_ptr->size, file, line );
238 
240  remove_mem_ptr( mem_ptr );
243 }
#define MEMORY_LOCK
Definition: papi_internal.h:89
int size
Definition: papi_memory.h:11
void
Definition: iozone.c:18627
static pmem_t * get_mem_ptr(void *ptr)
Definition: papi_memory.c:344
inline_static int _papi_hwi_lock(int lck)
Definition: threads.h:64
inline_static int _papi_hwi_unlock(int lck)
Definition: threads.h:78
#define MEMDBG(format, args...)
Definition: papi_debug.h:70
static void remove_mem_ptr(pmem_t *)
Definition: papi_memory.c:405
void * ptr
Definition: papi_memory.h:10
int _papi_mem_check_all_overflow()
Definition: papi_memory.c:470
char * ptr
Definition: iozone.c:23586

Here is the call graph for this function:

void* _papi_malloc ( char *  ,
int  ,
size_t   
)

Definition at line 124 of file papi_memory.c.

125 {
126  void *ptr;
127  void **tmp;
128  pmem_t *mem_ptr;
129  size_t nsize = size + MEM_PROLOG;
130 
131 #ifdef DEBUG
132  nsize += MEM_EPILOG;
133 #endif
134 
135  if ( size == 0 ) {
136  MEMDBG( "Attempting to allocate %lu bytes from File: %s Line: %d\n",
137  ( unsigned long ) size, file, line );
138  return ( NULL );
139  }
140 
141  ptr = ( void * ) malloc( nsize );
142 
143  if ( !ptr )
144  return ( NULL );
145  else {
146  if ( ( mem_ptr =
147  init_mem_ptr( ( char * ) ptr + MEM_PROLOG, ( int ) size, file,
148  line ) ) == NULL ) {
149  free( ptr );
150  return ( NULL );
151  }
152  tmp = ptr;
153  *tmp = mem_ptr;
154  ptr = mem_ptr->ptr;
155  mem_ptr->ptr = ptr;
157  insert_mem_ptr( mem_ptr );
158  set_epilog( mem_ptr );
160 
161  MEMDBG( "%p: Allocated %lu bytes from File: %s Line: %d\n",
162  mem_ptr->ptr, ( unsigned long ) size, file, line );
163  return ( ptr );
164  }
165  return ( NULL );
166 }
#define MEMORY_LOCK
Definition: papi_internal.h:89
static int set_epilog(pmem_t *mem_ptr)
Definition: papi_memory.c:420
inline_static int _papi_hwi_lock(int lck)
Definition: threads.h:64
#define MEM_EPILOG
Definition: papi_memory.c:38
char *long long size
Definition: iozone.c:12023
free(dummyfile[xx])
inline_static int _papi_hwi_unlock(int lck)
Definition: threads.h:78
static void insert_mem_ptr(pmem_t *)
Definition: papi_memory.c:383
static pmem_t * init_mem_ptr(void *, int, char *, int)
Definition: papi_memory.c:358
#define MEMDBG(format, args...)
Definition: papi_debug.h:70
void * ptr
Definition: papi_memory.h:10
#define MEM_PROLOG
Definition: papi_memory.c:31
long long tmp
Definition: iozone.c:12031
char * ptr
Definition: iozone.c:23586

Here is the call graph for this function:

Here is the caller graph for this function:

int _papi_mem_check_all_overflow ( )

Definition at line 470 of file papi_memory.c.

471 {
472  int fnd = 0;
473 #ifdef DEBUG
474  pmem_t *tmp;
475 
476  for ( tmp = mem_head; tmp; tmp = tmp->next ) {
477  if ( _papi_mem_check_buf_overflow( tmp ) )
478  fnd++;
479  }
480 
481  if ( fnd ) {
482  LEAKDBG( "%d Total Buffer overflows detected!\n", fnd );
483  }
484 #endif
485  return ( fnd );
486 }
static pmem_t * mem_head
Definition: papi_memory.c:46
struct pmem * next
Definition: papi_memory.h:16
#define LEAKDBG(format, args...)
Definition: papi_debug.h:71
static int _papi_mem_check_buf_overflow(pmem_t *tmp)
Definition: papi_memory.c:438
long long tmp
Definition: iozone.c:12031

Here is the call graph for this function:

Here is the caller graph for this function:

void _papi_mem_cleanup_all ( )

Clean all memory up and print out memory leak information to stderr

Definition at line 303 of file papi_memory.c.

304 {
305  pmem_t *ptr = NULL, *tmp = NULL;
306 #ifdef DEBUG
307  int cnt = 0;
308 #endif
309 
312 
313  for ( ptr = mem_head; ptr; ptr = tmp ) {
314  tmp = ptr->next;
315 #ifdef DEBUG
316  LEAKDBG( "MEMORY LEAK: %p of %d bytes, from File: %s Line: %d\n",
317  ptr->ptr, ptr->size, ptr->file, ptr->line );
318  cnt += ptr->size;
319 #endif
320 
321  remove_mem_ptr( ptr );
322  }
324 #ifdef DEBUG
325  if ( 0 != cnt ) {
326  LEAKDBG( "TOTAL MEMORY LEAK: %d bytes.\n", cnt );
327  }
328 #endif
329 }
static pmem_t * mem_head
Definition: papi_memory.c:46
int line
Definition: papi_memory.h:14
#define MEMORY_LOCK
Definition: papi_internal.h:89
struct pmem * next
Definition: papi_memory.h:16
int size
Definition: papi_memory.h:11
#define LEAKDBG(format, args...)
Definition: papi_debug.h:71
char file[DEBUG_FILE_LEN]
Definition: papi_memory.h:13
inline_static int _papi_hwi_lock(int lck)
Definition: threads.h:64
inline_static int _papi_hwi_unlock(int lck)
Definition: threads.h:78
static void remove_mem_ptr(pmem_t *)
Definition: papi_memory.c:405
void * ptr
Definition: papi_memory.h:10
int _papi_mem_check_all_overflow()
Definition: papi_memory.c:470
long long tmp
Definition: iozone.c:12031
char * ptr
Definition: iozone.c:23586

Here is the call graph for this function:

Here is the caller graph for this function:

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"

Definition at line 280 of file papi_memory.c.

281 {
282  pmem_t *ptr = NULL;
283  int size = 0;
284 
286  for ( ptr = mem_head; ptr; ptr = ptr->next ) {
287  if ( type & PAPI_MEM_LIB_OVERHEAD )
288  size += ptr->size;
289  if ( type & PAPI_MEM_OVERHEAD ) {
290  size += ( int ) sizeof ( pmem_t );
291  size += ( int ) MEM_PROLOG;
292 #ifdef DEBUG
293  size += ( int ) MEM_EPILOG;
294 #endif
295  }
296  }
298  return size;
299 }
static pmem_t * mem_head
Definition: papi_memory.c:46
#define MEMORY_LOCK
Definition: papi_internal.h:89
struct pmem * next
Definition: papi_memory.h:16
int size
Definition: papi_memory.h:11
inline_static int _papi_hwi_lock(int lck)
Definition: threads.h:64
#define MEM_EPILOG
Definition: papi_memory.c:38
char *long long size
Definition: iozone.c:12023
inline_static int _papi_hwi_unlock(int lck)
Definition: threads.h:78
#define PAPI_MEM_OVERHEAD
Definition: papi_memory.h:61
int
Definition: iozone.c:18528
#define MEM_PROLOG
Definition: papi_memory.c:31
#define PAPI_MEM_LIB_OVERHEAD
Definition: papi_memory.h:60
char * ptr
Definition: iozone.c:23586

Here is the call graph for this function:

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.

248 {
249  pmem_t *mem_ptr = get_mem_ptr( ptr );
250 
251 #ifdef DEBUG
252  fprintf( stderr, "%p: Allocated %d bytes from File: %s Line: %d\n", ptr,
253  mem_ptr->size, mem_ptr->file, mem_ptr->line );
254 #else
255  fprintf( stderr, "%p: Allocated %d bytes\n", ptr, mem_ptr->size );
256 #endif
257  return;
258 }
int line
Definition: papi_memory.h:14
int size
Definition: papi_memory.h:11
static pmem_t * get_mem_ptr(void *ptr)
Definition: papi_memory.c:344
char file[DEBUG_FILE_LEN]
Definition: papi_memory.h:13
char * ptr
Definition: iozone.c:23586

Here is the call graph for this function:

Here is the caller graph for this function:

void _papi_mem_print_stats ( )

Print out all memory information

Definition at line 262 of file papi_memory.c.

263 {
264  pmem_t *tmp = NULL;
265 
267  for ( tmp = mem_head; tmp; tmp = tmp->next ) {
268  _papi_mem_print_info( tmp->ptr );
269  }
271 }
static pmem_t * mem_head
Definition: papi_memory.c:46
#define MEMORY_LOCK
Definition: papi_internal.h:89
struct pmem * next
Definition: papi_memory.h:16
inline_static int _papi_hwi_lock(int lck)
Definition: threads.h:64
inline_static int _papi_hwi_unlock(int lck)
Definition: threads.h:78
void _papi_mem_print_info(void *ptr)
Definition: papi_memory.c:247
void * ptr
Definition: papi_memory.h:10
long long tmp
Definition: iozone.c:12031

Here is the call graph for this function:

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.

78 {
79  size_t nsize = size + MEM_PROLOG;
80  pmem_t *mem_ptr;
81  void *nptr;
82 
83 #ifdef DEBUG
84  nsize += MEM_EPILOG;
87 #endif
88 
89  if ( !ptr )
90  return ( _papi_malloc( file, line, size ) );
91 
92  mem_ptr = get_mem_ptr( ptr );
93  nptr = ( pmem_t * ) realloc( ( ( char * ) ptr - MEM_PROLOG ), nsize );
94 
95  if ( !nptr )
96  return ( NULL );
97 
98  mem_ptr->size = ( int ) size;
99  mem_ptr->ptr = ( char * ) nptr + MEM_PROLOG;
100 #ifdef DEBUG
101  strncpy( mem_ptr->file, file, DEBUG_FILE_LEN );
102  mem_ptr->file[DEBUG_FILE_LEN - 1] = '\0';
103  mem_ptr->line = line;
104  set_epilog( mem_ptr );
106 #endif
107  MEMDBG( "%p: Re-allocated: %lu bytes from File: %s Line: %d\n",
108  mem_ptr->ptr, ( unsigned long ) size, file, line );
109  return ( mem_ptr->ptr );
110 }
int line
Definition: papi_memory.h:14
#define DEBUG_FILE_LEN
Definition: papi_memory.h:6
#define MEMORY_LOCK
Definition: papi_internal.h:89
int size
Definition: papi_memory.h:11
static int set_epilog(pmem_t *mem_ptr)
Definition: papi_memory.c:420
static pmem_t * get_mem_ptr(void *ptr)
Definition: papi_memory.c:344
char file[DEBUG_FILE_LEN]
Definition: papi_memory.h:13
inline_static int _papi_hwi_lock(int lck)
Definition: threads.h:64
#define MEM_EPILOG
Definition: papi_memory.c:38
char *long long size
Definition: iozone.c:12023
inline_static int _papi_hwi_unlock(int lck)
Definition: threads.h:78
#define MEMDBG(format, args...)
Definition: papi_debug.h:70
void * _papi_malloc(char *file, int line, size_t size)
Definition: papi_memory.c:124
void * ptr
Definition: papi_memory.h:10
int
Definition: iozone.c:18528
int _papi_mem_check_all_overflow()
Definition: papi_memory.c:470
#define MEM_PROLOG
Definition: papi_memory.c:31
char * ptr
Definition: iozone.c:23586

Here is the call graph for this function:

char* _papi_strdup ( char *  ,
int  ,
const char *  s 
)

Definition at line 169 of file papi_memory.c.

170 {
171  size_t size;
172  char *ptr;
173 
174  if ( !s )
175  return ( NULL );
176 
177  /* String Length +1 for \0 */
178  size = strlen( s ) + 1;
179  ptr = ( char * ) _papi_malloc( file, line, size );
180 
181  if ( !ptr )
182  return ( NULL );
183 
184  memcpy( ptr, s, size );
185  return ( ptr );
186 }
char *long long size
Definition: iozone.c:12023
s
Definition: iozone.c:20289
void * _papi_malloc(char *file, int line, size_t size)
Definition: papi_memory.c:124
char * ptr
Definition: iozone.c:23586

Here is the call graph for this function:

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

Definition at line 191 of file papi_memory.c.

192 {
193  pmem_t *tmp;
194  int valid = 0;
195 
196  if ( !ptr ) {
197  ( void ) file;
198  ( void ) line;
199  return ( 0 );
200  }
201 
203 
204  for ( tmp = mem_head; tmp; tmp = tmp->next ) {
205  if ( ptr == tmp->ptr ) {
206  pmem_t *mem_ptr = get_mem_ptr( ptr );
207 
208  if ( mem_ptr ) {
209  MEMDBG( "%p: Freeing %d bytes from File: %s Line: %d\n",
210  mem_ptr->ptr, mem_ptr->size, file, line );
211  remove_mem_ptr( mem_ptr );
213  }
214 
215  valid = 1;
216  break;
217  }
218  }
219 
221  return ( valid );
222 }
static pmem_t * mem_head
Definition: papi_memory.c:46
#define MEMORY_LOCK
Definition: papi_internal.h:89
struct pmem * next
Definition: papi_memory.h:16
int size
Definition: papi_memory.h:11
void
Definition: iozone.c:18627
static pmem_t * get_mem_ptr(void *ptr)
Definition: papi_memory.c:344
inline_static int _papi_hwi_lock(int lck)
Definition: threads.h:64
inline_static int _papi_hwi_unlock(int lck)
Definition: threads.h:78
#define MEMDBG(format, args...)
Definition: papi_debug.h:70
static void remove_mem_ptr(pmem_t *)
Definition: papi_memory.c:405
void * ptr
Definition: papi_memory.h:10
int _papi_mem_check_all_overflow()
Definition: papi_memory.c:470
long long tmp
Definition: iozone.c:12031
char * ptr
Definition: iozone.c:23586

Here is the call graph for this function: