浏览代码

support for using trace files and parsing environment variables

Ioannis Koutras 12 年之前
父节点
当前提交
d8b415d87a

+ 3 - 1
CMakeLists.txt

@@ -190,8 +190,10 @@ message(STATUS "Have knobs: " ${WITH_KNOBS})
 message(STATUS "Have statistics: " ${STATS})
 message(STATUS "Requested Size per Block: " ${REQUEST_SIZE_INFO})
 message(STATUS "Support for debug functions: " ${WITH_DEBUG})
-message(STATUS "Trace level: " ${TRACE_LEVEL})
+message(STATUS "Support for memory traces: " ${WITH_MEM_TRACE})
+message(STATUS "Support for statistics traces: " ${WITH_STATS_TRACE})
 message(STATUS "Support for realloc(): " ${WITH_REALLOC})
 message(STATUS "Support for calloc(): " ${WITH_CALLOC})
 message(STATUS "Support for memalign(): " ${WITH_MEMALIGN})
+message(STATUS "Support to parse dmmlib environment variables: " ${PARSE_ENV})
 message(STATUS "********************************************")

+ 12 - 4
DefineOptions.cmake

@@ -40,7 +40,8 @@ set(REQUEST_SIZE_INFO OFF)
 
 # Trace Settings
 
-set(TRACE_LEVEL 0 CACHE INTEGER "Choose the trace level, options are: 0, 1, 2 and 3")
+option(WITH_MEM_TRACE "Support for memory traces" OFF)
+option(WITH_STATS_TRACE "Support for statistics traces" OFF)
 
 # Build Settings
 
@@ -49,6 +50,7 @@ option(WITH_SHARED_LIB "Build a shared library" OFF)
 
 # Misc Settings
 
+option(PARSE_ENV "Build with support to parse dmmlib environment variables" OFF)
 option(WITH_EXAMPLES "Build with examples" OFF)
 option(WITH_DOC "Build with documentation" OFF)
 
@@ -72,9 +74,11 @@ if(P2012)
   set(WITH_KNOBS OFF)
   set(STATS "none")
   set(REQUEST_SIZE_INFO OFF)
-  set(TRACE_LEVEL 0)
+  set(WITH_MEM_TRACE OFF)
+  set(WITH_STATS_TRACE OFF)
   set(WITH_STATIC_LIB ON)
   set(WITH_SHARED_LIB OFF)
+  set(PARSE_ENV OFF)
   set(WITH_EXAMPLES OFF)
   set(WITH_DOC OFF)
 endif(P2012)
@@ -93,9 +97,11 @@ if(LEON3)
   set(WITH_KNOBS OFF)
   set(STATS "none")
   set(REQUEST_SIZE_INFO OFF)
-  set(TRACE_LEVEL 0)
+  set(WITH_MEM_TRACE OFF)
+  set(WITH_STATS_TRACE OFF)
   set(WITH_STATIC_LIB ON)
   set(WITH_SHARED_LIB OFF)
+  set(PARSE_ENV OFF)
   set(WITH_EXAMPLES OFF)
   set(WITH_DOC OFF)
 endif(LEON3)
@@ -113,15 +119,17 @@ if(LINUX)
   set(WITH_SPLITTING "variable")
   set(MIN_SPLITTING_SIZE 64)
   set(FREELIST_COALESCE_AFTER_SPLIT ON)
-  set(TRACE_LEVEL 3)
   set(WITH_REALLOC ON)
   set(WITH_CALLOC ON)
   set(WITH_MEMALIGN ON)
   set(WITH_KNOBS ON)
   set(STATS "global")
   set(REQUEST_SIZE_INFO ON)
+  set(WITH_MEM_TRACE ON)
+  set(WITH_STATS_TRACE ON)
   set(WITH_SHARED_LIB ON)
   set(WITH_STATIC_LIB ON)
+  set(PARSE_ENV ON)
   set(WITH_EXAMPLES ON)
   set(WITH_DOC ON)
 endif(LINUX)

+ 8 - 3
dmm_config.h.in

@@ -40,9 +40,6 @@
 /** Support for locks */
 #cmakedefine HAVE_LOCKS
 
-/** Trace level */
-#cmakedefine TRACE_LEVEL @TRACE_LEVEL@
-
 /* Free-list Settings */
 #ifdef FL_RB_ONLY
 
