[gnome-builder] counters: sprinkle instance counters for various boxed types



commit 09867e11870e353e78271b5dbb9ad49f305747f4
Author: Christian Hergert <christian hergert me>
Date:   Mon May 11 00:50:25 2015 -0700

    counters: sprinkle instance counters for various boxed types
    
    These are super useful for tracking down memory leaks at runtime with
    very little overhead.

 libide/ide-diagnostic.c      |   10 ++++++++++
 libide/ide-highlight-index.c |    8 ++++++++
 libide/ide-pattern-spec.c    |   11 +++++++++--
 libide/ide-ref-ptr.c         |    9 +++++++++
 libide/ide-source-location.c |    9 +++++++++
 libide/ide-source-range.c    |   13 +++++++++++--
 libide/ide-symbol.c          |    8 ++++++++
 7 files changed, 64 insertions(+), 4 deletions(-)
---
diff --git a/libide/ide-diagnostic.c b/libide/ide-diagnostic.c
index 3a6bdf7..98020fd 100644
--- a/libide/ide-diagnostic.c
+++ b/libide/ide-diagnostic.c
@@ -16,6 +16,10 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+#define G_LOG_DOMAIN "ide-diagnostic"
+
+#include "egg-counter.h"
+
 #include "ide-diagnostic.h"
 #include "ide-internal.h"
 #include "ide-source-location.h"
@@ -23,6 +27,8 @@
 
 G_DEFINE_BOXED_TYPE (IdeDiagnostic, ide_diagnostic, ide_diagnostic_ref, ide_diagnostic_unref)
 
+EGG_DEFINE_COUNTER (instances, "Instances", "IdeDiagnostic", "Number of IdeDiagnostic")
+
 struct _IdeDiagnostic
 {
   volatile gint          ref_count;
@@ -57,6 +63,8 @@ ide_diagnostic_unref (IdeDiagnostic *self)
       g_clear_pointer (&self->ranges, g_ptr_array_unref);
       g_clear_pointer (&self->fixits, g_ptr_array_unref);
       g_free (self);
+
+      EGG_COUNTER_DEC (instances);
     }
 }
 
@@ -178,6 +186,8 @@ _ide_diagnostic_new (IdeDiagnosticSeverity  severity,
   ret->text = g_strdup (text);
   ret->location = location ? ide_source_location_ref (location) : NULL;
 
+  EGG_COUNTER_INC (instances);
+
   return ret;
 }
 
diff --git a/libide/ide-highlight-index.c b/libide/ide-highlight-index.c
index 9ddd47e..953702b 100644
--- a/libide/ide-highlight-index.c
+++ b/libide/ide-highlight-index.c
@@ -23,12 +23,16 @@
 #include <sys/user.h>
 #include <unistd.h>
 
+#include "egg-counter.h"
+
 #include "ide-debug.h"
 #include "ide-highlight-index.h"
 
 G_DEFINE_BOXED_TYPE (IdeHighlightIndex, ide_highlight_index,
                      ide_highlight_index_ref, ide_highlight_index_unref)
 
+EGG_DEFINE_COUNTER (instances, "Instances", "IdeHighlightIndex Instances", "Number of indexes")
+
 struct _IdeHighlightIndex
 {
   volatile gint  ref_count;
@@ -51,6 +55,8 @@ ide_highlight_index_new (void)
   ret->strings = g_string_chunk_new (sysconf (_SC_PAGE_SIZE));
   ret->index = g_hash_table_new (g_str_hash, g_str_equal);
 
+  EGG_COUNTER_INC (instances);
+
   return ret;
 }
 
@@ -117,6 +123,8 @@ ide_highlight_index_finalize (IdeHighlightIndex *self)
   g_hash_table_unref (self->index);
   g_free (self);
 
+  EGG_COUNTER_DEC (instances);
+
   IDE_EXIT;
 }
 
diff --git a/libide/ide-pattern-spec.c b/libide/ide-pattern-spec.c
index 982d0d0..c82e08c 100644
--- a/libide/ide-pattern-spec.c
+++ b/libide/ide-pattern-spec.c
@@ -23,10 +23,13 @@
 #endif
 #include <string.h>
 
+#include "egg-counter.h"
+
 #include "ide-pattern-spec.h"
 
