Pārlūkot izejas kodu

bitmap: add debug functions

Ioannis Koutras 13 gadi atpakaļ
vecāks
revīzija
87b3e9480b
5 mainītis faili ar 125 papildinājumiem un 2 dzēšanām
  1. 36 0
      private-include/bitmap/debug.h
  2. 1 1
      private-include/debug.h
  3. 7 0
      src/CMakeLists.txt
  4. 80 0
      src/bitmap/debug.c
  5. 1 1
      src/debug.c

+ 36 - 0
private-include/bitmap/debug.h

@@ -0,0 +1,36 @@
+/*
+ *   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   bitmap/debug.h
+ * @author Ioannis Koutras (joko@microlab.ntua.gr)
+ * @date   October 2012
+ * @brief  Debug functions for bitmap-organized raw blocks
+ */
+
+#ifndef BITMAP_DEBUG_H
+#define BITMAP_DEBUG_H
+#include "dmm_config.h"
+
+#include "bitmap/bitmap_rb.h"
+
+/** Returns the binary representation of the bitmap vector of a bitmap-organized
+ * raw block.
+ */
+void print_bitmap_vector(bitmap_rb_t *raw_block);
+
+#endif /* BITMAP_DEBUG_H */

+ 1 - 1
private-include/debug.h

@@ -16,7 +16,7 @@
  */
 
 /**
- * @file   debug.h
+ * @file   private-include/debug.h
  * @author Ioannis Koutras (joko@microlab.ntua.gr)
  * @date   September 2012
  * @brief  Debug functions

+ 7 - 0
src/CMakeLists.txt

@@ -137,6 +137,13 @@ elseif(RAW_BLOCKS_TYPE STREQUAL "bitmap")
     memmove.c
     )
 
+  if(WITH_DEBUG)
+    set(dmmlib_SRCS
+      ${dmmlib_SRCS}
+      bitmap/debug.c
+      )
+  endif(WITH_DEBUG)
+
 endif(RAW_BLOCKS_TYPE STREQUAL "freelist")
 
 if(WITH_SYSTEM_CALLS STREQUAL "none")

+ 80 - 0
src/bitmap/debug.c

@@ -0,0 +1,80 @@
+/*
+ *   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   bitmap/debug.c
+ * @author Ioannis Koutras (joko@microlab.ntua.gr)
+ * @date   October 2012
+ * @brief  Debug functions implementation for bitmap-organised raw blocks
+ */
+
+#include "bitmap/debug.h"
+
+#include <inttypes.h>
+#include <string.h>
+
+#include "trace.h"
+
+/**
+ * Returns the number of used cells (including the ones of the bitmap vector not
+ * actually used) in a bitmap-organized raw block.
+ */
+size_t get_used_cells(bitmap_rb_t *raw_block);
+
+size_t get_used_cells(bitmap_rb_t *raw_block) {
+    size_t count, i, j;
+    BMAP_EL_TYPE *bmap_p, buffer;
+
+    bmap_p = (BMAP_EL_TYPE *)((uintptr_t) raw_block + sizeof(bitmap_rb_t));
+    count = 0;
+
+    for(i = 0; i < raw_block->elements; i++) {
+        buffer = *bmap_p;
+        for(j = 0; j < BMAP_EL_SIZE_BITS; j++) {
+            if((buffer & (BMAP_EL_TYPE) 1) == (BMAP_EL_TYPE) 1) {
+                count++;
+            }
+            buffer >>= 1;
+        }
+        bmap_p++;
+    }
+    return raw_block->elements * BMAP_EL_SIZE_BITS - count;
+}
+
+void print_bitmap_vector(bitmap_rb_t *raw_block) {
+    char output[raw_block->elements * BMAP_EL_SIZE_BITS + 1], *el_out;
+    BMAP_EL_TYPE *bmap_p, z;
+
+    bmap_p = (BMAP_EL_TYPE *)((uintptr_t) raw_block + sizeof(bitmap_rb_t));
+
+    output[0] = '\0';
+
+    el_out = &output[0];
+
+    for(size_t i = 0; i < raw_block->elements; i++) {
+        for(z = ((BMAP_EL_TYPE) 1 << (BMAP_EL_SIZE_BITS - 1)); z > 0; z >>=1) {
+            strcat(el_out, ((*bmap_p & z) == z) ? "0" : "1");
+        }
+        el_out += BMAP_EL_SIZE_BITS;
+        bmap_p++;
+    }
+
+    TRACE_3("Bitmap vector: %s\n", output);
+    TRACE_3("dmmlib - mem - bm - %zu\n", get_used_cells(raw_block));
+
+    return;
+}

+ 1 - 1
src/debug.c

@@ -16,7 +16,7 @@
  */
 
 /**
- * @file   debug.c
+ * @file   src/debug.c
  * @author Ioannis Koutras (joko@microlab.ntua.gr)
  * @date   September 2012
  * @brief  Debug functions implementation