STXXL  1.4-dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
malloc_count.cpp File Reference
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <clocale>
#include <dlfcn.h>
#include <stxxl/bits/config.h>
#include <stxxl/bits/utils/malloc_count.h>

Go to the source code of this file.

Macros

#define _GNU_SOURCE
 
#define INIT_HEAP_SIZE   1024 * 1024
 
#define PPREFIX   "malloc_count ### "
 
#define THREAD_SAFE_GCC_INTRINSICS   STXXL_HAVE_SYNC_ADD_AND_FETCH
 

Typedefs

typedef void(* free_type )(void *)
 
typedef void *(* malloc_type )(size_t)
 
typedef void *(* realloc_type )(void *, size_t)
 

Functions

static __attribute__ ((constructor)) void init(void)
 
static __attribute__ ((destructor)) void finish(void)
 
void * calloc (size_t nmemb, size_t size) throw ()
 
static void dec_count (size_t dec)
 
void free (void *ptr) throw ()
 
static void inc_count (size_t inc)
 
void * malloc (size_t size) throw ()
 
size_t malloc_count_current (void)
 
size_t malloc_count_peak (void)
 
void malloc_count_print_status (void)
 
void malloc_count_reset_peak (void)
 
void malloc_count_set_callback (malloc_count_callback_type cb, void *cookie)
 
void * realloc (void *ptr, size_t size) throw ()
 

Variables

static const size_t alignment = 16
 
static malloc_count_callback_type callback = NULL
 
static void * callback_cookie = NULL
 
static long long curr = 0
 
static char init_heap [1024 *1024]
 
static size_t init_heap_use = 0
 
static const int log_operations = 1
 
static const int log_operations_init_heap = 0
 
static const size_t log_operations_threshold = 1024 * 1024
 
static long long peak = 0
 
static free_type real_free = NULL
 
static malloc_type real_malloc = NULL
 
static realloc_type real_realloc = NULL
 
static const size_t sentinel = 0xDEADC0DE
 
static long long total = 0
 

Macro Definition Documentation

#define _GNU_SOURCE

Definition at line 19 of file malloc_count.cpp.

#define INIT_HEAP_SIZE   1024 * 1024

Definition at line 55 of file malloc_count.cpp.

Referenced by malloc().

#define PPREFIX   "malloc_count ### "

Definition at line 61 of file malloc_count.cpp.

Referenced by __attribute__(), free(), malloc(), malloc_count_print_status(), and realloc().

#define THREAD_SAFE_GCC_INTRINSICS   STXXL_HAVE_SYNC_ADD_AND_FETCH

Definition at line 36 of file malloc_count.cpp.

Typedef Documentation

typedef void(* free_type)(void *)

Definition at line 44 of file malloc_count.cpp.

typedef void*(* malloc_type)(size_t)

Definition at line 43 of file malloc_count.cpp.

typedef void*(* realloc_type)(void *, size_t)

Definition at line 45 of file malloc_count.cpp.

Function Documentation

static __attribute__ ( (constructor)  )
static

Definition at line 313 of file malloc_count.cpp.

References PPREFIX, real_free, real_malloc, and real_realloc.

static __attribute__ ( (destructor)  )
static

Definition at line 340 of file malloc_count.cpp.

References curr, peak, PPREFIX, and total.

void* calloc ( size_t  nmemb,
size_t  size 
)
throw (
)

Definition at line 225 of file malloc_count.cpp.

References malloc().

static void dec_count ( size_t  dec)
static

Definition at line 88 of file malloc_count.cpp.

References callback, callback_cookie, and curr.

Referenced by free(), and realloc().

static void inc_count ( size_t  inc)
static

Definition at line 73 of file malloc_count.cpp.

References callback, callback_cookie, curr, peak, and total.

Referenced by malloc(), and realloc().

size_t malloc_count_current ( void  )

Definition at line 100 of file malloc_count.cpp.

References curr.

size_t malloc_count_peak ( void  )

Definition at line 106 of file malloc_count.cpp.

References peak.

void malloc_count_print_status ( void  )

Definition at line 118 of file malloc_count.cpp.

References curr, peak, and PPREFIX.

void malloc_count_reset_peak ( void  )

Definition at line 112 of file malloc_count.cpp.

References curr, and peak.

void malloc_count_set_callback ( malloc_count_callback_type  cb,
void *  cookie 
)

Definition at line 125 of file malloc_count.cpp.

References callback, and callback_cookie.

Variable Documentation

const size_t alignment = 16
static

Definition at line 40 of file malloc_count.cpp.

Referenced by free(), malloc(), and realloc().

malloc_count_callback_type callback = NULL
static

Definition at line 69 of file malloc_count.cpp.

Referenced by dec_count(), inc_count(), and malloc_count_set_callback().

void* callback_cookie = NULL
static

Definition at line 70 of file malloc_count.cpp.

Referenced by dec_count(), inc_count(), and malloc_count_set_callback().

char init_heap[1024 *1024]
static

Definition at line 56 of file malloc_count.cpp.

Referenced by free(), malloc(), and realloc().

size_t init_heap_use = 0
static

Definition at line 57 of file malloc_count.cpp.

Referenced by free(), malloc(), and realloc().

const int log_operations = 1
static

Definition at line 32 of file malloc_count.cpp.

Referenced by free(), malloc(), and realloc().

const int log_operations_init_heap = 0
static

Definition at line 58 of file malloc_count.cpp.

Referenced by free(), malloc(), and realloc().

const size_t log_operations_threshold = 1024 * 1024
static

Definition at line 33 of file malloc_count.cpp.

Referenced by free(), malloc(), and realloc().

long long peak = 0
static
free_type real_free = NULL
static

Definition at line 48 of file malloc_count.cpp.

Referenced by __attribute__(), and free().

malloc_type real_malloc = NULL
static

Definition at line 47 of file malloc_count.cpp.

Referenced by __attribute__(), and malloc().

realloc_type real_realloc = NULL
static

Definition at line 49 of file malloc_count.cpp.

Referenced by __attribute__().