-G_DEFINE_BOXED_TYPE (IdePatternSpec, ide_pattern_spec,
-                     ide_pattern_spec_ref, ide_pattern_spec_unref)
+G_DEFINE_BOXED_TYPE (IdePatternSpec, ide_pattern_spec, ide_pattern_spec_ref, ide_pattern_spec_unref)
+
+EGG_DEFINE_COUNTER (instances, "Instances", "IdePatternSpec", "Number of IdePatternSpec")
 
 /**
  * SECTION:ide-pattern-spec:
@@ -69,6 +72,8 @@ ide_pattern_spec_new (const gchar *needle)
         }
     }
 
+  EGG_COUNTER_INC (instances);
+
   return self;
 }
 
@@ -86,6 +91,8 @@ ide_pattern_spec_free (IdePatternSpec *self)
   g_strfreev (self->parts);
   g_free (self->needle);
   g_free (self);
+
+  EGG_COUNTER_DEC (instances);
 }
 
 static inline gboolean
diff --git a/libide/ide-ref-ptr.c b/libide/ide-ref-ptr.c
index 9c140f8..d15d29e 100644
--- a/libide/ide-ref-ptr.c
+++ b/libide/ide-ref-ptr.c
@@ -16,10 +16,16 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+#define G_LOG_DOMAIN "ide-ref-ptr"
+
+#include "egg-counter.h"
+
 #include "ide-ref-ptr.h"
 
 G_DEFINE_BOXED_TYPE (IdeRefPtr, ide_ref_ptr, ide_ref_ptr_ref, ide_ref_ptr_unref)
 
+EGG_DEFINE_COUNTER (instances, "Instances", "IdeRefPtr", "Number of IdeRefPtr instances.")
+
 struct _IdeRefPtr
 {
   volatile gint  ref_count;
@@ -38,6 +44,8 @@ ide_ref_ptr_new (gpointer       data,
   self->data = data;
   self->free_func = free_func;
 
+  EGG_COUNTER_INC (instances);
+
   return self;
 }
 
@@ -62,6 +70,7 @@ ide_ref_ptr_unref (IdeRefPtr *self)
     {
       if (self->free_func)
         g_clear_pointer (&self->data, self->free_func);
+      EGG_COUNTER_DEC (instances);
     }
 }
 
diff --git a/libide/ide-source-location.c b/libide/ide-source-location.c
index 6278eab..b46af8d 100644
--- a/libide/ide-source-location.c
+++ b/libide/ide-source-location.c
@@ -16,6 +16,10 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+#define G_LOG_DOMAIN "ide-source-location"
+
+#include "egg-counter.h"
+
 #include "ide-file.h"
 #include "ide-source-location.h"
 
@@ -31,6 +35,8 @@ struct _IdeSourceLocation
   IdeFile       *file;
 };
 
+EGG_DEFINE_COUNTER (instances, "Instances", "IdeSourceLocation", "Number of IdeSourceLocation")
+
 /**
  * ide_source_location_ref:
  *
@@ -63,6 +69,7 @@ ide_source_location_unref (IdeSourceLocation *self)
     {
       g_clear_object (&self->file);
       g_slice_free (IdeSourceLocation, self);
+      EGG_COUNTER_DEC (instances);
     }
 }
 
@@ -155,5 +162,7 @@ ide_source_location_new (IdeFile *file,
   ret->line_offset = line_offset;
   ret->offset = offset;
 
+  EGG_COUNTER_INC (instances);
+
   return ret;
 }
diff --git a/libide/ide-source-range.c b/libide/ide-source-range.c
index 43abeea..33a7f49 100644
--- a/libide/ide-source-range.c
+++ b/libide/ide-source-range.c
@@ -16,12 +16,17 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+#define G_LOG_DOMAIN "ide-source-range"
+
+#include "egg-counter.h"
+
 #include "ide-file.h"
 #include "ide-source-location.h"
 #include "ide-source-range.h"
 
-G_DEFINE_BOXED_TYPE (IdeSourceRange, ide_source_range,
-                     ide_source_range_ref, ide_source_range_unref)
+G_DEFINE_BOXED_TYPE (IdeSourceRange, ide_source_range, ide_source_range_ref, ide_source_range_unref)
+
+EGG_DEFINE_COUNTER (instances, "Instances", "IdeSourceRange", "Number of IdeSourceRange instances.")
 
 struct _IdeSourceRange
 {
@@ -47,6 +52,8 @@ _ide_source_range_new (IdeSourceLocation *begin,
   ret->begin = ide_source_location_ref (begin);
   ret->end = ide_source_location_ref (end);
 
+  EGG_COUNTER_INC (instances);
+
   return ret;
 }
 
@@ -117,5 +124,7 @@ ide_source_range_unref (IdeSourceRange *self)
       ide_source_location_unref (self->begin);
       ide_source_location_unref (self->end);
       g_slice_free (IdeSourceRange, self);
+
+      EGG_COUNTER_DEC (instances);
     }
 }
diff --git a/libide/ide-symbol.c b/libide/ide-symbol.c
index 0cbfde1..65003fc 100644
--- a/libide/ide-symbol.c
+++ b/libide/ide-symbol.c
@@ -18,6 +18,8 @@
 
 #define G_LOG_DOMAIN "ide-symbol"
 
+#include "egg-counter.h"
+
 #include "ide-symbol.h"
 #include "ide-source-location.h"
 
@@ -36,6 +38,8 @@ struct _IdeSymbol
 
 G_DEFINE_BOXED_TYPE (IdeSymbol, ide_symbol, ide_symbol_ref, ide_symbol_unref)
 
+EGG_DEFINE_COUNTER (instances, "Instances", "IdeSymbol", "Number of symbol instances")
+
 IdeSymbol *
 _ide_symbol_new (const gchar       *name,
                  IdeSymbolKind      kind,
@@ -61,6 +65,8 @@ _ide_symbol_new (const gchar       *name,
   if (canonical_location)
     ret->canonical_location = ide_source_location_ref (canonical_location);
 
+  EGG_COUNTER_INC (instances);
+
   return ret;
 }
 
@@ -162,5 +168,7 @@ ide_symbol_unref (IdeSymbol *self)
       g_clear_pointer (&self->canonical_location, ide_source_location_unref);
       g_clear_pointer (&self->name, g_free);
       g_free (self);
+
+      EGG_COUNTER_DEC (instances);
     }
 }


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