Advertisement
Guest User

Untitled

a guest
Sep 21st, 2017
416
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.32 KB | None | 0 0
  1. From 25f7e9342289b3a1f60888ce2df1b7b5708b7d45 Mon Sep 17 00:00:00 2001
  2. From: Lionel Landwerlin <lionel.g.landwerlin@linux.intel.com>
  3. Date: Fri, 10 Jun 2011 18:44:09 +0100
  4. Subject: [PATCH] cogl-debug: add object-instances debug option
  5.  
  6. This allows to track the number of objects allocated by Cogl. The
  7. results are displayed on the standard output by calling :
  8.  
  9. cogl_debug_print_instances ();
  10.  
  11. Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@linux.intel.com>
  12. ---
  13. clutter/cogl/cogl/cogl-debug-options.h | 6 ++
  14. clutter/cogl/cogl/cogl-debug.c | 30 +++++++-
  15. clutter/cogl/cogl/cogl-debug.h | 2 +
  16. clutter/cogl/cogl/cogl-object-private.h | 125 ++++++++++++++++++++-----------
  17. 4 files changed, 117 insertions(+), 46 deletions(-)
  18.  
  19. diff --git a/clutter/cogl/cogl/cogl-debug-options.h b/clutter/cogl/cogl/cogl-debug-options.h
  20. index 38027f5..c2c22da 100644
  21. --- a/clutter/cogl/cogl/cogl-debug-options.h
  22. +++ b/clutter/cogl/cogl/cogl-debug-options.h
  23. @@ -179,3 +179,9 @@ OPT (CLIPPING,
  24. "clipping",
  25. "Trace clipping",
  26. "Logs information about how Cogl is implementing clipping")
  27. +OPT (OBJECT_INSTANCES,
  28. + "Cogl object instances",
  29. + "object-instances",
  30. + "Trace object instances",
  31. + "Allow you to visulize number of Cogl objects per classes by calling"
  32. + " cogl_debug_print_instances()")
  33. diff --git a/clutter/cogl/cogl/cogl-debug.c b/clutter/cogl/cogl/cogl-debug.c
  34. index 73e88a7..e7f7178 100644
  35. --- a/clutter/cogl/cogl/cogl-debug.c
  36. +++ b/clutter/cogl/cogl/cogl-debug.c
  37. @@ -55,7 +55,8 @@ static const GDebugKey cogl_log_debug_keys[] = {
  38. { "offscreen", COGL_DEBUG_OFFSCREEN },
  39. { "texture-pixmap", COGL_DEBUG_TEXTURE_PIXMAP },
  40. { "bitmap", COGL_DEBUG_BITMAP },
  41. - { "clipping", COGL_DEBUG_CLIPPING }
  42. + { "clipping", COGL_DEBUG_CLIPPING },
  43. + { "object-instances", COGL_DEBUG_OBJECT_INSTANCES }
  44. };
  45. static const int n_cogl_log_debug_keys =
  46. G_N_ELEMENTS (cogl_log_debug_keys);
  47. @@ -83,6 +84,7 @@ static const int n_cogl_behavioural_debug_keys =
  48. G_N_ELEMENTS (cogl_behavioural_debug_keys);
  49.  
  50. unsigned int _cogl_debug_flags[COGL_DEBUG_N_INTS];
  51. +GHashTable *_cogl_debug_instances;
  52.  
  53. static void
  54. _cogl_parse_debug_string_for_keys (const char *value,
  55. @@ -224,6 +226,11 @@ pre_parse_hook (GOptionContext *context,
  56. FALSE /* don't ignore help */);
  57. env_string = NULL;
  58. }
  59. +
  60. + if (G_UNLIKELY (COGL_DEBUG_ENABLED (COGL_DEBUG_OBJECT_INSTANCES)))
  61. + {
  62. + _cogl_debug_instances = g_hash_table_new (g_str_hash, g_str_equal);
  63. + }
  64. #endif /* COGL_ENABLE_DEBUG */
  65.  
  66. return TRUE;
  67. @@ -245,3 +252,24 @@ cogl_get_option_group (void)
  68.  
  69. return group;
  70. }
  71. +
  72. +void
  73. +cogl_debug_print_instances (void)
  74. +{
  75. + GHashTableIter iter;
  76. + const gchar *name;
  77. + gulong *nb;
  78. +
  79. + if (G_LIKELY (!COGL_DEBUG_ENABLED (COGL_DEBUG_OBJECT_INSTANCES)))
  80. + return;
  81. +
  82. + g_print ("Cogl instances:\n");
  83. +
  84. + g_hash_table_iter_init (&iter, _cogl_debug_instances);
  85. + while (g_hash_table_iter_next (&iter,
  86. + (gpointer *) &name,
  87. + (gpointer *) &nb))
  88. + {
  89. + g_print ("\t%s: %lu\n", name, *nb);
  90. + }
  91. +}
  92. diff --git a/clutter/cogl/cogl/cogl-debug.h b/clutter/cogl/cogl/cogl-debug.h
  93. index 0cd039f..02f6bd8 100644
  94. --- a/clutter/cogl/cogl/cogl-debug.h
  95. +++ b/clutter/cogl/cogl/cogl-debug.h
  96. @@ -63,6 +63,7 @@ typedef enum {
  97. COGL_DEBUG_DISABLE_PROGRAM_CACHES,
  98. COGL_DEBUG_DISABLE_FAST_READ_PIXEL,
  99. COGL_DEBUG_CLIPPING,
  100. + COGL_DEBUG_OBJECT_INSTANCES,
  101.  
  102. COGL_DEBUG_N_FLAGS
  103. } CoglDebugFlags;
  104. @@ -78,6 +79,7 @@ typedef enum {
  105. easily and it can test more bits. However GDebugKey uses a guint
  106. for the mask and we need to fit the masks into this */
  107. extern unsigned int _cogl_debug_flags[COGL_DEBUG_N_INTS];
  108. +extern GHashTable *_cogl_debug_instances;
  109.  
  110. #define COGL_DEBUG_GET_FLAG_INDEX(flag) \
  111. ((flag) / (sizeof (unsigned int) * 8))
  112. diff --git a/clutter/cogl/cogl/cogl-object-private.h b/clutter/cogl/cogl/cogl-object-private.h
  113. index e8b4ed0..aab61de 100644
  114. --- a/clutter/cogl/cogl/cogl-object-private.h
  115. +++ b/clutter/cogl/cogl/cogl-object-private.h
  116. @@ -123,51 +123,86 @@ struct _CoglObject
  117. #define _COGL_HANDLE_DEBUG_UNREF _COGL_OBJECT_DEBUG_UNREF
  118. #define COGL_HANDLE_DEBUG_FREE COGL_OBJECT_DEBUG_FREE
  119.  
  120. -#define COGL_OBJECT_COMMON_DEFINE_WITH_CODE(TypeName, type_name, code) \
  121. - \
  122. -static CoglObjectClass _cogl_##type_name##_class; \
  123. - \
  124. -GQuark \
  125. -_cogl_object_##type_name##_get_type (void) \
  126. -{ \
  127. - static GQuark type = 0; \
  128. - if (!type) \
  129. - { \
  130. - type = g_quark_from_static_string ("Cogl"#TypeName); \
  131. - { code; } \
  132. - } \
  133. - return type; \
  134. -} \
  135. - \
  136. -GQuark \
  137. -_cogl_handle_##type_name##_get_type (void) \
  138. -{ \
  139. - return _cogl_object_##type_name##_get_type (); \
  140. -} \
  141. - \
  142. -static Cogl##TypeName * \
  143. -_cogl_##type_name##_object_new (Cogl##TypeName *new_obj) \
  144. -{ \
  145. - CoglObject *obj = (CoglObject *)&new_obj->_parent; \
  146. - obj->ref_count = 1; \
  147. - obj->n_user_data_entries = 0; \
  148. - obj->user_data_array = NULL; \
  149. - \
  150. - obj->klass = &_cogl_##type_name##_class; \
  151. - if (!obj->klass->type) \
  152. - { \
  153. - obj->klass->type = _cogl_object_##type_name##_get_type ();\
  154. - obj->klass->virt_free = _cogl_##type_name##_free; \
  155. - } \
  156. - \
  157. - _COGL_OBJECT_DEBUG_NEW (TypeName, obj); \
  158. - return new_obj; \
  159. -} \
  160. - \
  161. -Cogl##TypeName * \
  162. -_cogl_##type_name##_pointer_from_handle (CoglHandle handle) \
  163. -{ \
  164. - return handle; \
  165. +#define COGL_OBJECT_COMMON_DEFINE_WITH_CODE(TypeName, type_name, code) \
  166. + \
  167. +static CoglObjectClass _cogl_##type_name##_class; \
  168. +static gulong _cogl_object_##type_name##_count; \
  169. +static void *_cogl_object_##type_name##_free_func; \
  170. + \
  171. +static inline void \
  172. +_cogl_object_##type_name##_inc (void) \
  173. +{ \
  174. + _cogl_object_##type_name##_count++; \
  175. +} \
  176. + \
  177. +static inline void \
  178. +_cogl_object_##type_name##_dec (void) \
  179. +{ \
  180. + _cogl_object_##type_name##_count--; \
  181. +} \
  182. + \
  183. +static void \
  184. +_cogl_object_##type_name##_indirect_free (CoglObject *obj) \
  185. +{ \
  186. + _cogl_##type_name##_free ((Cogl##TypeName *) obj); \
  187. + _cogl_object_##type_name##_dec (); \
  188. +} \
  189. + \
  190. +GQuark \
  191. +_cogl_object_##type_name##_get_type (void) \
  192. +{ \
  193. + static GQuark type = 0; \
  194. + if (!type) \
  195. + { \
  196. + type = g_quark_from_static_string ("Cogl"#TypeName); \
  197. + _cogl_object_##type_name##_count = 0; \
  198. + if (G_UNLIKELY (COGL_DEBUG_ENABLED (COGL_DEBUG_OBJECT_INSTANCES)))\
  199. + { \
  200. + g_hash_table_insert (_cogl_debug_instances, \
  201. + "Cogl"#TypeName, \
  202. + &_cogl_object_##type_name##_count); \
  203. + _cogl_object_##type_name##_free_func = \
  204. + _cogl_object_##type_name##_indirect_free; \
  205. + } \
  206. + else \
  207. + _cogl_object_##type_name##_free_func = \
  208. + _cogl_##type_name##_free; \
  209. + { code; } \
  210. + } \
  211. + return type; \
  212. +} \
  213. + \
  214. +GQuark \
  215. +_cogl_handle_##type_name##_get_type (void) \
  216. +{ \
  217. + return _cogl_object_##type_name##_get_type (); \
  218. +} \
  219. + \
  220. +static Cogl##TypeName * \
  221. +_cogl_##type_name##_object_new (Cogl##TypeName *new_obj) \
  222. +{ \
  223. + CoglObject *obj = (CoglObject *)&new_obj->_parent; \
  224. + obj->ref_count = 0; \
  225. + cogl_object_ref (obj); \
  226. + obj->n_user_data_entries = 0; \
  227. + obj->user_data_array = NULL; \
  228. + \
  229. + obj->klass = &_cogl_##type_name##_class; \
  230. + if (!obj->klass->type) \
  231. + { \
  232. + obj->klass->type = _cogl_object_##type_name##_get_type (); \
  233. + obj->klass->virt_free = _cogl_object_##type_name##_free_func; \
  234. + } \
  235. + \
  236. + _cogl_object_##type_name##_inc (); \
  237. + _COGL_OBJECT_DEBUG_NEW (TypeName, obj); \
  238. + return new_obj; \
  239. +} \
  240. + \
  241. +Cogl##TypeName * \
  242. +_cogl_##type_name##_pointer_from_handle (CoglHandle handle) \
  243. +{ \
  244. + return handle; \
  245. }
  246.  
  247. #define COGL_OBJECT_DEFINE_WITH_CODE(TypeName, type_name, code) \
  248. --
  249. 1.7.5.4
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement