Browse Source

Added option to enable / disable stats.

Ioannis Koutras 13 years ago
parent
commit
baa748229c
8 changed files with 30 additions and 2 deletions
  1. 2 0
      DefineOptions.cmake
  2. 2 0
      dmm_config.h.in
  3. 4 0
      include/dmmlib/heap.h
  4. 7 1
      src/CMakeLists.txt
  5. 4 1
      src/custom_free.c
  6. 2 0
      src/custom_malloc.c
  7. 3 0
      src/initialize_allocator.c
  8. 6 0
      src/sys_alloc.c

+ 2 - 0
DefineOptions.cmake

@@ -2,6 +2,7 @@ option(HAVE_LOCKS "Build with POSIX locking mechanisms" ON)
 option(WITH_EXAMPLES "Build with examples" OFF)
 option(WITH_MEMORY_SPACE_AWARENESS "Build with memory space awareness" OFF)
 option(WITH_FIXED_LISTS "Build with predefined lists of fixed-sized blocks" ON)
+option(WITH_STATS "Build with statistics" ON)
 option(WITH_KNOBS "Build with knobs support" OFF)
 option(WITH_ADAPTIVITY "Build with adaptivity" OFF)
 option(WITH_STATIC_LIB "Build a static library" OFF)
@@ -27,6 +28,7 @@ if (P2012)
   set(NUM_HEAPS 1)
   set(LINUXTEST OFF)
   set(WITH_FIXED_LISTS OFF)
+  set(WITH_STATS OFF)
   set(WITH_COALESCING "never")
   set(WITH_SPLITTING "never")
   set(BLOCKS_ORGANIZATION "sll")

+ 2 - 0
dmm_config.h.in

@@ -19,6 +19,8 @@
 
 #cmakedefine MIN_SPLITTING_SIZE @MIN_SPLITTING_SIZE@
 
+#cmakedefine WITH_STATS
+
 #cmakedefine WITH_KNOBS
 
 #cmakedefine WITH_ADAPTIVITY

+ 4 - 0
include/dmmlib/heap.h

@@ -51,6 +51,7 @@ typedef struct maptable_node_s {
 					maptable. */
 } maptable_node_t;
 
