Пример #1
0
static void
profiler_log (ProfilerJob job,
	      gulong      n_bytes,
	      gboolean    success)
{
  g_mutex_lock (g_profile_mutex);
  if (!profile_data)
    {
      profile_data = standard_malloc ((MEM_PROFILE_TABLE_SIZE + 1) * 8 * sizeof (profile_data[0]));
      if (!profile_data)	/* memory system kiddin' me, eh? */
	{
	  g_mutex_unlock (g_profile_mutex);
	  return;
	}
    }

  if (MEM_CHUNK_ROUTINE_COUNT () == 0)
    {
      if (n_bytes < MEM_PROFILE_TABLE_SIZE)
	profile_data[n_bytes + PROFILE_TABLE ((job & PROFILER_ALLOC) != 0,
					      (job & PROFILER_RELOC) != 0,
					      success != 0)] += 1;
      else
	profile_data[MEM_PROFILE_TABLE_SIZE + PROFILE_TABLE ((job & PROFILER_ALLOC) != 0,
							     (job & PROFILER_RELOC) != 0,
							     success != 0)] += 1;
      if (success)
	{
	  if (job & PROFILER_ALLOC)
	    {
	      profile_allocs += n_bytes;
	      if (job & PROFILER_ZINIT)
		profile_zinit += n_bytes;
	    }
	  else
	    profile_frees += n_bytes;
	}
    }
  else if (success)
    {
      if (job & PROFILER_ALLOC)
	profile_mc_allocs += n_bytes;
      else
	profile_mc_frees += n_bytes;
    }
  g_mutex_unlock (g_profile_mutex);
}
Пример #2
0
static gpointer
profiler_try_malloc (gsize n_bytes)
{
  gsize *p;

#ifdef  G_ENABLE_DEBUG
  if (g_trap_malloc_size == n_bytes)
    G_BREAKPOINT ();
#endif  /* G_ENABLE_DEBUG */

  p = standard_malloc (sizeof (gsize) * 2 + n_bytes);

  if (p)
    {
      p[0] = 0;		/* free count */
      p[1] = n_bytes;	/* length */
      profiler_log (PROFILER_ALLOC, n_bytes, TRUE);
      p += 2;
    }
  else
    profiler_log (PROFILER_ALLOC, n_bytes, FALSE);
  
  return p;
}