[sgen] Debug option for printing the heap usage and minor collection allowance.
authorMark Probst <mark.probst@gmail.com>
Fri, 8 Jul 2011 19:47:00 +0000 (21:47 +0200)
committerMark Probst <mark.probst@gmail.com>
Mon, 11 Jul 2011 10:23:42 +0000 (12:23 +0200)
man/mono.1
mono/metadata/sgen-gc.c

index 37e96045e568c18fd12d3f69cf4a67516fc2751a..35527c942e174847bb7865749540494360447cde 100644 (file)
@@ -1081,6 +1081,12 @@ words.  Do not use these options in production.
 \fInumber\fR
 Sets the debug level to the specified number.
 .TP
+\fBprint-allowance\fR
+After each major collection prints memory consumption for before and
+after the collection and the allowance for the minor collector, i.e. how
+much the heap is allowed to grow from minor collections before the next
+major collection is triggered.
+.TP
 \fBcollect-before-allocs\fR
 .TP
 \fBcheck-at-minor-collections\fR
index 1d79f38871b4c5dd8e2d6fb17e1d9040eba59a82..d1ccb878c54de32b5618f1695efe1662493022f6 100644 (file)
@@ -337,6 +337,7 @@ static long long time_major_fragment_creation = 0;
 
 int gc_debug_level = 0;
 FILE* gc_debug_file;
+static gboolean debug_print_allowance = FALSE;
 
 /*
 void
@@ -2835,6 +2836,17 @@ try_calculate_minor_collection_allowance (gboolean overwrite)
 
        minor_collection_allowance = MAX (MIN (allowance_target, num_major_sections * major_collector.section_size + los_memory_usage), MIN_MINOR_COLLECTION_ALLOWANCE);
 
+       if (debug_print_allowance) {
+               mword old_major = last_collection_old_num_major_sections * major_collector.section_size;
+               mword new_major = num_major_sections * major_collector.section_size;
+
+               fprintf (gc_debug_file, "Before collection: %ld bytes (%ld major, %ld LOS)\n",
+                               old_major + last_collection_old_los_memory_usage, old_major, last_collection_old_los_memory_usage);
+               fprintf (gc_debug_file, "After collection: %ld bytes (%ld major, %ld LOS)\n",
+                               new_major + last_collection_los_memory_usage, new_major, last_collection_los_memory_usage);
+               fprintf (gc_debug_file, "Allowance: %ld bytes\n", minor_collection_allowance);
+       }
+
        if (major_collector.have_computed_minor_collection_allowance)
                major_collector.have_computed_minor_collection_allowance ();
 
@@ -6631,7 +6643,7 @@ mono_gc_base_init (void)
        LOCK_INIT (gc_mutex);
 
        pagesize = mono_pagesize ();
-       gc_debug_file = stdout;
+       gc_debug_file = stderr;
 
        cb.thread_register = sgen_thread_register;
        cb.thread_unregister = sgen_thread_unregister;
@@ -6862,6 +6874,8 @@ mono_gc_base_init (void)
                                                gc_debug_file = stderr;
                                        g_free (rf);
                                }
+                       } else if (!strcmp (opt, "print-allowance")) {
+                               debug_print_allowance = TRUE;
                        } else if (!strcmp (opt, "collect-before-allocs")) {
                                collect_before_allocs = 1;
                        } else if (g_str_has_prefix (opt, "collect-before-allocs=")) {
@@ -6903,6 +6917,7 @@ mono_gc_base_init (void)
                                fprintf (stderr, "  disable-major\n");
                                fprintf (stderr, "  xdomain-checks\n");
                                fprintf (stderr, "  clear-at-gc\n");
+                               fprintf (stderr, "  print-allowance\n");
                                exit (1);
                        }
                }