+#ifdef WITH_STATS
 /** Statistics data structure. */
 typedef struct dmmstats_s {
 	size_t max_mem_allocated; /**< Maximum total memory allocated. */
@@ -63,6 +64,7 @@ typedef struct dmmstats_s {
 	uint32_t num_malloc; /**< Number of malloc()'s served. */
 	uint32_t num_free; /**< Number of free()'s served. */
 } dmmstats_t;
+#endif /* WITH_STATS */
 
 #ifdef WITH_KNOBS
 /** A structure to represent tunable parameters of a heap */
@@ -94,7 +96,9 @@ typedef struct heap_s {
 	void *used_blocks_head; /**< The head of the used blocks list. */
 	void *rov_ptr; /**< Roving pointer. */
 	uint64_t num_objects; /**< Number of objects in the heap. */
+#ifdef WITH_STATS
 	dmmstats_t dmm_stats; /**< Statistics of the heap. */
+#endif /* WITH_STATS */
 #ifdef WITH_KNOBS
 	dmmknobs_t dmm_knobs; /**< Tunable parameters of the heap. */
 #endif /* WITH_KNOBS */

+ 7 - 1
src/CMakeLists.txt

@@ -37,7 +37,6 @@ set(dmmlib_SRCS
   other.c
   initialize_allocator.c
   sys_alloc.c
-  print_stats.c
 )
 
 if (HAVE_LOCKS)
@@ -62,6 +61,13 @@ if (SPLITTING_FIXED OR SPLITTING_VARIABLE)
   )
 endif (SPLITTING_FIXED OR SPLITTING_VARIABLE)
 
+if (WITH_STATS)
+  set(dmmlib_SRCS
+    ${dmmlib_SRCS}
+    print_stats.c
+  )
+endif (WITH_STATS)
+
 if (WITH_ADAPTIVITY)
   set(dmmlib_SRCS
     ${dmmlib_SRCS}

+ 4 - 1
src/custom_free.c

@@ -60,8 +60,10 @@ void custom_ahfree(allocator_t *allocator, heap_t* heap, void *ptr) {
 
     remove_block(ptr, heap->used_blocks_head);
 
+#ifdef WITH_STATS
     heap->dmm_stats.mem_allocated -= size;
     heap->dmm_stats.mem_requested -= get_requested_size(ptr);
+#endif /* WITH_STATS */
 
 #if defined (COALESCING_FIXED) || defined (COALESCING_VARIABLE)
     coalesced = false;
@@ -117,11 +119,12 @@ void custom_ahfree(allocator_t *allocator, heap_t* heap, void *ptr) {
     }
 #endif /* WITH_FIXED_LISTS */
 
+#ifdef WITH_STATS
     /* Update Stats */
     heap->dmm_stats.live_objects -= 1;
     heap->dmm_stats.num_free += 1;
-
     /* End of Stats */
+#endif /* WITH_STATS */
 
 #ifdef WITH_ADAPTIVITY
     /* Refresh the state of the heap allocator if a certain number of

+ 2 - 0
src/custom_malloc.c

@@ -98,11 +98,13 @@ void * custom_ahmalloc(allocator_t* allocator, heap_t* heap, size_t size) {
         /* Update the used blocks list */
         push_block(ptr, heap->used_blocks_head);
 
+#ifdef WITH_STATS
         /* Update statistics */
         heap->dmm_stats.mem_allocated += req_padding(size);
         heap->dmm_stats.mem_requested += size;
         heap->dmm_stats.live_objects += 1;
         heap->dmm_stats.num_malloc += 1;
+#endif /* WITH_STATS */
 
         /* FIXME To be refactored - END */
 

+ 3 - 0
src/initialize_allocator.c

@@ -48,11 +48,14 @@ void initialize_allocator(allocator_t *allocator) {
         allocator->heaps[i].used_blocks_head = NULL;
         allocator->heaps[i].rov_ptr = NULL;
         allocator->heaps[i].num_objects = 0;
+
+#ifdef WITH_STATS
         allocator->heaps[i].dmm_stats.mem_allocated = 0;
         allocator->heaps[i].dmm_stats.mem_requested = 0;
         allocator->heaps[i].dmm_stats.live_objects = 0;
         allocator->heaps[i].dmm_stats.num_malloc = 0;
         allocator->heaps[i].dmm_stats.num_free = 0;
+#endif /* WITH_STATS */
 
 #ifdef WITH_KNOBS
         /* Knobs initialization */

+ 6 - 0
src/sys_alloc.c

@@ -27,7 +27,9 @@
 #include "other.h"
 #include "sys_alloc.h"
 #include "block_header.h"
+#ifdef WITH_STATS
 #include "print_stats.h"
+#endif /* WITH_STATS */
 
 void *sys_alloc(allocator_t *allocator, heap_t *heap, size_t size) {
 
@@ -81,7 +83,9 @@ void *sys_alloc(allocator_t *allocator, heap_t *heap, size_t size) {
         allocator->remaining_size -= allocation_size;
     } else {
         printf("No more free space.\n");
+#ifdef WITH_STATS
         print_stats(allocator);
+#endif /* WITH_STATS */
         return NULL;
     }
 #endif /* WITH_MEMORY_SPACE_AWARENESS */
@@ -103,11 +107,13 @@ void *sys_alloc(allocator_t *allocator, heap_t *heap, size_t size) {
     /* Update the used blocks list */
     push_block(ptr, heap->used_blocks_head);
 
+#ifdef WITH_STATS
     /* Update statistics */
     heap->dmm_stats.mem_allocated += req_padding(size);
     heap->dmm_stats.mem_requested += size;
     heap->dmm_stats.live_objects += 1;
     heap->dmm_stats.num_malloc += 1;
+#endif /* WITH_STATS */
 
     /* FIXME To be refactored - END */