]> granicus.if.org Git - gc/commitdiff
Improve logged messages about heap size and usage
authorIvan Maidanski <ivmai@mail.ru>
Wed, 12 Dec 2012 19:05:36 +0000 (23:05 +0400)
committerIvan Maidanski <ivmai@mail.ru>
Wed, 12 Dec 2012 19:19:32 +0000 (23:19 +0400)
* alloc.c (GC_stopped_mark): Print heap size to debug log in KiB
(using TO_KiB_UL macro) excluding unmapped memory size.
* alloc.c (GC_compute_heap_usage_percent): New inline function.
* alloc.c (GC_finish_collection): Use GC_DBGLOG_PRINTF instead of
GC_COND_LOG_PRINTF for heap usage logging; print heap usage in KiB;
log memory heap utilization in percent (using
GC_compute_heap_usage_percent).
* alloc.c (GC_expand_hp_inner): Log increased heap size (in KiB)
instead of increment size.
* include/private/gc_priv.h (TO_KiB_UL): New macro.

alloc.c
include/private/gc_priv.h

diff --git a/alloc.c b/alloc.c
index 4616ba52e30bb589ab43a102977ab9fb76974027..cf7bbaeb4bde84218dbbd57bbc603d43cb64a0bd 100644 (file)
--- a/alloc.c
+++ b/alloc.c
@@ -638,11 +638,11 @@ STATIC GC_bool GC_stopped_mark(GC_stop_func stop_func)
         }
 
     GC_gc_no++;
-    GC_DBGLOG_PRINTF("GC #%lu reclaimed %ld bytes --> heapsize: %lu"
-                     " bytes" IF_USE_MUNMAP(" (%lu unmapped)") "\n",
+    GC_DBGLOG_PRINTF("GC #%lu freed %ld bytes, heap %lu KiB"
+                     IF_USE_MUNMAP(" (+ %lu KiB unmapped)") "\n",
                      (unsigned long)GC_gc_no, (long)GC_bytes_found,
-                     (unsigned long)GC_heapsize /*, */
-                     COMMA_IF_USE_MUNMAP((unsigned long)GC_unmapped_bytes));
+                     TO_KiB_UL(GC_heapsize - GC_unmapped_bytes) /*, */
+                     COMMA_IF_USE_MUNMAP(TO_KiB_UL(GC_unmapped_bytes)));
 
     /* Check all debugged objects for consistency */
     if (GC_debugging_started) {
@@ -811,6 +811,15 @@ STATIC void GC_clear_fl_marks(ptr_t q)
 
 GC_on_heap_resize_proc GC_on_heap_resize = 0;
 
+/* Used for logging only. */
+GC_INLINE int GC_compute_heap_usage_percent(void)
+{
+  word used = GC_composite_in_use + GC_atomic_in_use;
+  word heap_sz = GC_heapsize - GC_unmapped_bytes;
+  return used >= heap_sz ? 0 : used < ((word)-1) / 100 ?
+                (int)((used * 100) / heap_sz) : (int)(used / (heap_sz / 100));
+}
+
 /* Finish up a collection.  Assumes mark bits are consistent, lock is   */
 /* held, but the world is otherwise running.                            */
 STATIC void GC_finish_collection(void)
@@ -906,10 +915,10 @@ STATIC void GC_finish_collection(void)
 
     /* Reconstruct free lists to contain everything not marked */
     GC_start_reclaim(FALSE);
-    GC_COND_LOG_PRINTF("Heap contains %lu pointer-containing"
-                       " + %lu pointer-free reachable bytes\n",
-                       (unsigned long)GC_composite_in_use,
-                       (unsigned long)GC_atomic_in_use);
+    GC_DBGLOG_PRINTF("In-use heap: %d%% (%lu KiB pointers + %lu KiB other)\n",
+                     GC_compute_heap_usage_percent(),
+                     TO_KiB_UL(GC_composite_in_use),
+                     TO_KiB_UL(GC_atomic_in_use));
     if (GC_is_full_gc) {
         GC_used_heap_size_after_full = USED_HEAP_SIZE;
         GC_need_full_gc = FALSE;
@@ -1159,9 +1168,9 @@ GC_INNER GC_bool GC_expand_hp_inner(word n)
         WARN("Failed to expand heap by %" WARN_PRIdPTR " bytes\n", bytes);
         return(FALSE);
     }
-    GC_INFOLOG_PRINTF(
-                "Increasing heap size by %lu after %lu allocated bytes\n",
-                (unsigned long)bytes, (unsigned long)GC_bytes_allocd);
+    GC_INFOLOG_PRINTF("Grow heap to %lu KiB after %lu bytes allocated\n",
+                      TO_KiB_UL(GC_heapsize + bytes),
+                      (unsigned long)GC_bytes_allocd);
     /* Adjust heap limits generously for blacklisting to work better.   */
     /* GC_add_to_heap performs minimal adjustment needed for            */
     /* correctness.                                                     */
index cb5d6780fc28ee944e89090e04be34f6060f5c84..4c7608cd6b8e0b9296708aa2372b9c2bd8b13cbc 100644 (file)
@@ -2093,6 +2093,10 @@ void GC_err_puts(const char *s);
                         /* Write s to stderr, don't buffer, don't add   */
                         /* newlines, don't ...                          */
 
+/* Handy macro for logging size values (of word type) in KiB (rounding  */
+/* to nearest value).                                                   */
+#define TO_KiB_UL(v) ((unsigned long)(((v) + ((1 << 9) - 1)) >> 10))
+
 GC_EXTERN unsigned GC_fail_count;
                         /* How many consecutive GC/expansion failures?  */
                         /* Reset by GC_allochblk(); defined in alloc.c. */