Browse Source

fixes on debug traces

Ioannis Koutras 12 years ago
parent
commit
9d1fec9368
6 changed files with 27 additions and 7 deletions
  1. 4 0
      include/dmmlib/CMakeLists.txt
  2. 1 1
      private-include/debug.h
  3. 1 1
      src/debug.c
  4. 1 1
      src/malloc.c
  5. 18 3
      src/parse_env.c
  6. 2 1
      src/realloc.c

+ 4 - 0
include/dmmlib/CMakeLists.txt

@@ -8,6 +8,10 @@ set(dmmlib_HDRS
   lists.h
 )
 
+if(WITH_DEBUG)
+  set(dmmlib_HDRS ${dmmlib_HDRS} debug.h)
+endif(WITH_DEBUG)
+
 if(WITH_KNOBS)
   set(dmmlib_HDRS ${dmmlib_HDRS} knobs.h)
 endif(WITH_KNOBS)

+ 1 - 1
private-include/debug.h

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

+ 1 - 1
src/debug.c

@@ -22,7 +22,7 @@
  * @brief  Debug functions implementation
  */
 
-#include "debug.h"
+#include "dmmlib/debug.h"
 
 #include "trace.h"
 #include <stdbool.h>

+ 1 - 1
src/malloc.c

@@ -28,12 +28,12 @@
 #include <inttypes.h>
 #include <assert.h>
 
+#include "dmmlib/debug.h"
 #include "dmmlib/lists.h"
 
 #include "locks.h"
 #include "default_rb.h"
 
-#include "debug.h"
 #include "statistics.h"
 #include "trace.h"
 

+ 18 - 3
src/parse_env.c

@@ -59,12 +59,22 @@ void parse_env(void) {
     }
 #endif /* WITH_STATS_TRACE */
 
-    systemallocator.initialized = true;
+#ifdef WITH_DEBUG
+    env = getenv("DMMLIB_DBG_TRACE");
+
+    if(env == NULL) {
+        dbg_fd = stderr;
+    } else {
+        dbg_fd = fopen(env, "a+");
+    }
+#endif /* WITH_DEBUG */
+
+   systemallocator.initialized = true;
 
     return;
 }
 
-#if defined WITH_MEM_TRACE || defined WITH_STATS_TRACE
+#if defined WITH_MEM_TRACE || defined WITH_STATS_TRACE || defined WITH_DEBUG
 __attribute__((destructor)) void close_trace_files(void);
 
 /** Closes the opened trace files. */
@@ -79,6 +89,11 @@ void close_trace_files(void) {
         fclose(stats_fd);
     }
 #endif /* WITH_STATS_TRACE */
+#ifdef WITH_DEBUG
+    if(dbg_fd != stderr) {
+        fclose(dbg_fd);
+    }
+#endif /* WITH_DEBUG */
     return;
 }
-#endif /* WITH_MEM_TRACE || WITH_STATS_TRACE */
+#endif /* WITH_MEM_TRACE || WITH_STATS_TRACE || WITH_DEBUG */

+ 2 - 1
src/realloc.c

@@ -25,6 +25,8 @@
 
 #include "dmmlib/dmmlib.h"
 
+#include "dmmlib/debug.h"
+
 #include "locks.h"
 #include "default_rb.h"
 #include "other.h"
@@ -35,7 +37,6 @@
 
 #include "memcpy.h"
 
-#include "debug.h"
 #include "trace.h"
 
 void * realloc(void *ptr, size_t size) {