2 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3 * 2000 Wim Taymans <wtay@chello.be>
4 * 2003 Benjamin Otte <in7y118@public.uni-hamburg.de>
6 * gstinfo.c: debugging functions
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
24 #include "gst_private.h"
28 #ifndef GST_DISABLE_GST_DEBUG
36 #include "gst_private.h"
37 #include "gstelement.h"
39 #include "gstscheduler.h"
40 #include "gst_private.h"
42 GST_DEBUG_CATEGORY_STATIC(GST_CAT_DEBUG);
46 #include <rld_interface.h>
47 typedef struct DL_INFO {
48 const char * dli_fname;
50 const char * dli_sname;
56 #define _RLD_DLADDR 14
57 int dladdr(void *address, Dl_info *dl);
59 int dladdr(void *address, Dl_info *dl)
62 v = _rld_new_interface(_RLD_DLADDR,address,dl);
68 extern gchar *_gst_progname;
70 static void gst_debug_reset_threshold (gpointer category,
72 static void gst_debug_reset_all_thresholds (void);
74 /* list of all name/level pairs from --gst-debug and GST_DEBUG */
75 static GStaticMutex __level_name_mutex = G_STATIC_MUTEX_INIT;
76 static GSList *__level_name = NULL;
82 /* list of all categories */
83 static GStaticMutex __cat_mutex = G_STATIC_MUTEX_INIT;
84 static GSList *__categories = NULL;
86 /* all registered debug handlers */
91 static GStaticMutex __log_func_mutex = G_STATIC_MUTEX_INIT;
92 static GSList *__log_functions = NULL;
94 static GstAtomicInt __default_level;
95 static GstAtomicInt __use_color;
96 gboolean __gst_debug_enabled = TRUE;
99 GstDebugCategory *GST_CAT_DEFAULT = NULL;
101 GstDebugCategory *GST_CAT_GST_INIT = NULL;
102 GstDebugCategory *GST_CAT_COTHREADS = NULL;
103 GstDebugCategory *GST_CAT_COTHREAD_SWITCH = NULL;
104 GstDebugCategory *GST_CAT_AUTOPLUG = NULL;
105 GstDebugCategory *GST_CAT_AUTOPLUG_ATTEMPT = NULL;
106 GstDebugCategory *GST_CAT_PARENTAGE = NULL;
107 GstDebugCategory *GST_CAT_STATES = NULL;
108 GstDebugCategory *GST_CAT_PLANNING = NULL;
109 GstDebugCategory *GST_CAT_SCHEDULING = NULL;
110 GstDebugCategory *GST_CAT_DATAFLOW = NULL;
111 GstDebugCategory *GST_CAT_BUFFER = NULL;
112 GstDebugCategory *GST_CAT_CAPS = NULL;
113 GstDebugCategory *GST_CAT_CLOCK = NULL;
114 GstDebugCategory *GST_CAT_ELEMENT_PADS = NULL;
115 GstDebugCategory *GST_CAT_ELEMENT_FACTORY = NULL;
116 GstDebugCategory *GST_CAT_PADS = NULL;
117 GstDebugCategory *GST_CAT_PIPELINE = NULL;
118 GstDebugCategory *GST_CAT_PLUGIN_LOADING = NULL;
119 GstDebugCategory *GST_CAT_PLUGIN_INFO = NULL;
120 GstDebugCategory *GST_CAT_PROPERTIES = NULL;
121 GstDebugCategory *GST_CAT_THREAD = NULL;
122 GstDebugCategory *GST_CAT_TYPES = NULL;
123 GstDebugCategory *GST_CAT_XML = NULL;
124 GstDebugCategory *GST_CAT_NEGOTIATION = NULL;
125 GstDebugCategory *GST_CAT_REFCOUNTING = NULL;
126 GstDebugCategory *GST_CAT_EVENT = NULL;
127 GstDebugCategory *GST_CAT_PARAMS = NULL;
128 GstDebugCategory *GST_CAT_CALL_TRACE = NULL;
129 GstDebugCategory *GST_CAT_SEEK = NULL;
134 * Initializes the debugging system.
135 * Normally you don't want to call this, because gst_init does it for you.
137 void _gst_debug_init (void)
139 gst_atomic_int_init (&__default_level, GST_LEVEL_DEFAULT);
140 gst_atomic_int_init (&__use_color, 1);
142 /* do NOT use a single debug function before this line has been run */
143 GST_CAT_DEFAULT = _gst_debug_category_new ("default",
146 GST_CAT_DEBUG = _gst_debug_category_new ("GST_DEBUG",
147 GST_DEBUG_BOLD | GST_DEBUG_FG_YELLOW,
148 "debugging subsystem");
150 gst_debug_add_log_function (gst_debug_log_default, NULL);
152 /* FIXME: add descriptions here */
153 GST_CAT_GST_INIT = _gst_debug_category_new ("GST_INIT",
154 GST_DEBUG_BOLD | GST_DEBUG_FG_RED,
156 GST_CAT_COTHREADS = _gst_debug_category_new ("GST_COTHREADS",
157 GST_DEBUG_BOLD | GST_DEBUG_FG_GREEN,
159 GST_CAT_COTHREAD_SWITCH = _gst_debug_category_new ("GST_COTHREAD_SWITCH",
160 GST_DEBUG_BOLD | GST_DEBUG_FG_WHITE | GST_DEBUG_BG_GREEN,
162 GST_CAT_AUTOPLUG = _gst_debug_category_new ("GST_AUTOPLUG",
163 GST_DEBUG_BOLD | GST_DEBUG_FG_BLUE,
165 GST_CAT_AUTOPLUG_ATTEMPT = _gst_debug_category_new ("GST_AUTOPLUG_ATTEMPT",
166 GST_DEBUG_BOLD | GST_DEBUG_FG_CYAN | GST_DEBUG_BG_BLUE,
168 GST_CAT_PARENTAGE = _gst_debug_category_new ("GST_PARENTAGE",
169 GST_DEBUG_BOLD | GST_DEBUG_FG_WHITE | GST_DEBUG_BG_RED,
171 GST_CAT_STATES = _gst_debug_category_new ("GST_STATES",
172 GST_DEBUG_BOLD | GST_DEBUG_FG_RED,
174 GST_CAT_PLANNING = _gst_debug_category_new ("GST_PLANNING",
175 GST_DEBUG_BOLD | GST_DEBUG_FG_MAGENTA,
177 GST_CAT_SCHEDULING = _gst_debug_category_new ("GST_SCHEDULING",
178 GST_DEBUG_BOLD | GST_DEBUG_FG_MAGENTA,
180 GST_CAT_DATAFLOW = _gst_debug_category_new ("GST_DATAFLOW",
181 GST_DEBUG_BOLD | GST_DEBUG_FG_GREEN,
183 GST_CAT_BUFFER = _gst_debug_category_new ("GST_BUFFER",
184 GST_DEBUG_BOLD | GST_DEBUG_FG_GREEN,
186 GST_CAT_CAPS = _gst_debug_category_new ("GST_CAPS",
187 GST_DEBUG_BOLD | GST_DEBUG_FG_BLUE,
189 GST_CAT_CLOCK = _gst_debug_category_new ("GST_CLOCK",
190 GST_DEBUG_BOLD | GST_DEBUG_FG_YELLOW,
192 GST_CAT_ELEMENT_PADS = _gst_debug_category_new ("GST_ELEMENT_PADS",
193 GST_DEBUG_BOLD | GST_DEBUG_FG_WHITE | GST_DEBUG_BG_RED,
195 GST_CAT_ELEMENT_FACTORY = _gst_debug_category_new ("GST_ELEMENT_FACTORY",
196 GST_DEBUG_BOLD | GST_DEBUG_FG_WHITE | GST_DEBUG_BG_RED,
198 GST_CAT_PADS = _gst_debug_category_new ("GST_PADS",
199 GST_DEBUG_BOLD | GST_DEBUG_FG_WHITE | GST_DEBUG_BG_RED,
201 GST_CAT_PIPELINE = _gst_debug_category_new ("GST_PIPELINE",
202 GST_DEBUG_BOLD | GST_DEBUG_FG_WHITE | GST_DEBUG_BG_RED,
204 GST_CAT_PLUGIN_LOADING = _gst_debug_category_new ("GST_PLUGIN_LOADING",
205 GST_DEBUG_BOLD | GST_DEBUG_FG_CYAN,
207 GST_CAT_PLUGIN_INFO = _gst_debug_category_new ("GST_PLUGIN_INFO",
208 GST_DEBUG_BOLD | GST_DEBUG_FG_CYAN,
210 GST_CAT_PROPERTIES = _gst_debug_category_new ("GST_PROPERTIES",
211 GST_DEBUG_BOLD | GST_DEBUG_FG_WHITE | GST_DEBUG_BG_BLUE,
213 GST_CAT_THREAD = _gst_debug_category_new ("GST_THREAD",
214 GST_DEBUG_BOLD | GST_DEBUG_FG_RED,
216 GST_CAT_TYPES = _gst_debug_category_new ("GST_TYPES",
217 GST_DEBUG_BOLD | GST_DEBUG_FG_WHITE | GST_DEBUG_BG_RED,
219 GST_CAT_XML = _gst_debug_category_new ("GST_XML",
220 GST_DEBUG_BOLD | GST_DEBUG_FG_WHITE | GST_DEBUG_BG_RED,
222 GST_CAT_NEGOTIATION = _gst_debug_category_new ("GST_NEGOTIATION",
223 GST_DEBUG_BOLD | GST_DEBUG_FG_BLUE,
225 GST_CAT_REFCOUNTING = _gst_debug_category_new ("GST_REFCOUNTING",
226 GST_DEBUG_BOLD | GST_DEBUG_FG_BLUE | GST_DEBUG_BG_GREEN,
228 GST_CAT_EVENT = _gst_debug_category_new ("GST_EVENT",
229 GST_DEBUG_BOLD | GST_DEBUG_FG_WHITE | GST_DEBUG_BG_RED,
231 GST_CAT_PARAMS = _gst_debug_category_new ("GST_PARAMS",
232 GST_DEBUG_BOLD | GST_DEBUG_FG_BLACK | GST_DEBUG_BG_YELLOW,
234 GST_CAT_CALL_TRACE = _gst_debug_category_new ("GST_CALL_TRACE",
237 GST_CAT_SEEK = _gst_debug_category_new ("GST_SEEK",
239 "plugins reacting to seek events");
242 /* we can't do this further above, because we initialize the GST_CAT_DEFAULT struct */
243 #define GST_CAT_DEFAULT GST_CAT_DEBUG
247 * @category: category to log
248 * @level: level of the message is in
249 * @file: the file that emitted the message, usually the __FILE__ identifier
250 * @function: the function that emitted the message
251 * @line: the line from that the message was emitted, usually __LINE__
252 * @object: the object this message relates to or NULL if none
253 * @format: a printf style format string
254 * @...: optional arguments for the format
256 * Logs the given message using the currently registered debugging handlers.
258 void gst_debug_log (GstDebugCategory *category, GstDebugLevel level,
259 const gchar *file, const gchar *function, gint line,
260 GObject *object, gchar *format, ...)
264 va_start (var_args, format);
265 gst_debug_logv (category, level, file, function, line, object, format, var_args);
270 * @category: category to log
271 * @level: level of the message is in
272 * @file: the file that emitted the message, usually the __FILE__ identifier
273 * @function: the function that emitted the message
274 * @line: the line from that the message was emitted, usually __LINE__
275 * @object: the object this message relates to or NULL if none
276 * @format: a printf style format string
277 * @args: optional arguments for the format
279 * Logs the given message using the currently registered debugging handlers.
281 void gst_debug_logv (GstDebugCategory *category, GstDebugLevel level,
282 const gchar *file, const gchar *function, gint line,
283 GObject *object, gchar *format, va_list args)
289 g_return_if_fail (category != NULL);
290 g_return_if_fail (file != NULL);
291 g_return_if_fail (function != NULL);
292 g_return_if_fail (format != NULL);
294 message = g_strdup_vprintf (format, args);
295 handler = __log_functions;
297 entry = handler->data;
298 handler = g_slist_next (handler);
299 entry->func (category, level, file, function, line, object, message, entry->user_data);
304 * gst_debug_construct_term_color:
305 * @colorinfo: the color info
307 * Constructs a string that can be used for getting the desired color in color
309 * You need to free the string after use.
311 * Returns: a string containing the color definition
314 gst_debug_construct_term_color (guint colorinfo)
319 color = g_string_new ("\033[00");
321 if (colorinfo & GST_DEBUG_BOLD) {
322 g_string_append (color, ";01");
324 if (colorinfo & GST_DEBUG_UNDERLINE) {
325 g_string_append (color, ";04");
327 if (colorinfo & GST_DEBUG_FG_MASK) {
328 g_string_append_printf (color, ";3%1d", colorinfo & GST_DEBUG_FG_MASK);
330 if (colorinfo & GST_DEBUG_BG_MASK) {
331 g_string_append_printf (color, ";4%1d", (colorinfo & GST_DEBUG_BG_MASK) >> 4);
333 g_string_append (color, "m");
336 g_string_free (color, FALSE);
340 * gst_debug_log_default:
341 * @category: category to log
342 * @level: level of the message
343 * @file: the file that emitted the message, usually the __FILE__ identifier
344 * @function: the function that emitted the message
345 * @line: the line from that the message was emitted, usually __LINE__
346 * @message: the actual message
347 * @object: the object this message relates to or NULL if none
348 * @unused: an unused variable, reserved for some user_data.
350 * The default logging handler used by GStreamer. Logging functions get called
351 * whenever a macro like GST_DEBUG or similar is used. This function outputs the
352 * message and additional info using the glib error handler.
353 * You can add other handlers by using #gst_debug_add_log_function.
354 * And you can remove this handler by calling
355 * gst_debug_remove_log_function (gst_debug_log_default);
358 gst_debug_log_default (GstDebugCategory *category, GstDebugLevel level,
359 const gchar *file, const gchar *function, gint line,
360 GObject *object, gchar *message, gpointer unused)
368 if (level > gst_debug_category_get_threshold (category))
374 if (gst_debug_is_colored ()) {
375 color = gst_debug_construct_term_color (gst_debug_category_get_color (category));
377 pidcolor = g_strdup_printf ("\033[3%1dm", pid % 6 + 31);
379 color = g_strdup ("");
381 pidcolor = g_strdup ("");
383 /* nicely printed object */
384 if (object == NULL) {
386 } else if (GST_IS_PAD (object) && GST_OBJECT_NAME (object)) {
387 obj = g_strdup_printf (" [%s:%s]", GST_DEBUG_PAD_NAME (object));
388 } else if (GST_IS_OBJECT (object) && GST_OBJECT_NAME (object)) {
389 obj = g_strdup_printf (" [%s]", GST_OBJECT_NAME (object));
391 obj = g_strdup_printf (" [%s@%p]", G_OBJECT_TYPE_NAME(object), object);
394 g_printerr ("%s %s%15s%s(%s%5d%s) %s%s(%d):%s:%s%s %s\n",
395 gst_debug_level_get_name (level),
396 color, gst_debug_category_get_name (category), clear,
397 pidcolor, pid, clear,
398 color, file, line, function, obj, clear,
406 * gst_debug_level_get_name:
407 * @level: the level to get the name for
409 * Get the string trepresentation of a debugging level
414 gst_debug_level_get_name (GstDebugLevel level)
417 case GST_LEVEL_NONE: return "";
418 case GST_LEVEL_ERROR: return "ERROR";
419 case GST_LEVEL_WARNING: return "WARN ";
420 case GST_LEVEL_INFO: return "INFO ";
421 case GST_LEVEL_DEBUG: return "DEBUG";
422 case GST_LEVEL_LOG: return "LOG ";
424 g_warning ("invalid level specified for gst_debug_level_get_name");
429 * gst_debug_add_log_function:
430 * @func: the function to use
433 * Adds the logging function to the list of logging functions.
434 * Be sure to use G_GNUC_NO_INSTRUMENT on that function, it is needed.
437 gst_debug_add_log_function (GstLogFunction func, gpointer data)
442 g_return_if_fail (func != NULL);
444 entry = g_new (LogFuncEntry, 1);
446 entry->user_data = data;
447 /* FIXME: we leak the old list here - other threads might access it right now
448 * in gst_debug_logv. Another solution is to lock the mutex in gst_debug_logv,
449 * but that is waaay costly.
450 * It'd probably be clever to use some kind of RCU here, but I don't know
451 * anything about that.
453 g_static_mutex_lock (&__log_func_mutex);
454 list = g_slist_copy (__log_functions);
455 __log_functions = g_slist_prepend (list, entry);
456 g_static_mutex_unlock (&__log_func_mutex);
458 GST_DEBUG ("prepended log function %p (user data %p) to log functions",
462 gst_debug_compare_log_function_by_func (gconstpointer entry, gconstpointer func)
464 gpointer entryfunc = ((LogFuncEntry *) entry)->func;
466 return (entryfunc < func) ? -1 : (entryfunc > func) ? 1 : 0;
469 gst_debug_compare_log_function_by_data (gconstpointer entry, gconstpointer data)
471 gpointer entrydata = ((LogFuncEntry *) entry)->user_data;
473 return (entrydata < data) ? -1 : (entrydata > data) ? 1 : 0;
476 gst_debug_remove_with_compare_func (GCompareFunc func, gpointer data)
481 g_static_mutex_lock (&__log_func_mutex);
482 new = __log_functions;
483 while ((found = g_slist_find_custom (new, data, func))) {
484 if (new == __log_functions) {
485 new = g_slist_copy (new);
488 g_free (found->data);
489 new = g_slist_remove_link (new, found);
490 g_slist_free_1 (found);
493 /* FIXME: We leak the old list here. See _add_log_function for why. */
494 __log_functions = new;
495 g_static_mutex_unlock (&__log_func_mutex);
500 * gst_debug_remove_log_function:
501 * @func: the log function to remove
503 * Removes all registrered instances of the given logging functions.
505 * Returns: How many instances of the function were removed
508 gst_debug_remove_log_function (GstLogFunction func)
512 g_return_val_if_fail (func != NULL, 0);
514 removals = gst_debug_remove_with_compare_func (gst_debug_compare_log_function_by_func, func);
515 GST_DEBUG ("removed log function %p %d times from log function list",
521 * gst_debug_remove_log_function_by_data:
522 * @data: user data of the log function to remove
524 * Removes all registrered instances of log functions with the given user data.
526 * Returns: How many instances of the function were removed
529 gst_debug_remove_log_function_by_data (gpointer data)
533 removals = gst_debug_remove_with_compare_func (gst_debug_compare_log_function_by_data, data);
534 GST_DEBUG ("removed %d log functions with user data %p from log function list",
540 * gst_debug_set_colored:
541 * @colored: Whether to use colored output or not
543 * Sets or unsets the use of coloured debugging output.
546 gst_debug_set_colored (gboolean colored)
548 gst_atomic_int_set (&__use_color, colored ? 1 : 0);
551 * gst_debug_is_colored:
553 * Checks if the debugging output should be colored.
555 * Returns: TRUE, if the debug output should be colored.
558 gst_debug_is_colored (void)
560 return gst_atomic_int_read (&__use_color) == 0 ? FALSE : TRUE;
563 * gst_debug_set_active:
564 * @active: Whether to use debugging output or not
566 * If activated, debugging messages are sent to the debugging
568 * It makes sense to deactivate it for speed issues.
569 * <note><para>This function is not threadsafe. It makes sense to only call it
570 * during initialization.</para></note>
573 gst_debug_set_active (gboolean active)
575 __gst_debug_enabled = active;
578 * gst_debug_is_active:
580 * Checks if debugging output is activated.
582 * Returns: TRUE, if debugging is activated
585 gst_debug_is_active (void)
587 return __gst_debug_enabled;
590 * gst_debug_set_default_threshold:
591 * @level: level to set
593 * Sets the default threshold to the given level and updates all categories to
594 * use this threshold.
597 gst_debug_set_default_threshold (GstDebugLevel level)
599 gst_atomic_int_set (&__default_level, level);
600 gst_debug_reset_all_thresholds ();
603 * gst_debug_get_default_threshold:
605 * Returns the default threshold that is used for new categories.
607 * Returns: the default threshold level
610 gst_debug_get_default_threshold (void)
612 return (GstDebugLevel) gst_atomic_int_read (&__default_level);
615 gst_debug_reset_threshold (gpointer category, gpointer unused)
617 GstDebugCategory *cat = (GstDebugCategory *) category;
620 g_static_mutex_lock (&__level_name_mutex);
623 LevelNameEntry *entry = walk->data;
624 walk = g_slist_next (walk);
625 if (g_pattern_match_string (entry->pat, cat->name)) {
626 GST_LOG ("category %s matches pattern %p - gets set to level %d",
627 cat->name, entry->pat, entry->level);
628 gst_debug_category_set_threshold (cat, entry->level);
632 gst_debug_category_set_threshold (cat, gst_debug_get_default_threshold ());
635 g_static_mutex_unlock (&__level_name_mutex);
638 gst_debug_reset_all_thresholds (void)
640 g_static_mutex_lock (&__cat_mutex);
641 g_slist_foreach (__categories, gst_debug_reset_threshold, NULL);
642 g_static_mutex_unlock (&__cat_mutex);
645 for_each_threshold_by_entry (gpointer data, gpointer user_data)
647 GstDebugCategory *cat = (GstDebugCategory *) data;
648 LevelNameEntry *entry = (LevelNameEntry *) user_data;
650 if (g_pattern_match_string (entry->pat, cat->name)) {
651 GST_LOG ("category %s matches pattern %p - gets set to level %d",
652 cat->name, entry->pat, entry->level);
653 gst_debug_category_set_threshold (cat, entry->level);
657 * gst_debug_set_threshold_for_name:
658 * @name: name of the categories to set
659 * @level: level to set them to
661 * Sets all categories which match the gven glob style pattern to the given
665 gst_debug_set_threshold_for_name (const gchar *name, GstDebugLevel level)
668 LevelNameEntry *entry;
670 g_return_if_fail (name != NULL);
672 pat = g_pattern_spec_new (name);
673 entry = g_new (LevelNameEntry, 1);
675 entry->level = level;
676 g_static_mutex_lock (&__level_name_mutex);
677 __level_name = g_slist_prepend (__level_name, entry);
678 g_static_mutex_unlock (&__level_name_mutex);
679 g_static_mutex_lock (&__cat_mutex);
680 g_slist_foreach (__categories, for_each_threshold_by_entry, entry);
681 g_static_mutex_unlock (&__cat_mutex);
684 * gst_debug_unset_threshold_for_name:
685 * @name: name of the categories to set
687 * Resets all categories with the given name back to the default level.
690 gst_debug_unset_threshold_for_name (const gchar *name)
695 g_return_if_fail (name != NULL);
697 pat = g_pattern_spec_new (name);
698 g_static_mutex_lock (&__level_name_mutex);
700 /* improve this if you want, it's mighty slow */
702 LevelNameEntry *entry = walk->data;
703 if (g_pattern_spec_equal (entry->pat, pat)) {
704 __level_name = g_slist_remove_link (__level_name, walk);
705 g_pattern_spec_free (entry->pat);
707 g_slist_free_1 (walk);
711 g_static_mutex_unlock (&__level_name_mutex);
712 g_pattern_spec_free (pat);
713 gst_debug_reset_all_thresholds ();
716 _gst_debug_category_new (gchar *name, guint color, gchar *description)
718 GstDebugCategory *cat;
720 g_return_val_if_fail (name != NULL, NULL);
722 cat = g_new (GstDebugCategory, 1);
723 cat->name = g_strdup (name);
725 if (description != NULL) {
726 cat->description = g_strdup (description);
728 cat->description = g_strdup ("no description");
730 cat->threshold = g_new (GstAtomicInt, 1);
731 gst_atomic_int_init (cat->threshold, 0);
732 gst_debug_reset_threshold (cat, NULL);
734 /* add to category list */
735 g_static_mutex_lock (&__cat_mutex);
736 __categories = g_slist_prepend (__categories, cat);
737 g_static_mutex_unlock (&__cat_mutex);
742 * gst_debug_category_free:
743 * @category: category to remove
745 * Removes and frees the category and all associated ressources.
748 gst_debug_category_free (GstDebugCategory *category)
750 if (category == NULL) return;
752 /* remove from category list */
753 g_static_mutex_lock (&__cat_mutex);
754 __categories = g_slist_remove (__categories, category);
755 g_static_mutex_unlock (&__cat_mutex);
757 g_free ((gpointer) category->name);
758 g_free ((gpointer) category->description);
759 gst_atomic_int_destroy (category->threshold);
760 g_free (category->threshold);
764 * gst_debug_category_set_threshold:
765 * @category: category to set threshold for
766 * @level: the threshold to set
768 * Sets the threshold of the category to the given level. Debug information will
769 * only be output if the threshold is lower or equal to the level of the
772 * Do not use this function in production code, because other functions may
773 * change the threshold of categories as side effect. It is however a nice
774 * function to use when debugging (even from gdb).
778 gst_debug_category_set_threshold (GstDebugCategory *category, GstDebugLevel level)
780 g_return_if_fail (category != NULL);
782 gst_atomic_int_set (category->threshold, level);
785 * gst_debug_category_reset_threshold:
786 * @category: category to set threshold for
788 * Resets the threshold of the category to the default level. Debug information
789 * will only be output if the threshold is lower or equal to the level of the
791 * Use this function to set the threshold back to where it was after using
792 * gst_debug_category_set_threshold().
795 gst_debug_category_reset_threshold (GstDebugCategory *category)
797 gst_debug_reset_threshold (category, NULL);
800 * gst_debug_category_get_threshold:
801 * @category: category to get threshold for
803 * Returns the threshold of a #GstCategory.
805 * Returns: the level that is used as threshold
808 gst_debug_category_get_threshold (GstDebugCategory *category)
810 return gst_atomic_int_read (category->threshold);
813 * gst_debug_category_get_name:
814 * @category: category to get name for
816 * Returns the name of a #GstCategory.
818 * Returns: the name of the category
821 gst_debug_category_get_name (GstDebugCategory *category)
823 return category->name;
826 * gst_debug_category_get_color:
827 * @category: category to get color for
829 * Returns the color of a #GstCategory to use when outputting this.
831 * Returns: the color of the category
834 gst_debug_category_get_color (GstDebugCategory *category)
836 return category->color;
839 * gst_debug_category_get_description:
840 * @category: category to get description for
842 * Returns the description of a #GstCategory
844 * Returns: the description of the category
847 gst_debug_category_get_description (GstDebugCategory *category)
849 return category->description;
852 * gst_debug_get_all_categories:
854 * Returns a snapshot of a all categories that are currently in use . This list
855 * may change anytime.
856 * The caller has to free the list after use.
857 * <emphasis>This function is not threadsafe, so only use it while only the
858 * main thread is running.</emphasis>
860 * Returns: the list of categories
863 gst_debug_get_all_categories (void)
867 g_static_mutex_lock (&__cat_mutex);
868 ret = g_slist_copy (__categories);
869 g_static_mutex_unlock (&__cat_mutex);
874 /*** FUNCTION POINTERS ********************************************************/
876 GHashTable *__gst_function_pointers = NULL;
877 const gchar *_gst_debug_nameof_funcptr (void *ptr) G_GNUC_NO_INSTRUMENT;
879 /* This function MUST NOT return NULL */
881 _gst_debug_nameof_funcptr (void *ptr)
888 if (__gst_function_pointers && (ptrname = g_hash_table_lookup(__gst_function_pointers,ptr))) {
891 /* we need to create an entry in the hash table for this one so we don't leak
894 if (dladdr(ptr,&dlinfo) && dlinfo.dli_sname) {
895 gchar *name = g_strdup (dlinfo.dli_sname);
896 _gst_debug_register_funcptr (ptr, name);
901 gchar *name = g_strdup_printf ("%p", ptr);
902 _gst_debug_register_funcptr (ptr, name);
908 _gst_debug_register_funcptr (void *ptr, gchar *ptrname)
910 if (!__gst_function_pointers)
911 __gst_function_pointers = g_hash_table_new (g_direct_hash, g_direct_equal);
912 if (!g_hash_table_lookup (__gst_function_pointers, ptr))
913 g_hash_table_insert (__gst_function_pointers, ptr, ptrname);
918 #endif /* GST_DISABLE_GST_DEBUG */
920 #ifdef GST_ENABLE_FUNC_INSTRUMENTATION
921 /* FIXME make this thread specific */
922 static GSList *stack_trace = NULL;
924 void __cyg_profile_func_enter(void *this_fn,void *call_site) G_GNUC_NO_INSTRUMENT;
925 void __cyg_profile_func_enter(void *this_fn,void *call_site)
927 gchar *name = _gst_debug_nameof_funcptr (this_fn);
928 gchar *site = _gst_debug_nameof_funcptr (call_site);
930 GST_CAT_DEBUG(GST_CAT_CALL_TRACE, "entering function %s from %s", name, site);
931 stack_trace = g_slist_prepend (stack_trace, g_strdup_printf ("%8p in %s from %p (%s)", this_fn, name, call_site, site));
937 void __cyg_profile_func_exit(void *this_fn,void *call_site) G_GNUC_NO_INSTRUMENT;
938 void __cyg_profile_func_exit(void *this_fn,void *call_site)
940 gchar *name = _gst_debug_nameof_funcptr (this_fn);
942 GST_CAT_DEBUG(GST_CAT_CALL_TRACE, "leaving function %s", name);
943 g_free (stack_trace->data);
944 stack_trace = g_slist_delete_link (stack_trace, stack_trace);
950 gst_debug_print_stack_trace (void)
952 GSList *walk = stack_trace;
956 walk = g_slist_next (walk);
959 gchar *name = (gchar *) walk->data;
961 g_print ("#%-2d %s\n", count++, name);
963 walk = g_slist_next (walk);
968 gst_debug_print_stack_trace (void)
970 /* nothing because it's compiled out */
973 #endif /* GST_ENABLE_FUNC_INTSTRUMENTATION */