Explorar o código

Formalized and integrated the debug functions for a quick check

Ioannis Koutras %!s(int64=12) %!d(string=hai) anos
pai
achega
f1e1240677
Modificáronse 6 ficheiros con 96 adicións e 12 borrados
  1. 2 1
      DefineOptions.cmake
  2. 2 2
      dmm_config.h.in
  3. 38 1
      private-include/debug.h
  4. 7 1
      src/CMakeLists.txt
  5. 39 7
      src/debug.c
  6. 8 0
      src/dmmlib.c

+ 2 - 1
DefineOptions.cmake

@@ -3,8 +3,9 @@ set(RAW_BLOCKS_TYPE "bitmap" CACHE STRING "Choose what raw blocks can be used, o
 option(HAVE_LOCKS "Build with POSIX locking mechanisms" ON)
 option(WITH_REALLOC "Build with realloc" OFF)
 set(TRACE_LEVEL 1 CACHE INTEGER "Choose the trace level, options are: 0, 1, 2 and 3")
-option(WITH_EXAMPLES "Build with examples" OFF)
 set(STATS "global" CACHE STRING "Choose if the memory allocator keeps internally statistics per raw block or globally, options are: none, rawblock, global")
+option(WITH_DEBUG "Build with debugging functions" ON)
+option(WITH_EXAMPLES "Build with examples" OFF)
 option(WITH_ADAPTIVITY "Build with adaptivity" OFF)
 option(WITH_STATIC_LIB "Build a static library" OFF)
 option(WITH_SHARED_LIB "Build a shared library" OFF)

+ 2 - 2
dmm_config.h.in

@@ -42,11 +42,11 @@
 
 #cmakedefine WITH_RAWBLOCK_STATS
 #cmakedefine WITH_ALLOCATOR_STATS
-#cmakedefine COUNT_ACCESSES
-#cmakedefine COUNT_HOPS
 
 #cmakedefine WITH_KNOBS
 
+#cmakedefine WITH_DEBUG
+
 #cmakedefine WITH_ADAPTIVITY
 
 #cmakedefine BLOCKS_IN_SLL

+ 38 - 1
private-include/debug.h

@@ -1,5 +1,42 @@
-#include <dmmlib/pool.h>
+/*
+ *   Copyright 2012 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   debug.h
+ * @author Ioannis Koutras (joko@microlab.ntua.gr)
+ * @date   September 2012
+ * @brief  Debug functions
+ */
+
+#ifndef DEBUG_H
+#define DEBUG_H
 #include "dmm_config.h"
 
+#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 */

+ 7 - 1
src/CMakeLists.txt

@@ -32,7 +32,6 @@ set(dmmlib_SRCS
   dmmlib.c
   raw_block.c
   release_memory.c
-  #debug.c FIXME
 )
 
 if(RAW_BLOCKS_TYPE STREQUAL "freelist")
@@ -118,6 +117,13 @@ elseif(WITH_SYSTEM_CALLS STREQUAL "mmap")
 
 endif(WITH_SYSTEM_CALLS STREQUAL "none")
 
+if(WITH_DEBUG)
+  set(dmmlib_SRCS
+    ${dmmlib_SRCS}
+    debug.c
+  )
+endif(WITH_DEBUG)
+
 if (WITH_REALLOC)
   set(dmmlib_SRCS
     ${dmmlib_SRCS}

+ 39 - 7
src/debug.c

@@ -1,8 +1,36 @@
-#include <stdio.h>
-#include "dmmlib/block_header.h"
+/*
+ *   Copyright 2012 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   debug.c
+ * @author Ioannis Koutras (joko@microlab.ntua.gr)
+ * @date   September 2012
+ * @brief  Debug functions implementation
+ */
+
+#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"
-#include "debug.h"
+#endif /* FL_RB_ONLY */
+
+#include "trace.h"
 
 void get_raw_blocks(allocator_t *allocator) {
     int counter;
@@ -13,16 +41,18 @@ void get_raw_blocks(allocator_t *allocator) {
 
     while(current_raw_block) {
         counter++;
-        printf("Raw block at %p with remaining size %zu\n",
+        TRACE_1("dmmlib - Raw block at %p of size %zu\n",
                 (void *)current_raw_block,
-                current_raw_block->remaining_size);
+                current_raw_block->size);
         current_raw_block = current_raw_block->next_raw_block;
     }
 
-    printf("There are %d raw blocks\n", counter);
+    TRACE_1("dmmlib - there are %d raw blocks\n", counter);
 
 }
 
+#ifdef FL_RB_ONLY
+
 void get_memory_blocks(raw_block_header_t *raw_block) {
     block_header_t *memory_block;
     int counter;
@@ -37,6 +67,8 @@ void get_memory_blocks(raw_block_header_t *raw_block) {
         memory_block = memory_block->next;
     }
 
-    printf("Raw block at %p has %d memory blocks\n",
+    TRACE_1("Raw block at %p has %d memory blocks\n",
             (void *)raw_block, counter);
 }
+
+#endif /* FL_RB_ONLY */

+ 8 - 0
src/dmmlib.c

@@ -38,6 +38,10 @@
 
 #include "trace.h"
 
+#ifdef WITH_DEBUG
+#include "debug.h"
+#endif /* WITH_DEBUG */
+
 void * malloc(size_t size) {
     raw_block_header_t *raw_block, *new_raw_block;
     size_t allocation_size;
@@ -111,6 +115,10 @@ void * malloc(size_t size) {
         }
     }
     
+#ifdef WITH_DEBUG
+    get_raw_blocks(&systemallocator);
+#endif /* WITH_DEBUG */
+
     return ptr;
 }