Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- From 25f7e9342289b3a1f60888ce2df1b7b5708b7d45 Mon Sep 17 00:00:00 2001
- From: Lionel Landwerlin <lionel.g.landwerlin@linux.intel.com>
- Date: Fri, 10 Jun 2011 18:44:09 +0100
- Subject: [PATCH] cogl-debug: add object-instances debug option
- This allows to track the number of objects allocated by Cogl. The
- results are displayed on the standard output by calling :
- cogl_debug_print_instances ();
- Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@linux.intel.com>
- ---
- clutter/cogl/cogl/cogl-debug-options.h | 6 ++
- clutter/cogl/cogl/cogl-debug.c | 30 +++++++-
- clutter/cogl/cogl/cogl-debug.h | 2 +
- clutter/cogl/cogl/cogl-object-private.h | 125 ++++++++++++++++++++-----------
- 4 files changed, 117 insertions(+), 46 deletions(-)
- diff --git a/clutter/cogl/cogl/cogl-debug-options.h b/clutter/cogl/cogl/cogl-debug-options.h
- index 38027f5..c2c22da 100644
- --- a/clutter/cogl/cogl/cogl-debug-options.h
- +++ b/clutter/cogl/cogl/cogl-debug-options.h
- @@ -179,3 +179,9 @@ OPT (CLIPPING,
- "clipping",
- "Trace clipping",
- "Logs information about how Cogl is implementing clipping")
- +OPT (OBJECT_INSTANCES,
- + "Cogl object instances",
- + "object-instances",
- + "Trace object instances",
- + "Allow you to visulize number of Cogl objects per classes by calling"
- + " cogl_debug_print_instances()")
- diff --git a/clutter/cogl/cogl/cogl-debug.c b/clutter/cogl/cogl/cogl-debug.c
- index 73e88a7..e7f7178 100644
- --- a/clutter/cogl/cogl/cogl-debug.c
- +++ b/clutter/cogl/cogl/cogl-debug.c
- @@ -55,7 +55,8 @@ static const GDebugKey cogl_log_debug_keys[] = {
- { "offscreen", COGL_DEBUG_OFFSCREEN },
- { "texture-pixmap", COGL_DEBUG_TEXTURE_PIXMAP },
- { "bitmap", COGL_DEBUG_BITMAP },
- - { "clipping", COGL_DEBUG_CLIPPING }
- + { "clipping", COGL_DEBUG_CLIPPING },
- + { "object-instances", COGL_DEBUG_OBJECT_INSTANCES }
- };
- static const int n_cogl_log_debug_keys =
- G_N_ELEMENTS (cogl_log_debug_keys);
- @@ -83,6 +84,7 @@ static const int n_cogl_behavioural_debug_keys =
- G_N_ELEMENTS (cogl_behavioural_debug_keys);
- unsigned int _cogl_debug_flags[COGL_DEBUG_N_INTS];
- +GHashTable *_cogl_debug_instances;
- static void
- _cogl_parse_debug_string_for_keys (const char *value,
- @@ -224,6 +226,11 @@ pre_parse_hook (GOptionContext *context,
- FALSE /* don't ignore help */);
- env_string = NULL;
- }
- +
- + if (G_UNLIKELY (COGL_DEBUG_ENABLED (COGL_DEBUG_OBJECT_INSTANCES)))
- + {
- + _cogl_debug_instances = g_hash_table_new (g_str_hash, g_str_equal);
- + }
- #endif /* COGL_ENABLE_DEBUG */
- return TRUE;
- @@ -245,3 +252,24 @@ cogl_get_option_group (void)
- return group;
- }
- +
- +void
- +cogl_debug_print_instances (void)
- +{
- + GHashTableIter iter;
- + const gchar *name;
- + gulong *nb;
- +
- + if (G_LIKELY (!COGL_DEBUG_ENABLED (COGL_DEBUG_OBJECT_INSTANCES)))
- + return;
- +
- + g_print ("Cogl instances:\n");
- +
- + g_hash_table_iter_init (&iter, _cogl_debug_instances);
- + while (g_hash_table_iter_next (&iter,
- + (gpointer *) &name,
- + (gpointer *) &nb))
- + {
- + g_print ("\t%s: %lu\n", name, *nb);
- + }
- +}
- diff --git a/clutter/cogl/cogl/cogl-debug.h b/clutter/cogl/cogl/cogl-debug.h
- index 0cd039f..02f6bd8 100644
- --- a/clutter/cogl/cogl/cogl-debug.h
- +++ b/clutter/cogl/cogl/cogl-debug.h
- @@ -63,6 +63,7 @@ typedef enum {
- COGL_DEBUG_DISABLE_PROGRAM_CACHES,
- COGL_DEBUG_DISABLE_FAST_READ_PIXEL,
- COGL_DEBUG_CLIPPING,
- + COGL_DEBUG_OBJECT_INSTANCES,
- COGL_DEBUG_N_FLAGS
- } CoglDebugFlags;
- @@ -78,6 +79,7 @@ typedef enum {
- easily and it can test more bits. However GDebugKey uses a guint
- for the mask and we need to fit the masks into this */
- extern unsigned int _cogl_debug_flags[COGL_DEBUG_N_INTS];
- +extern GHashTable *_cogl_debug_instances;
- #define COGL_DEBUG_GET_FLAG_INDEX(flag) \
- ((flag) / (sizeof (unsigned int) * 8))
- diff --git a/clutter/cogl/cogl/cogl-object-private.h b/clutter/cogl/cogl/cogl-object-private.h
- index e8b4ed0..aab61de 100644
- --- a/clutter/cogl/cogl/cogl-object-private.h
- +++ b/clutter/cogl/cogl/cogl-object-private.h
- @@ -123,51 +123,86 @@ struct _CoglObject
- #define _COGL_HANDLE_DEBUG_UNREF _COGL_OBJECT_DEBUG_UNREF
- #define COGL_HANDLE_DEBUG_FREE COGL_OBJECT_DEBUG_FREE
- -#define COGL_OBJECT_COMMON_DEFINE_WITH_CODE(TypeName, type_name, code) \
- - \
- -static CoglObjectClass _cogl_##type_name##_class; \
- - \
- -GQuark \
- -_cogl_object_##type_name##_get_type (void) \
- -{ \
- - static GQuark type = 0; \
- - if (!type) \
- - { \
- - type = g_quark_from_static_string ("Cogl"#TypeName); \
- - { code; } \
- - } \
- - return type; \
- -} \
- - \
- -GQuark \
- -_cogl_handle_##type_name##_get_type (void) \
- -{ \
- - return _cogl_object_##type_name##_get_type (); \
- -} \
- - \
- -static Cogl##TypeName * \
- -_cogl_##type_name##_object_new (Cogl##TypeName *new_obj) \
- -{ \
- - CoglObject *obj = (CoglObject *)&new_obj->_parent; \
- - obj->ref_count = 1; \
- - obj->n_user_data_entries = 0; \
- - obj->user_data_array = NULL; \
- - \
- - obj->klass = &_cogl_##type_name##_class; \
- - if (!obj->klass->type) \
- - { \
- - obj->klass->type = _cogl_object_##type_name##_get_type ();\
- - obj->klass->virt_free = _cogl_##type_name##_free; \
- - } \
- - \
- - _COGL_OBJECT_DEBUG_NEW (TypeName, obj); \
- - return new_obj; \
- -} \
- - \
- -Cogl##TypeName * \
- -_cogl_##type_name##_pointer_from_handle (CoglHandle handle) \
- -{ \
- - return handle; \
- +#define COGL_OBJECT_COMMON_DEFINE_WITH_CODE(TypeName, type_name, code) \
- + \
- +static CoglObjectClass _cogl_##type_name##_class; \
- +static gulong _cogl_object_##type_name##_count; \
- +static void *_cogl_object_##type_name##_free_func; \
- + \
- +static inline void \
- +_cogl_object_##type_name##_inc (void) \
- +{ \
- + _cogl_object_##type_name##_count++; \
- +} \
- + \
- +static inline void \
- +_cogl_object_##type_name##_dec (void) \
- +{ \
- + _cogl_object_##type_name##_count--; \
- +} \
- + \
- +static void \
- +_cogl_object_##type_name##_indirect_free (CoglObject *obj) \
- +{ \
- + _cogl_##type_name##_free ((Cogl##TypeName *) obj); \
- + _cogl_object_##type_name##_dec (); \
- +} \
- + \
- +GQuark \
- +_cogl_object_##type_name##_get_type (void) \
- +{ \
- + static GQuark type = 0; \
- + if (!type) \
- + { \
- + type = g_quark_from_static_string ("Cogl"#TypeName); \
- + _cogl_object_##type_name##_count = 0; \
- + if (G_UNLIKELY (COGL_DEBUG_ENABLED (COGL_DEBUG_OBJECT_INSTANCES)))\
- + { \
- + g_hash_table_insert (_cogl_debug_instances, \
- + "Cogl"#TypeName, \
- + &_cogl_object_##type_name##_count); \
- + _cogl_object_##type_name##_free_func = \
- + _cogl_object_##type_name##_indirect_free; \
- + } \
- + else \
- + _cogl_object_##type_name##_free_func = \
- + _cogl_##type_name##_free; \
- + { code; } \
- + } \
- + return type; \
- +} \
- + \
- +GQuark \
- +_cogl_handle_##type_name##_get_type (void) \
- +{ \
- + return _cogl_object_##type_name##_get_type (); \
- +} \
- + \
- +static Cogl##TypeName * \
- +_cogl_##type_name##_object_new (Cogl##TypeName *new_obj) \
- +{ \
- + CoglObject *obj = (CoglObject *)&new_obj->_parent; \
- + obj->ref_count = 0; \
- + cogl_object_ref (obj); \
- + obj->n_user_data_entries = 0; \
- + obj->user_data_array = NULL; \
- + \
- + obj->klass = &_cogl_##type_name##_class; \
- + if (!obj->klass->type) \
- + { \
- + obj->klass->type = _cogl_object_##type_name##_get_type (); \
- + obj->klass->virt_free = _cogl_object_##type_name##_free_func; \
- + } \
- + \
- + _cogl_object_##type_name##_inc (); \
- + _COGL_OBJECT_DEBUG_NEW (TypeName, obj); \
- + return new_obj; \
- +} \
- + \
- +Cogl##TypeName * \
- +_cogl_##type_name##_pointer_from_handle (CoglHandle handle) \
- +{ \
- + return handle; \
- }
- #define COGL_OBJECT_DEFINE_WITH_CODE(TypeName, type_name, code) \
- --
- 1.7.5.4
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement