Re: Small patch to show only memory usage.



Reworked the patch as per suggestions of Tim Janik and Havoc Pennington,
have tested and put on ftp://ftp.gtk.org/incoming/gtk-rocky-001501-0.patch.tar.gz


*** ../glib-orig.h	Thu Mar 23 21:34:01 2000
--- ../glib.h	Thu Feb  1 01:34:04 2001
***************
*** 1366,1373 ****
  
  #endif /* !USE_DMALLOC */
  
! void	 g_mem_profile (void);
! void	 g_mem_check   (gpointer  mem);
  
  /* Generic allocators
   */
--- 1366,1387 ----
  
  #endif /* !USE_DMALLOC */
  
! void	 g_mem_profile   (void);
! 
! /* Memory summary flags.
!  */
! typedef enum
! {
!   G_MEM_SHOW_ALLOC_SIZE		= 1 << 0,
!   G_MEM_SHOW_LARGE_ALLOC	= 1 << 1,
!   G_MEM_SHOW_ALLOC	        = 1 << 2,
!   G_MEM_SHOW_FREED	        = 1 << 3,
!   G_MEM_SHOW_USED		= 1 << 4,
!   G_MEM_SHOW_ALL		= 0xff
! } GMemSummaryFlags;
! 
! void     g_mem_summarize (const gchar *msg, const GMemSummaryFlags show_what);
! void	 g_mem_check     (gpointer  mem);
  
  /* Generic allocators
   */
*** ../gmem-orig.c	Fri May 19 03:25:05 2000
--- ../gmem.c	Thu Feb  1 01:35:54 2001
***************
*** 415,430 ****
  
  #endif /* ! USE_DMALLOC */
  
- 
  void
  g_mem_profile (void)
  {
  #ifdef ENABLE_MEM_PROFILE
    gint i;
    gulong local_allocations[MEM_PROFILE_TABLE_SIZE];
    gulong local_allocated_mem;
    gulong local_freed_mem;  
  
    g_mutex_lock (mem_profile_lock);
    for (i = 0; i < MEM_PROFILE_TABLE_SIZE; i++)
      local_allocations[i] = allocations[i];
--- 415,439 ----
  
  #endif /* ! USE_DMALLOC */
  
  void
  g_mem_profile (void)
  {
+   g_mem_summarize (NULL, G_MEM_SHOW_ALL);
+ }
+ 
+ void
+ g_mem_summarize (const gchar *msg, const GMemSummaryFlags show_what) 
+ {
  #ifdef ENABLE_MEM_PROFILE
    gint i;
    gulong local_allocations[MEM_PROFILE_TABLE_SIZE];
    gulong local_allocated_mem;
    gulong local_freed_mem;  
  
+   if (msg != NULL) {
+     g_log (g_log_domain_glib, G_LOG_LEVEL_INFO,"%s", msg);
+   }
+ 
    g_mutex_lock (mem_profile_lock);
    for (i = 0; i < MEM_PROFILE_TABLE_SIZE; i++)
      local_allocations[i] = allocations[i];
***************
*** 433,449 ****
    g_mutex_unlock (mem_profile_lock);
  
    for (i = 0; i < (MEM_PROFILE_TABLE_SIZE - 1); i++)
!     if (local_allocations[i] > 0)
        g_log (g_log_domain_glib, G_LOG_LEVEL_INFO,
  	     "%lu allocations of %d bytes", local_allocations[i], i + 1);
    
!   if (local_allocations[MEM_PROFILE_TABLE_SIZE - 1] > 0)
      g_log (g_log_domain_glib, G_LOG_LEVEL_INFO,
  	   "%lu allocations of greater than %d bytes",
  	   local_allocations[MEM_PROFILE_TABLE_SIZE - 1], MEM_PROFILE_TABLE_SIZE - 1);
!   g_log (g_log_domain_glib, G_LOG_LEVEL_INFO, "%lu bytes allocated", local_allocated_mem);
!   g_log (g_log_domain_glib, G_LOG_LEVEL_INFO, "%lu bytes freed", local_freed_mem);
!   g_log (g_log_domain_glib, G_LOG_LEVEL_INFO, "%lu bytes in use", local_allocated_mem - local_freed_mem);
  #endif /* ENABLE_MEM_PROFILE */
  }
  
--- 442,462 ----
    g_mutex_unlock (mem_profile_lock);
  
    for (i = 0; i < (MEM_PROFILE_TABLE_SIZE - 1); i++)
!     if (local_allocations[i] > 0 && (show_what & G_MEM_SHOW_ALLOC_SIZE))
        g_log (g_log_domain_glib, G_LOG_LEVEL_INFO,
  	     "%lu allocations of %d bytes", local_allocations[i], i + 1);
    
!   if (local_allocations[MEM_PROFILE_TABLE_SIZE - 1] > 0 
!       && (show_what & G_MEM_SHOW_LARGE_ALLOC))
      g_log (g_log_domain_glib, G_LOG_LEVEL_INFO,
  	   "%lu allocations of greater than %d bytes",
  	   local_allocations[MEM_PROFILE_TABLE_SIZE - 1], MEM_PROFILE_TABLE_SIZE - 1);
!   if (show_what & G_MEM_SHOW_ALLOC) 
!     g_log (g_log_domain_glib, G_LOG_LEVEL_INFO, "%lu bytes allocated", local_allocated_mem);
!   if (show_what & G_MEM_SHOW_FREED) 
!     g_log (g_log_domain_glib, G_LOG_LEVEL_INFO, "%lu bytes freed", local_freed_mem);
!   if (show_what & G_MEM_SHOW_USED)
!     g_log (g_log_domain_glib, G_LOG_LEVEL_INFO, "%lu bytes in use", local_allocated_mem - local_freed_mem);
  #endif /* ENABLE_MEM_PROFILE */
  }
  




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]