Browse Source

Initial support for printing stats.

Ioannis Koutras 13 years ago
parent
commit
caa5ae3815
4 changed files with 62 additions and 0 deletions
  1. 26 0
      private-include/print_stats.h
  2. 1 0
      src/CMakeLists.txt
  3. 33 0
      src/print_stats.c
  4. 2 0
      src/sys_alloc.c

+ 26 - 0
private-include/print_stats.h

@@ -0,0 +1,26 @@
+/*
+ *   Copyright 2011 Institute of Communication and Computer Systems (ICCS) 
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+
+#ifndef PRINT_STATS_H
+#define PRINT_STATS_H
+
+#include <dmmlib/heap.h>
+
+void print_stats(allocator_t *allocator);
+
+#endif /* PRINT_STATS_H */
+

+ 1 - 0
src/CMakeLists.txt

@@ -38,6 +38,7 @@ set(dmmlib_SRCS
   initialize_allocator.c
   sys_alloc.c
   dmm_adaptor.c
+  print_stats.c
 )
 
 if (HAVE_LOCKS)

+ 33 - 0
src/print_stats.c

@@ -0,0 +1,33 @@
+/*
+ *   Copyright 2011 Institute of Communication and Computer Systems (ICCS) 
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+
+#include "print_stats.h"
+#include "dmm_config.h"
+
+#include <stdio.h>
+
+void print_stats(allocator_t *allocator) {
+    int i;
+
+    for(i = 0; i < NUM_HEAPS; i++) {
+        printf("Heap %d statistics:\n", i);
+        printf("Memory currently allocated: %d\n",
+                allocator->heaps[i].dmm_stats.mem_allocated);
+        printf("Memory currently requested: %d\n",
+                allocator->heaps[i].dmm_stats.mem_requested);
+    }
+}

+ 2 - 0
src/sys_alloc.c

@@ -27,6 +27,7 @@
 #include "other.h"
 #include "sys_alloc.h"
 #include "block_header.h"
+#include "print_stats.h"
 
 void *sys_alloc(allocator_t *allocator, heap_t *heap, size_t size) {
 
@@ -52,6 +53,7 @@ void *sys_alloc(allocator_t *allocator, heap_t *heap, size_t size) {
     if(ptr == (void *) -1) {
         printf("sbrk problem for size of: %zu\n", allocation_size);
         printf("Error on sbrk: %s\n", strerror( errno ) );
+        print_stats(allocator);
         return NULL;
     }   
 #if defined (COALESCING_FIXED) || defined (COALESCING_VARIABLE)