Browse Source

Large update on stats

Ioannis Koutras 13 years ago
parent
commit
8eb08a1ee7

+ 4 - 3
include/dmmlib/heap.h

@@ -70,10 +70,11 @@ typedef struct maptable_node_s {
 #ifdef WITH_STATS
 /** Statistics data structure. */
 typedef struct dmmstats_s {
-	size_t max_mem_allocated; /**< Maximum total memory allocated. */
-	size_t max_mem_requested; /**< Maximum total memory requested. */
-	size_t mem_allocated; /**< Total memory currently allocated. */
+#ifdef FUTURE_FEATURES
 	size_t mem_requested; /**< Total memory currently requested. */
+#endif /* FUTURE_FEATURES */
+	size_t mem_used; /**< Total memory actively allocated. */
+	size_t mem_allocated; /**< Total managed memory. */
 	uint32_t live_objects; /**< Number of the currently used blocks. */
 #ifdef COUNT_ACCESSES
 	uint32_t read_mem_accesses; /**< Number of read accesses. */

+ 7 - 1
private-include/print_stats.h

@@ -20,7 +20,13 @@
 
 #include <dmmlib/heap.h>
 
+size_t get_used_space(heap_t *heap);
+size_t get_allocated_space(heap_t *heap);
+
+#ifdef FUTURE_FEATURES
+uint32_t get_requested_space(heap_t *heap);
+#endif /* FUTURE_FEATURES */
+
 void print_stats(allocator_t *allocator);
 
 #endif /* PRINT_STATS_H */
-

+ 1 - 7
src/custom_free.c

@@ -68,13 +68,6 @@ void custom_ahfree(allocator_t *allocator, heap_t* heap, void *ptr) {
 #endif /* COUNT_HOPS */
 #endif /* FUTURE_FEATURES */
 
-#ifdef WITH_STATS
-    heap->dmm_stats.mem_allocated -= size;
-#ifdef FUTURE_FEATURES
-    heap->dmm_stats.mem_requested -= get_requested_size(ptr);
-#endif /* FUTURE_FEATURES */
-#endif /* WITH_STATS */
-
 #if defined (COALESCING_FIXED) || defined (COALESCING_VARIABLE)
     coalesced = false;
 #ifdef COALESCING_FIXED
@@ -222,6 +215,7 @@ void custom_ahfree(allocator_t *allocator, heap_t* heap, void *ptr) {
 
 #ifdef WITH_STATS
     /* Update Stats */
+    heap->dmm_stats.mem_used -= HEADER_SIZE + size;
     heap->dmm_stats.live_objects -= 1;
     heap->dmm_stats.num_free += 1;
     /* End of Stats */

+ 3 - 1
src/custom_malloc.c

@@ -117,8 +117,10 @@ void * custom_ahmalloc(allocator_t* allocator, heap_t* heap, size_t size) {
 
 #ifdef WITH_STATS
         /* Update statistics */
-        heap->dmm_stats.mem_allocated += req_padding(size);
+#ifdef FUTURE_FEATURES
         heap->dmm_stats.mem_requested += size;
+#endif /* FUTURE_FEATURES */
+        heap->dmm_stats.mem_used += HEADER_SIZE + get_size(ptr);
         heap->dmm_stats.live_objects += 1;
         heap->dmm_stats.num_malloc += 1;
 #endif /* WITH_STATS */

+ 4 - 1
src/initialize_allocator.c

@@ -68,8 +68,11 @@ void initialize_allocator(allocator_t *allocator) {
         allocator->heaps[i].num_objects = 0;
 
 #ifdef WITH_STATS
-        allocator->heaps[i].dmm_stats.mem_allocated = 0;
+#ifdef FUTURE_FEATURES
         allocator->heaps[i].dmm_stats.mem_requested = 0;
+#endif /* FUTURE_FEATURES */
+        allocator->heaps[i].dmm_stats.mem_used = 0;
+        allocator->heaps[i].dmm_stats.mem_allocated = 0;
         allocator->heaps[i].dmm_stats.live_objects = 0;
 #ifdef COUNT_ACCESSES
         allocator->heaps[i].dmm_stats.read_mem_accesses = 0;

+ 19 - 1
src/print_stats.c

@@ -15,11 +15,25 @@
  *
  */
 
-#include "print_stats.h"
+#include <dmmlib/print_stats.h>
 #include "dmm_config.h"
 
 #include <stdio.h>
 
+size_t get_allocated_space(heap_t *heap) {
+    return heap->dmm_stats.mem_allocated;
+}
+
+size_t get_used_space(heap_t *heap) {
+    return heap->dmm_stats.mem_used;
+}
+
+#ifdef FUTURE_FEATURES
+uint32_t get_requested_space(heap_t *heap) {
+    return heap->dmm_stats.mem_requested;
+}
+#endif /* FUTURE_FEATURES */
+
 void print_stats(allocator_t *allocator) {
     int i;
 
@@ -29,9 +43,13 @@ void print_stats(allocator_t *allocator) {
                 (int) allocator->heaps[i].dmm_stats.num_malloc);
         printf("Total free() calls: %d\n",
                 (int) allocator->heaps[i].dmm_stats.num_free);
+        printf("Memory currently used: %d\n",
+                (int) allocator->heaps[i].dmm_stats.mem_used);
         printf("Memory currently allocated: %d\n",
                 (int) allocator->heaps[i].dmm_stats.mem_allocated);
+#ifdef FUTURE_FEATURES
         printf("Memory currently requested: %d\n",
                 (int) allocator->heaps[i].dmm_stats.mem_requested);
+#endif /* FUTURE_FEATURES */
     }
 }

+ 5 - 2
src/sys_alloc.c

@@ -35,7 +35,7 @@
 #include "other.h"
 #include "block_header.h"
 #ifdef WITH_STATS
-#include "print_stats.h"
+#include <dmmlib/print_stats.h>
 #endif /* WITH_STATS */
 
 #ifdef WITH_MMAP
@@ -150,8 +150,11 @@ void *sys_alloc(allocator_t *allocator, heap_t *heap, size_t size) {
 
 #ifdef WITH_STATS
     /* Update statistics */
-    heap->dmm_stats.mem_allocated += req_padding(size);
+#ifdef FUTURE_FEATURES
     heap->dmm_stats.mem_requested += size;
+#endif /* FUTURE_FEATURES */
+    heap->dmm_stats.mem_used += HEADER_SIZE + req_padding(size);
+    heap->dmm_stats.mem_allocated += HEADER_SIZE + req_padding(size);
     heap->dmm_stats.live_objects += 1;
     heap->dmm_stats.num_malloc += 1;
 #endif /* WITH_STATS */