Browse Source

Separated debug functions for freelist-organised raw blocks

Ioannis Koutras 13 years ago
parent
commit
04f75ced96
5 changed files with 95 additions and 42 deletions
  1. 1 10
      private-include/debug.h
  2. 33 0
      private-include/freelist/freelist_debug.h
  3. 7 0
      src/CMakeLists.txt
  4. 1 32
      src/debug.c
  5. 53 0
      src/freelist/freelist_debug.c

+ 1 - 10
private-include/debug.h

@@ -1,5 +1,5 @@
 /*
- *   Copyright 2012 Institute of Communication and Computer Systems (ICCS) 
+ *   Copyright 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.
@@ -28,15 +28,6 @@
 
 #include "dmmlib/allocator.h"
 
-#ifdef FL_RB_ONLY
-#include "dmmlib/raw_block.h"
-#endif /* FL_RB_ONLY */
-
 void get_raw_blocks(allocator_t *allocator);
 
-// FIXME separate debugging functions for different raw blocks
-#ifdef FL_RB_ONLY
-void get_memory_blocks(raw_block_header_t *raw_block);
-#endif /* FL_RB_ONLY */
-
 #endif /* DEBUG_H */

+ 33 - 0
private-include/freelist/freelist_debug.h

@@ -0,0 +1,33 @@
+/*
+ *   Copyright 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.
+ *
+ */
+
+/**
+ * @file   freelist_debug.h
+ * @author Ioannis Koutras (joko@microlab.ntua.gr)
+ * @date   September 2012
+ * @brief  Debug functions for freelist-organised raw blocks
+ */
+
+#ifndef FREELIST_DEBUG_H
+#define FREELIST_DEBUG_H
+#include "dmm_config.h"
+
+#include "freelist/freelist_rb.h"
+
+void get_memory_blocks(freelist_rb_t *raw_block);
+
+#endif /* FREELIST_DEBUG_H */

+ 7 - 0
src/CMakeLists.txt

@@ -87,6 +87,13 @@ if(RAW_BLOCKS_TYPE STREQUAL "freelist")
       )
   endif(SPLITTING_FIXED OR SPLITTING_VARIABLE)
 
+  if(WITH_DEBUG)
+    set(dmmlib_SRCS
+      ${dmmlib_SRCS}
+      freelist/freelist_debug.c
+      )
+  endif(WITH_DEBUG)
+
 elseif(RAW_BLOCKS_TYPE STREQUAL "bitmap")
 
   set(dmmlib_SRCS

+ 1 - 32
src/debug.c

@@ -1,5 +1,5 @@
 /*
- *   Copyright 2012 Institute of Communication and Computer Systems (ICCS) 
+ *   Copyright 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.
@@ -24,12 +24,6 @@
 
 #include "debug.h"
 
-#ifdef FL_RB_ONLY 
-#include "freelist/block_header.h"
-#include "freelist/block_header_funcs.h"
-#include "freelist/linked_lists/search_algorithms.h"
-#endif /* FL_RB_ONLY */
-
 #include "trace.h"
 
 /** Gets the number of raw blocks that are currently managed by an allocator.
@@ -54,28 +48,3 @@ void get_raw_blocks(allocator_t *allocator) {
     TRACE_1("dmmlib - there are %d raw blocks\n", counter);
 
 }
-
-#ifdef FL_RB_ONLY
-
-void get_memory_blocks(raw_block_header_t *raw_block) {
-    freelist_rb_t *rb_header;
-    block_header_t *memory_block;
-    int counter;
-
-    rb_header = (freelist_rb_t *)((char *)raw_block +
-            sizeof(raw_block_header_t));
-    memory_block = rb_header->free_list_head;
-    counter = 0;
-
-    while(memory_block) {
-        counter++;
-        printf("Free memory block at %p with size %zu\n",
-                (void *)memory_block, get_size(memory_block));
-        memory_block = memory_block->next;
-    }
-
-    TRACE_1("Raw block at %p has %d memory blocks\n",
-            (void *)raw_block, counter);
-}
-
-#endif /* FL_RB_ONLY */

+ 53 - 0
src/freelist/freelist_debug.c

@@ -0,0 +1,53 @@
+/*
+ *   Copyright 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.
+ *
+ */
+
+/**
+ * @file   freelist_debug.c
+ * @author Ioannis Koutras (joko@microlab.ntua.gr)
+ * @date   September 2012
+ * @brief  Debug functions implementation for freelist-organised raw blocks
+ */
+
+#include "freelist/freelist_debug.h"
+
+#include "freelist/block_header.h"
+#include "freelist/block_header_funcs.h"
+#include "freelist/linked_lists/search_algorithms.h"
+
+#include "trace.h"
+
+/** Prints the list of free blocks of a specific freelist-organised raw block.
+ *
+ * @param raw_block The pointer of the freelist raw block.
+ */
+void get_memory_blocks(freelist_rb_t *raw_block) {
+    block_header_t *memory_block;
+    int counter;
+
+    memory_block = raw_block->free_list_head;
+    counter = 0;
+
+    while(memory_block) {
+        counter++;
+        TRACE_1("Free memory block at %p with size %zu\n",
+                (void *)memory_block, get_size(memory_block));
+        memory_block = memory_block->next;
+    }
+
+    TRACE_1("Raw block at %p has %d memory blocks\n",
+            (void *)raw_block, counter);
+}