Example #1
0
void
g_mem_profile (void)
{
  guint local_data[(MEM_PROFILE_TABLE_SIZE + 1) * 8 * sizeof (profile_data[0])];
  gulong local_allocs;
  gulong local_zinit;
  gulong local_frees;
  gulong local_mc_allocs;
  gulong local_mc_frees;

  g_mutex_lock (g_profile_mutex);

  local_allocs = profile_allocs;
  local_zinit = profile_zinit;
  local_frees = profile_frees;
  local_mc_allocs = profile_mc_allocs;
  local_mc_frees = profile_mc_frees;

  if (!profile_data)
    {
      g_mutex_unlock (g_profile_mutex);
      return;
    }

  memcpy (local_data, profile_data, 
	  (MEM_PROFILE_TABLE_SIZE + 1) * 8 * sizeof (profile_data[0]));
  
  g_mutex_unlock (g_profile_mutex);

  g_print ("GLib Memory statistics (successful operations):\n");
  profile_print_locked (local_data, TRUE);
  g_print ("GLib Memory statistics (failing operations):\n");
  profile_print_locked (local_data, FALSE);
  g_print ("Total bytes: allocated=%lu, zero-initialized=%lu (%.2f%%), freed=%lu (%.2f%%), remaining=%lu\n",
	   local_allocs,
	   local_zinit,
	   ((gdouble) local_zinit) / local_allocs * 100.0,
	   local_frees,
	   ((gdouble) local_frees) / local_allocs * 100.0,
	   local_allocs - local_frees);
  g_print ("MemChunk bytes: allocated=%lu, freed=%lu (%.2f%%), remaining=%lu\n",
	   local_mc_allocs,
	   local_mc_frees,
	   ((gdouble) local_mc_frees) / local_mc_allocs * 100.0,
	   local_mc_allocs - local_mc_frees);
}
Example #2
0
void
g_mem_profile (void)
{
    guint local_data[(MEM_PROFILE_TABLE_SIZE + 1) * 8 * sizeof (profile_data[0])];
    gsize local_allocs;
    gsize local_zinit;
    gsize local_frees;

    if (G_UNLIKELY (!g_mem_initialized))
        g_mem_init_nomessage();

    g_mutex_lock (gmem_profile_mutex);

    local_allocs = profile_allocs;
    local_zinit = profile_zinit;
    local_frees = profile_frees;

    if (!profile_data)
    {
        g_mutex_unlock (gmem_profile_mutex);
        return;
    }

    memcpy (local_data, profile_data,
            (MEM_PROFILE_TABLE_SIZE + 1) * 8 * sizeof (profile_data[0]));

    g_mutex_unlock (gmem_profile_mutex);

    g_print ("GLib Memory statistics (successful operations):\n");
    profile_print_locked (local_data, TRUE);
    g_print ("GLib Memory statistics (failing operations):\n");
    profile_print_locked (local_data, FALSE);
    g_print ("Total bytes: allocated=%"G_GSIZE_FORMAT", "
             "zero-initialized=%"G_GSIZE_FORMAT" (%.2f%%), "
             "freed=%"G_GSIZE_FORMAT" (%.2f%%), "
             "remaining=%"G_GSIZE_FORMAT"\n",
             local_allocs,
             local_zinit,
             ((gdouble) local_zinit) / local_allocs * 100.0,
             local_frees,
             ((gdouble) local_frees) / local_allocs * 100.0,
             local_allocs - local_frees);
}