Several improvements to (internal) statistics reporting about memory usage,
making it easier to understand the memory and/or oom situation.
No functional (user level) change.

* For --profile-heap=yes, sort the cost centers by decreasing size,
  so that the most relevant cost centers are closed to the arena
  total.

* factorise duplicated code calling a series of print stat functions

* VG_(show_sched_status)
    optionally show the host stacktrace
               the amount of valgrind stack used by each thread
               the exited threads

* various functions: update to add VG_(show_sched_status) new
  args, keeping the same info production as before.
 
* In case of out of memory situation detected by m_mallocfree.c,
  reports more information:
    valgrind and tool stats
    scheduler status (full information)

* gdbserver v.info scheduler :
    show full information.

The oom behaviour/reporting was tested using a small
program causing an OOM, and having several threads
(some terminated, some still active).



git-svn-id: svn://svn.valgrind.org/valgrind/trunk@13897 a5019735-40e9-0310-863c-91ae7b9d1cf9
diff --git a/coregrind/m_main.c b/coregrind/m_main.c
index 82a5dde..98192de 100644
--- a/coregrind/m_main.c
+++ b/coregrind/m_main.c
@@ -73,31 +73,6 @@
 
 
 /*====================================================================*/
-/*=== Counters, for profiling purposes only                        ===*/
-/*====================================================================*/
-
-static void print_all_stats ( void )
-{
-   VG_(print_translation_stats)();
-   VG_(print_tt_tc_stats)();
-   VG_(print_scheduler_stats)();
-   VG_(print_ExeContext_stats)( False /* with_stacktraces */ );
-   VG_(print_errormgr_stats)();
-
-   // Memory stats
-   if (VG_(clo_verbosity) > 2) {
-      VG_(message)(Vg_DebugMsg, "\n");
-      VG_(message)(Vg_DebugMsg, 
-         "------ Valgrind's internal memory use stats follow ------\n" );
-      VG_(sanity_check_malloc_all)();
-      VG_(message)(Vg_DebugMsg, "------\n" );
-      VG_(print_all_arena_stats)();
-      VG_(message)(Vg_DebugMsg, "\n");
-   }
-}
-
-
-/*====================================================================*/
 /*=== Command-line: variables, processing, etc                     ===*/
 /*====================================================================*/
 
@@ -2489,7 +2464,8 @@
    VG_(sanity_check_general)( True /*include expensive checks*/ );
 
    if (VG_(clo_stats))
-      print_all_stats();
+      VG_(print_all_stats)(VG_(clo_verbosity) > 2, /* Memory stats */
+                           False /* tool prints stats in the tool fini */);
 
    /* Show a profile of the heap(s) at shutdown.  Optionally, first
       throw away all the debug info, as that makes it easy to spot