From 9b7901e74d1bf6419a4c1428be1842a2d5165903 Mon Sep 17 00:00:00 2001 From: David Malcolm Date: Mon, 26 Jan 2026 19:35:23 -0500 Subject: [PATCH 50/98] FIXME: experiment with capturing heap usage (PR analyzer/123770) --- gcc/timevar.cc | 19 ++++++++++++++++++- gcc/timevar.h | 4 ++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/gcc/timevar.cc b/gcc/timevar.cc index 2b2dd9386af2..6e5926337235 100644 --- a/gcc/timevar.cc +++ b/gcc/timevar.cc @@ -18,6 +18,7 @@ You should have received a copy of the GNU General Public License along with GCC; see the file COPYING3. If not see . */ +#include // FIXME #include "config.h" #include "system.h" #include "coretypes.h" @@ -157,6 +158,13 @@ get_time (struct timevar_time_def *now) now->wall = 0; now->ggc_mem = timevar_ggc_mem_total; + // FIXME: + { + struct mallinfo info (mallinfo ()); + /* "This is the total size of memory occupied by chunks handed out by malloc." */ + now->heap_mem = info.uordblks; + } + #ifdef HAVE_CLOCK_GETTIME struct timespec ts; #if _POSIX_TIMERS > 0 && defined(_POSIX_MONOTONIC_CLOCK) @@ -185,6 +193,7 @@ timevar_accumulate (struct timevar_time_def *timer, { timer->wall += stop_time->wall - start_time->wall; timer->ggc_mem += stop_time->ggc_mem - start_time->ggc_mem; + timer->heap_mem += stop_time->heap_mem - start_time->heap_mem; } /* Get the difference between STOP_TIME and START_TIME. */ @@ -196,6 +205,7 @@ timevar_diff (struct timevar_time_def *out, { out->wall = stop_time.wall - start_time.wall; out->ggc_mem = stop_time.ggc_mem - start_time.ggc_mem; + out->heap_mem = stop_time.heap_mem - start_time.heap_mem; } /* Class timer's constructor. */ @@ -581,6 +591,12 @@ timer::print_row (FILE *fp, ? 0 : (float) elapsed.ggc_mem / total->ggc_mem) * 100); + /* FIXME. */ +#define PRsignedsa(n) "%" #n "lli" "%c" +#define SIGNED_SIZE_AMOUNT(size) (int64_t)SIZE_SCALE (size), SIZE_LABEL (llabs(size)) + fprintf (fp, PRsignedsa (10), + SIGNED_SIZE_AMOUNT (elapsed.heap_mem)); + putc ('\n', fp); } @@ -625,7 +641,7 @@ timer::print (FILE *fp) TIMEVAR. */ m_start_time = now; - fprintf (fp, "\n%-35s%16s%14s\n", "Time variable", "wall", "GGC"); + fprintf (fp, "\n%-35s%16s%14s%14s\n", "Time variable", "wall", "GGC", "heap delta"); if (m_jit_client_items) fputs ("GCC items:\n", fp); for (id = 0; id < (unsigned int) TIMEVAR_LAST; ++id) @@ -705,6 +721,7 @@ make_json_for_timevar_time_def (const timevar_time_def &ttd) auto obj = std::make_unique (); obj->set_float ("wall", nanosec_to_floating_sec (ttd.wall)); obj->set_integer ("ggc_mem", ttd.ggc_mem); + obj->set_integer ("heap_mem", ttd.heap_mem); return obj; } #undef nanosec_to_floating_sec diff --git a/gcc/timevar.h b/gcc/timevar.h index 1e7503d43bad..b956926a5dfc 100644 --- a/gcc/timevar.h +++ b/gcc/timevar.h @@ -56,6 +56,10 @@ struct timevar_time_def /* Garbage collector memory. */ size_t ggc_mem; + + /* Overall heap memory, or change in overall heap memory + (thus non-monotonic). */ + ssize_t heap_mem; }; /* An enumeration of timing variable identifiers. Constructed from -- 2.49.0