library/src/memory_profiling/BP_LibraryMemoryProfiling.cc
// This must be called once per application run.  It initializes
// semaphores and insures global data is in the right configuration
// before any allocations are performed.  Not calling this function
// can result in undefined behavior.
This must be called once per application run.  It initializes
semaphores and insures global data is in the right configuration
before any allocations are performed.  Not calling this function
can result in undefined behavior.
This must be called once per application run . It initializes semaphores and insures global data is in the right configuration before any allocations are performed . Not calling this function can result in undefined behavior .
BP_ERROR_T BP_InitMemProfilerSubsystem
(
	size_t log_chunk_min_size,
	size_t diag_bpstrdup,
	size_t diag_bpstrndup,
	size_t diag_bprealloc,
	size_t diag_bpmalloc,
	size_t diag_bpcalloc,
	size_t diag_bpfree
)
{
#if DEBUG_MEMORY_PROFILER == 1
	printf("\n [!!] Attempting to initialize main memory profiler.");
#endif
	sem_init(&global_memory_profiler_semaphore, 0, 1);
#if DEBUG_MEMORY_PROFILER == 1
	printf("\n [!!] Initialized global semaphor at %p, now waiting for lock.", &global_memory_profiler_semaphore);
#endif
	sem_wait(&global_memory_profiler_semaphore);
#if DEBUG_MEMORY_PROFILER == 1
	printf("\n [!!] Locked global memory profile semaphore.");
#endif
	global_memprofiler_diag_bpstrdup  = diag_bpstrdup;
	global_memprofiler_diag_bpstrndup = diag_bpstrndup;
	global_memprofiler_diag_bprealloc = diag_bprealloc;
	global_memprofiler_diag_bpmalloc  = diag_bpmalloc;
	global_memprofiler_diag_bpcalloc  = diag_bpcalloc;
	global_memprofiler_diag_bpfree    = diag_bpfree;
	global_memprof_pool                    = NULL;
	global_memprof_pool_n                  = 0;
	global_memprof_last_index_added        = 0;
	global_memprofiler_pool_memory_usage   = 0;
	global_size_for_chunk_logging          = log_chunk_min_size;
	global_memory_profiler_enabled         = 0xcafebabe;
#if DEBUG_MEMORY_PROFILER == 1
	printf("\n [!!] Memory profiler has been loaded OK.  Now unlocking global lock.");
#endif
	sem_post(&global_memory_profiler_semaphore);
#if DEBUG_MEMORY_PROFILER == 1
	printf("\n [!!] Global memory profiler lock has been unlocked.  Exiting profiler init.");
#endif
	return ERR_SUCCESS;
}
BP_ERROR_T BP_InitMemProfilerSubsystem ( size_t log_chunk_min_size , size_t diag_bpstrdup , size_t diag_bpstrndup , size_t diag_bprealloc , size_t diag_bpmalloc , size_t diag_bpcalloc , size_t diag_bpfree ) { #if DEBUG_MEMORY_PROFILER == 1 printf ( " \n " ) ; #endif sem_init ( & global_memory_profiler_semaphore , 0 , 1 ) ; #if DEBUG_MEMORY_PROFILER == 1 printf ( " \n " , & global_memory_profiler_semaphore ) ; #endif sem_wait ( & global_memory_profiler_semaphore ) ; #if DEBUG_MEMORY_PROFILER == 1 printf ( " \n " ) ; #endif global_memprofiler_diag_bpstrdup = diag_bpstrdup ; global_memprofiler_diag_bpstrndup = diag_bpstrndup ; global_memprofiler_diag_bprealloc = diag_bprealloc ; global_memprofiler_diag_bpmalloc = diag_bpmalloc ; global_memprofiler_diag_bpcalloc = diag_bpcalloc ; global_memprofiler_diag_bpfree = diag_bpfree ; global_memprof_pool = NULL ; global_memprof_pool_n = 0 ; global_memprof_last_index_added = 0 ; global_memprofiler_pool_memory_usage = 0 ; global_size_for_chunk_logging = log_chunk_min_size ; global_memory_profiler_enabled = 0xcafebabe ; #if DEBUG_MEMORY_PROFILER == 1 printf ( " \n " ) ; #endif sem_post ( & global_memory_profiler_semaphore ) ; #if DEBUG_MEMORY_PROFILER == 1 printf ( " \n " ) ; #endif return ERR_SUCCESS ; }
This must be called once per application run.
This must be called once per application run .
// initialize the memory profile semaphore // lock global semaphor // set global diagnostic flags from parameters // set the global profiler pool to null // unlock global semaphore // return indicating success