Browse Source

Initial tracing support

Ioannis Koutras 12 years ago
parent
commit
122adcb347
5 changed files with 80 additions and 1 deletions
  1. 1 0
      DefineOptions.cmake
  2. 2 0
      dmm_config.h.in
  3. 55 0
      private-include/trace.h
  4. 13 0
      src/bitmap/bitmap_free.c
  5. 9 1
      src/bitmap/bitmap_malloc.c

+ 1 - 0
DefineOptions.cmake

@@ -2,6 +2,7 @@ set(WITH_SYSTEM_CALLS "none" CACHE STRING "Choose what system calls can be used,
 set(RAW_BLOCKS_TYPE "bitmap" CACHE STRING "Choose what raw blocks can be used, options are: freelist, bitmap")
 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)
 option(WITH_FIXED_LISTS "Build with predefined lists of fixed-sized blocks" ON)
 option(WITH_STATS "Build with statistics" OFF)

+ 2 - 0
dmm_config.h.in

@@ -6,6 +6,8 @@
 #cmakedefine SYS_ALLOC_SIZE @SYS_ALLOC_SIZE@
 #cmakedefine HAVE_LOCKS
 
+#cmakedefine TRACE_LEVEL @TRACE_LEVEL@
+
 #cmakedefine LIFO_SORT_POLICY
 #cmakedefine FIFO_SORT_POLICY
 #cmakedefine SIZE_SORT_POLICY

+ 55 - 0
private-include/trace.h

@@ -0,0 +1,55 @@
+/*
+ *   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   trace.h
+ * @author Ioannis Koutras (joko@microlab.ntua.gr)
+ * @date   September 2012
+ * @brief  Tracing functions
+ */
+
+#ifndef TRACE_H
+#define TRACE_H
+#include "dmm_config.h"
+
+#include <stdio.h>
+
+#if TRACE_LEVEL >= 1
+/** Function for Level 1 trace messages */
+#define TRACE_1(...) fprintf(stderr, __VA_ARGS__)
+#else /* TRACE_LEVEL >= 1 */
+/** Function for Level 1 trace messages */
+#define TRACE_1(...) /* do nothing */
+#endif /* TRACE_LEVEL >= 1 */
+
+#if TRACE_LEVEL >= 2
+/** Function for Level 2 trace messages */
+#define TRACE_2(...) fprintf(stderr, __VA_ARGS__)
+#else /* TRACE_LEVEL >= 2 */
+/** Function for Level 2 trace messages */
+#define TRACE_2(...) /* do nothing */
+#endif /* TRACE_LEVEL >= 2 */
+
+#if TRACE_LEVEL >= 3
+/** Function for Level 3 trace messages */
+#define TRACE_3(...) fprintf(stderr, __VA_ARGS__)
+#else /* TRACE_LEVEL >= 3 */
+/** Function for Level 3 trace messages */
+#define TRACE_3(...) /* do nothing */
+#endif /* TRACE_LEVEL >= 3 */
+
+#endif /* TRACE_H */

+ 13 - 0
src/bitmap/bitmap_free.c

@@ -26,6 +26,8 @@
 #include "bitmap/bitmap_rb.h"
 #include "bitmap/bitmap_other.h"
 
+#include "trace.h"
+
 #ifdef HAVE_LOCKS
 #include <pthread.h>
 #endif /* HAVE_LOCKS */
@@ -49,6 +51,17 @@ void bitmap_free(raw_block_header_t *raw_block, void *ptr) {
 
     cells_used = chunk_header->num_of_cells;
 
+#ifndef REQUEST_SIZE_INFO
+    TRACE_1("dmmlib - free - free'ing %zu bytes from bitmap raw block %p\n",
+            cells_used * rb_header->bytes_per_cell, (void *)raw_block);
+#else /* REQUEST_SIZE_INFO */
+    TRACE_1("dmmlib - free - free'ing %zu bytes from bitmap raw block %p, out of "
+            "which %zu were used by the application\n",
+            cells_used * rb_header->bytes_per_cell,
+            (void *)raw_block,
+            chunk_header->requested_size);
+#endif /* REQUEST_SIZE_INFO */
+
     cell_no = ((char *)chunk_header - ((char *)rb_header + sizeof(bitmap_rb_t)))
         / rb_header->bytes_per_cell;
 

+ 9 - 1
src/bitmap/bitmap_malloc.c

@@ -26,6 +26,8 @@
 #include "bitmap/bitmap_rb.h"
 #include "bitmap/bitmap_other.h"
 
+#include "trace.h"
+
 #ifdef HAVE_LOCKS
 #include <pthread.h>
 #endif /* HAVE_LOCKS */
@@ -101,11 +103,17 @@ void * bitmap_malloc(raw_block_header_t *raw_block, size_t req_size) {
                     rb_header->bytes_per_cell);
             chunk_address->num_of_cells = cells;
 #ifdef REQUEST_SIZE_INFO
-            chunk_address->requested_size = req_size;
+            chunk_address->requested_size = req_size - sizeof(chunk_header_t);
 #endif /* REQUEST_SIZE_INFO */
 
             ret = (void *)((char *)chunk_address + sizeof(chunk_header_t));
 
+            TRACE_1("dmmlib - malloc - allocated %zu bytes for a memory request"
+                    " of %zu bytes at bitmap raw block %p...\n",
+                    cells * rb_header->bytes_per_cell,
+                    req_size - sizeof(chunk_header_t),
+                    (void *)raw_block);
+
             break;
         }
     }