Browse Source

Initial DMM statistics support.

Ioannis Koutras 13 years ago
parent
commit
0db7c47a56
4 changed files with 31 additions and 3 deletions
  1. 7 0
      custom_free.c
  2. 19 1
      custom_malloc.c
  3. 3 0
      dmm_init.c
  4. 2 2
      larson.c

+ 7 - 0
custom_free.c

@@ -30,6 +30,13 @@ void custom_free(heap_t* heap, void *ptr) {
 		heap->free_list_head = ptr;
 	}
 
+	// Begin of Stats
+
+	heap->dmm_stats.live_objects -= 1;
+	heap->dmm_stats.num_free += 1;
+
+	// End of Stats
+
 	posix_unlock(heap);
 }
 

+ 19 - 1
custom_malloc.c

@@ -39,7 +39,8 @@ void * custom_malloc(heap_t* heap, size_t size) {
 		found = 0;
 
 		// first fit from free list
-		for(current_block = heap->free_list_head; current_block != NULL; current_block = get_next(current_block)) {
+		for(current_block = heap->free_list_head; current_block != NULL;
+				current_block = get_next(current_block)) {
 			if(get_size(current_block) >= size) {
 				ptr = current_block;
 				heap->used_blocks_head = ptr;
@@ -50,6 +51,14 @@ void * custom_malloc(heap_t* heap, size_t size) {
 				}
 				set_requested_size(ptr, size);
 				set_next(ptr, heap->used_blocks_head);
+
+				// Begin of Stats
+
+				heap->dmm_stats.live_objects += 1;
+				heap->dmm_stats.num_malloc += 1;
+
+				// End of Stats
+
 				posix_unlock(heap);
 				return ptr;
 			}
@@ -58,10 +67,19 @@ void * custom_malloc(heap_t* heap, size_t size) {
 
 		if(!found) {
 			ptr = sys_alloc(heap, size);
+			heap->dmm_stats.mem_allocated += req_padding(size);
+			heap->dmm_stats.mem_requested += size;
 		}
 
 	}
 
+	// Begin of Stats
+
+	heap->dmm_stats.live_objects += 1;
+	heap->dmm_stats.num_malloc += 1;
+
+	// End of Stats
+
 	posix_unlock(heap);
 	return ptr;
 }

+ 3 - 0
dmm_init.c

@@ -17,6 +17,9 @@ allocator_t * dmm_init(void) {
 		main_allocator->heaps[i].used_blocks_head = NULL;
 		main_allocator->heaps[i].rov_ptr = NULL;
 		main_allocator->heaps[i].num_objects = 0;
+		main_allocator->heaps[i].dmm_stats.mem_allocated = 0;
+		main_allocator->heaps[i].dmm_stats.mem_requested = 0;
+		main_allocator->heaps[i].dmm_stats.live_objects = 0;
 		main_allocator->heaps[i].dmm_stats.num_malloc = 0;
 		main_allocator->heaps[i].dmm_stats.num_free = 0;
 		pthread_mutex_init(&main_allocator->heaps[i].mutex, NULL);

+ 2 - 2
larson.c

@@ -298,8 +298,8 @@ int main(void) {
 	
 	printf("chunk size (min,max): ") ;
 	//scanf("%d %d", &min_size, &max_size ) ;
-	min_size = 1024;
-	max_size = 2048;
+	min_size = 32;
+	max_size = 256;
 	
 	printf("threads (min, max):   ") ; 
 	//scanf("%d %d", &min_threads, &max_threads) ;