@@ -117,9 +114,17 @@
 /** Support for debugging functions */
 #cmakedefine WITH_DEBUG
 
+/** Support for memory trace */
+#cmakedefine WITH_MEM_TRACE
+/** Support for statistics trace */
+#cmakedefine WITH_STATS_TRACE
+
 /** Support for realloc() calls */
 #cmakedefine WITH_REALLOC
 
+/** Support to parse dmmlib environment variables */
+#cmakedefine PARSE_ENV
+
 /** Support for memalign() calls */
 #cmakedefine WITH_MEMALIGN
 

+ 16 - 0
include/dmmlib/allocator.h

@@ -39,6 +39,12 @@
 #include <dmmlib/dmmstats.h>
 #endif /* WITH_ALLOCATOR_STATS */
 
+#ifdef PARSE_ENV
+#if defined  WITH_MEM_TRACE || defined WITH_STATS_TRACE || defined WITH_DEBUG
+#include <stdbool.h>
+#endif /* WITH_MEM_TRACE || WITH_STATS_TRACE || WITH_DEBUG */
+#endif /* PARSE_ENV */
+
 /** The allocator structure of dmmlib. */
 typedef struct allocator_s {
     /** The head of the raw blocks list. */
@@ -57,6 +63,16 @@ typedef struct allocator_s {
 #ifdef WITH_ALLOCATOR_STATS
     dmmstats_t dmm_stats; /**< Global statistics. */
 #endif /* WITH_ALLOCATOR_STATS */
+
+#ifdef PARSE_ENV
+#if defined  WITH_MEM_TRACE || defined WITH_STATS_TRACE || defined WITH_DEBUG
+    /* During initialization it is possible that some files are being opened to
+     * write the traces, so some dynamic memory is requested. For such cases the
+     * trace functions should not be run. */
+    bool initialized; /**< Initialization value. */
+#endif /* WITH_MEM_TRACE || WITH_STATS_TRACE || WITH_DEBUG */
+#endif /* PARSE_ENV */
+
 } allocator_t;
 
 #endif /* ALLOCATOR_H */

+ 4 - 6
private-include/statistics.h

@@ -36,13 +36,11 @@ typedef enum dmm_event_type_en {
 } dmm_event_type;
 
 void update_stats
-(
- dmmstats_t *dmm_stats,
- dmm_event_type event,
+  ( dmmstats_t *dmm_stats
+  , dmm_event_type event
 #ifdef REQUEST_SIZE_INFO
- size_t mem_req,
+  , size_t mem_req
 #endif /* REQUEST_SIZE_INFO */
- size_t mem_alloc
-);
+  );
 
 #endif /* STATISTICS_H */

+ 69 - 27
private-include/trace.h

@@ -22,35 +22,77 @@
  * @brief  Tracing functions
  */
 
-#ifndef TRACE_H
-#define TRACE_H
+#ifndef _DMMLIB_TRACE_H_
+#define _DMMLIB_TRACE_H_
 #include "dmm_config.h"
 
-#if TRACE_LEVEL >= 1
+#ifdef WITH_MEM_TRACE
+#include <stdio.h>
+
+#ifndef PARSE_ENV
+/** Memory trace file descriptor */
+#define MEM_FD stderr
+#else /* PARSE_ENV */
+/** Memory trace file descriptor macro */
+#define MEM_FD mem_fd
+/** Memory trace file descriptor */
+FILE* mem_fd;
+#endif /* PARSE_ENV */
+
+/** Function for memory trace messages */
+#define MEM_TRACE(...) fprintf(MEM_FD, __VA_ARGS__)
+
+#else /* WITH_MEM_TRACE */
+
+/** Function for memory trace messages */
+#define MEM_TRACE(...) /* do nothing */
+
+#endif /* WITH_MEM_TRACE */
+
+#ifdef WITH_STATS_TRACE
+#include <stdio.h>
+
+#ifndef PARSE_ENV
+/** Statistics file descriptor */
+#define STATS_FD stderr
+#else /* PARSE_ENV */
+/** Statistics file descriptor macro */
+#define STATS_FD stats_fd
+/** Statistics file descriptor */
+FILE* stats_fd;
+#endif /* PARSE_ENV */
 
+/** Function for statistics trace messages */
+#define STATS_TRACE(...) fprintf(STATS_FD, __VA_ARGS__)
+
+#else /* WITH_STATS_TRACE */
+
+/** Function for statistics trace messages */
+#define STATS_TRACE(...) /* do nothing */
+
+#endif /* WITH_STATS_TRACE */
+
+#ifdef WITH_DEBUG
 #include <stdio.h>
 
-/** 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 */
+#ifndef PARSE_ENV
+/** Debug file descriptor */
+#define DBG_FD stderr
+#else /* PARSE_ENV */
+/** Debug file descriptor macro */
+#define DBG_FD dbg_fd
+/** Debug file descriptor */
+FILE* dbg_fd;
+#endif /* PARSE_ENV */
+
+/** Function for debug trace messages */
+#define DBG_TRACE(...) fprintf(DBG_FD, __VA_ARGS__)
+
+#else /* WITH_DEBUG */
+
+/** Function for debug trace messages */
+#define DBG_TRACE(...) /* do nothing */
+
+#endif /* WITH_DEBUG */
+
+#endif /* _DMMLIB_TRACE_H_ */

+ 3 - 6
src/CMakeLists.txt

@@ -209,12 +209,9 @@ if(WITH_MEMALIGN)
   )
 endif(WITH_MEMALIGN)
 
-if (WITH_ADAPTIVITY)
-  set(dmmlib_SRCS
-    ${dmmlib_SRCS}
-    dmm_adaptor.c
-  )
-endif (WITH_ADAPTIVITY)
+if(PARSE_ENV)
+  set(dmmlib_SRCS ${dmmlib_SRCS} parse_env.c)
+endif(PARSE_ENV)
 
 include_directories(
   ${DMMLIB_PUBLIC_INCLUDE_DIRS}

+ 2 - 2
src/bitmap/debug.c

@@ -76,8 +76,8 @@ void print_bitmap_vector(bitmap_rb_t *raw_block) {
         bmap_p++;
     }
 
-    TRACE_3("Cells in data layout: %s\n", output);
-    TRACE_3("dmmlib - mem - bm - %zu\n", get_used_cells(raw_block));
+    DBG_TRACE("Cells in data layout: %s\n", output);
+    DBG_TRACE("dmmlib - mem - bm - %zu\n", get_used_cells(raw_block));
 
     return;
 }

+ 5 - 4
src/bitmap/free.c

@@ -72,12 +72,13 @@ void bitmap_free(bitmap_rb_t *raw_block, void *ptr) {
 
 #ifdef WITH_ALLOCATOR_STATS
     LOCK_GLOBAL();
-    update_stats(&systemallocator.dmm_stats,
-            FREE,
+    update_stats
+        ( &systemallocator.dmm_stats
+        , FREE
 #ifdef REQUEST_SIZE_INFO
-            chunk_header->requested_size,
+        , chunk_header->requested_size
 #endif /* REQUEST_SIZE_INFO */
-            cells_used * raw_block->bytes_per_cell);
+        );
     UNLOCK_GLOBAL();
 #endif /* WITH_ALLOCATOR_STATS */
 

+ 5 - 4
src/bitmap/malloc.c

@@ -126,12 +126,13 @@ void * bitmap_malloc(bitmap_rb_t *raw_block, size_t req_size) {
             // 5. Statistics support
 #ifdef WITH_ALLOCATOR_STATS
             LOCK_GLOBAL();
-            update_stats(&systemallocator.dmm_stats,
-                    MALLOC,
+            update_stats
+                ( &systemallocator.dmm_stats
+                , MALLOC
 #ifdef REQUEST_SIZE_INFO
-                    req_size - CHUNK_HDR_SIZE,
+                , req_size - CHUNK_HDR_SIZE
 #endif /* REQUEST_SIZE_INFO */
-                    cells * raw_block->bytes_per_cell);
+                );
             UNLOCK_GLOBAL();
 #endif /* WITH_ALLOCATOR_STATS */
 

+ 4 - 4
src/debug.c

@@ -41,21 +41,21 @@ void get_raw_blocks(allocator_t *allocator) {
 
     SLIST_FOREACH(current_raw_block, &allocator->rb_head, pointers) {
         counter++;
-        TRACE_3("dmmlib - Raw block at %p of size %zu\n",
+        DBG_TRACE("dmmlib - Raw block at %p of size %zu\n",
                 (void *)current_raw_block,
                 current_raw_block->size);
     }
 
-    TRACE_3("dmmlib - there are %d raw blocks\n", counter);
+    DBG_TRACE("dmmlib - there are %d raw blocks\n", counter);
 
     counter = 0;
 
     SLIST_FOREACH(current_raw_block, &allocator->bb_head, pointers) {
         counter++;
-        TRACE_3("dmmlib - Raw block at %p of size %zu\n",
+        DBG_TRACE("dmmlib - Raw block at %p of size %zu\n",
                 (void *)current_raw_block,
                 current_raw_block->size);
     }
 
-    TRACE_3("dmmlib - there are %d big blocks\n", counter);
+    DBG_TRACE("dmmlib - there are %d big blocks\n", counter);
 }

+ 6 - 5
src/free.c

@@ -51,7 +51,7 @@ void free(void *ptr) {
         return;
     }
 
-    TRACE_1("dmmlib - f %p\n", ptr);
+    MEM_TRACE("dmmlib - f %p\n", ptr);
 
     owner_raw_block = find_raw_block_owner(systemallocator.rb_head, ptr);
 
@@ -77,12 +77,13 @@ void free(void *ptr) {
 
 #ifdef WITH_ALLOCATOR_STATS
         LOCK_GLOBAL();
-        update_stats(&systemallocator.dmm_stats,
-                FREE,
+        update_stats
+            ( &systemallocator.dmm_stats
+            , FREE
 #ifdef REQUEST_SIZE_INFO
-                owner_raw_block->requested_size,
+            , owner_raw_block->requested_size
 #endif /* REQUEST_SIZE_INFO */
-                owner_raw_block->size);
+            );
         systemallocator.dmm_stats.total_mem_allocated -= owner_raw_block->size;
         UNLOCK_GLOBAL();
 #endif /* WITH_ALLOCATOR_STATS */

+ 5 - 4
src/freelist/free.c

@@ -50,12 +50,13 @@ void freelist_free(freelist_rb_t *raw_block, void *ptr) {
 
 #ifdef WITH_ALLOCATOR_STATS
     LOCK_GLOBAL();
-    update_stats(&systemallocator.dmm_stats,
-            FREE,
+    update_stats
+        ( &systemallocator.dmm_stats
+        , FREE
 #ifdef REQUEST_SIZE_INFO
-            get_requested_size(block),
+        , get_requested_size(block)
 #endif /* REQUEST_SIZE_INFO */
-            get_size(block) + HEADER_SIZE);
+        );
     UNLOCK_GLOBAL();
 #endif /* WITH_ALLOCATOR_STATS */
 

+ 2 - 2
src/freelist/freelist_debug.c

@@ -41,10 +41,10 @@ void get_memory_blocks(freelist_rb_t *raw_block) {
 
     SLIST_FOREACH(memory_block, &raw_block->fl_head, pointers) {
         counter++;
-        TRACE_1("Free memory block at %p with size %zu\n",
+        DBG_TRACE("Free memory block at %p with size %zu\n",
                 (void *)memory_block, get_size(memory_block));
     }
 
-    TRACE_1("Raw block at %p has %d memory blocks\n",
+    DBG_TRACE("Raw block at %p has %d memory blocks\n",
             (void *)raw_block, counter);
 }

+ 5 - 4
src/freelist/malloc.c

@@ -124,12 +124,13 @@ void * freelist_malloc(freelist_rb_t *raw_block, size_t size) {
 
 #ifdef WITH_ALLOCATOR_STATS
         LOCK_GLOBAL();
-        update_stats(&systemallocator.dmm_stats,
-                MALLOC,
+        update_stats
+            ( &systemallocator.dmm_stats
+            , MALLOC
 #ifdef REQUEST_SIZE_INFO
-                size,
+            , size
 #endif /* REQUEST_SIZE_INFO */
-                get_size(ptr) + HEADER_SIZE);
+            );
         UNLOCK_GLOBAL();
 #endif /* WITH_ALLOCATOR_STATS */
 

+ 12 - 5
src/malloc.c

@@ -115,12 +115,13 @@ void * malloc(size_t size) {
 
 #ifdef WITH_ALLOCATOR_STATS
                 LOCK_GLOBAL();
-                update_stats(&systemallocator.dmm_stats,
-                        MALLOC,
+                update_stats
+                    ( &systemallocator.dmm_stats
+                    , MALLOC
 #ifdef REQUEST_SIZE_INFO
-                        size,
+                    , size
 #endif /* REQUEST_SIZE_INFO */
-                        ((raw_block_header_t *)ptr)->size);
+                    );
                 UNLOCK_GLOBAL();
 #endif /* WITH_ALLOCATOR_STATS */
 
@@ -147,7 +148,13 @@ void * malloc(size_t size) {
         }
     }
 
-    TRACE_1("dmmlib - m %p %zu\n", ptr, size);
+#if defined PARSE_ENV && defined WITH_MEM_TRACE
+    if(__builtin_expect (systemallocator.initialized, true)) {
+#endif /* PARSE_ENV && WITH_MEM_TRACE */
+        MEM_TRACE("dmmlib - m %p %zu\n", ptr, size);
+#if defined PARSE_ENV && defined WITH_MEM_TRACE
+    }
+#endif /* PARSE_ENV && WITH_MEM_TRACE */
     
     return ptr;
 }

+ 6 - 5
src/memalign.c

@@ -172,12 +172,13 @@ CheckAlignment:
 
 #ifdef WITH_ALLOCATOR_STATS
                 LOCK_GLOBAL();
-                update_stats(&systemallocator.dmm_stats,
-                        MALLOC,
+                update_stats
+                    ( &systemallocator.dmm_stats
+                    , MALLOC
 #ifdef REQUEST_SIZE_INFO
-                        size,
+                    , size
 #endif /* REQUEST_SIZE_INFO */
-                        size + sizeof(raw_block_header_t));
+                    );
                 UNLOCK_GLOBAL();
 #endif /* WITH_ALLOCATOR_STATS */
 
@@ -226,7 +227,7 @@ CheckAlignment:
         assert((uintptr_t) *memptr % alignment == 0);
     }
 
-    TRACE_1("dmmlib - ma %p %zu %zu\n", *memptr, alignment, size);
+    MEM_TRACE("dmmlib - ma %p %zu %zu\n", *memptr, alignment, size);
 
     return 0;
 }

+ 84 - 0
src/parse_env.c

@@ -0,0 +1,84 @@
+/*
+ *   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   parse_env.c
+ * @author Ioannis Koutras (joko@microlab.ntua.gr)
+ * @date   November 2012
+ * @brief  Parse the DMMLIB_OPTS enviroment variable.
+ */
+
+#include "dmm_config.h"
+
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+
+#include "dmmlib/dmmlib.h"
+#include "trace.h"
+
+__attribute__((constructor)) void parse_env(void);
+
+/** Parses the DMMLIB_OPTS enviroment variable. */
+void parse_env(void) {
+    const char* env;
+
+    systemallocator.initialized = false;
+
+#ifdef WITH_MEM_TRACE
+    env = getenv("DMMLIB_MEM_TRACE");
+
+    if(env == NULL) {
+        mem_fd = stderr;
+    } else {
+        mem_fd = fopen(env, "a+");
+    }
+#endif /* WITH_MEM_TRACE */
+
+#ifdef WITH_STATS_TRACE
+    env = getenv("DMMLIB_STATS_TRACE");
+
+    if(env == NULL) {
+        stats_fd = stderr;
+    } else {
+        stats_fd = fopen(env, "a+");
+    }
+#endif /* WITH_STATS_TRACE */
+
+    systemallocator.initialized = true;
+
+    return;
+}
+
+#if defined WITH_MEM_TRACE || defined WITH_STATS_TRACE
+__attribute__((destructor)) void close_trace_files(void);
+
+/** Closes the opened trace files. */
+void close_trace_files(void) {
+#ifdef WITH_MEM_TRACE
+    if(mem_fd != stderr) {
+        fclose(mem_fd);
+    }
+#endif /* WITH_MEM_TRACE */
+#ifdef WITH_STATS_TRACE
+    if(stats_fd != stderr) {
+        fclose(stats_fd);
+    }
+#endif /* WITH_STATS_TRACE */
+    return;
+}
+#endif /* WITH_MEM_TRACE || WITH_STATS_TRACE */

+ 5 - 5
src/realloc.c

@@ -89,12 +89,12 @@ void * realloc(void *ptr, size_t size) {
             LOCK_GLOBAL();
             systemallocator.dmm_stats.total_mem_allocated -=
                 remaining_size;
-            TRACE_2("dmmlib - ms all %zu\n",
+            STATS_TRACE("dmmlib - ms all %zu\n",
                     systemallocator.dmm_stats.total_mem_allocated);
 #ifdef REQUEST_SIZE_INFO
             systemallocator.dmm_stats.total_mem_requested -=
                 remaining_size;
-            TRACE_2("dmmlib - ms req %zu\n",
+            STATS_TRACE("dmmlib - ms req %zu\n",
                     systemallocator.dmm_stats.total_mem_requested);
 #endif /* REQUEST_SIZE_INFO */
             systemallocator.dmm_stats.num_realloc++;
@@ -145,12 +145,12 @@ void * realloc(void *ptr, size_t size) {
                 LOCK_GLOBAL();
                 systemallocator.dmm_stats.total_mem_allocated +=
                     size_diff;
-                TRACE_2("dmmlib - ms all %zu\n",
+                STATS_TRACE("dmmlib - ms all %zu\n",
                         systemallocator.dmm_stats.total_mem_allocated);
 #ifdef REQUEST_SIZE_INFO
                 systemallocator.dmm_stats.total_mem_requested +=
                     size_diff;
-                TRACE_2("dmmlib - ms req %zu\n",
+                STATS_TRACE("dmmlib - ms req %zu\n",
                         systemallocator.dmm_stats.total_mem_requested);
 #endif /* REQUEST_SIZE_INFO */
                 systemallocator.dmm_stats.num_realloc++;
@@ -164,7 +164,7 @@ void * realloc(void *ptr, size_t size) {
 
 done:
 
-    TRACE_1("dmmlib - r %p %p %zu\n", ptr, return_ptr, size);
+    MEM_TRACE("dmmlib - r %p %p %zu\n", ptr, return_ptr, size);
 
     return return_ptr;
 

+ 15 - 11
src/statistics.c

@@ -32,7 +32,6 @@
  *
  * @param dmm_stats Pointer to the dmmstats_t variable.
  * @param event     The event type, could be MALLOC or FREE.
- * @param mem_alloc Allocated memory size info.
  * */
 #ifdef REQUEST_SIZE_INFO
  /**
@@ -40,14 +39,13 @@
   */
 #endif /* REQUEST_SIZE_INFO */
 void update_stats
-(
- dmmstats_t *dmm_stats, 
- dmm_event_type event, 
+    ( dmmstats_t *dmm_stats
+    , dmm_event_type event
 #ifdef REQUEST_SIZE_INFO
- size_t mem_req,
+    , size_t mem_req
 #endif /* REQUEST_SIZE_INFO */
- size_t mem_alloc
-) {
+    )
+{
     if(event == MALLOC) {
 #ifdef REQUEST_SIZE_INFO
         dmm_stats->total_mem_requested += mem_req;
@@ -64,21 +62,27 @@ void update_stats
         dmm_stats->num_free++;
     }
 
-    TRACE_2("dmmlib - ms all %zu\n", dmm_stats->total_mem_allocated);
+#if defined PARSE_ENV && defined WITH_STATS_TRACE
+    if(__builtin_expect (systemallocator.initialized, true)) {
+#endif /* PARSE_ENV && WITH_STATS_TRACE */
+        STATS_TRACE("dmmlib - ms all %zu\n", dmm_stats->total_mem_allocated);
 #ifdef REQUEST_SIZE_INFO
-    TRACE_2("dmmlib - ms req %zu\n", dmm_stats->total_mem_requested);
+        STATS_TRACE("dmmlib - ms req %zu\n", dmm_stats->total_mem_requested);
 #endif /* REQUEST_SIZE_INFO */
+#if defined PARSE_ENV && defined WITH_STATS_TRACE
+    }
+#endif /* PARSE_ENV && WITH_STATS_TRACE */
 
 }
 
 #ifdef REQUEST_SIZE_INFO
+/** Returns the total memory that is currently requested */
 size_t get_total_requested_memory(void) {
     return systemallocator.dmm_stats.total_mem_requested;
 }
 #endif /* REQUEST_SIZE_INFO */
 
+/** Returns the total memory that is currently allocated */
 size_t get_total_allocated_memory(void) {
     return systemallocator.dmm_stats.total_mem_allocated;
 }
-
-