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_PADS = NULL;
116 GstDebugCategory *GST_CAT_PIPELINE = NULL;
117 GstDebugCategory *GST_CAT_PLUGIN_LOADING = NULL;
118 GstDebugCategory *GST_CAT_PLUGIN_INFO = NULL;
119 GstDebugCategory *GST_CAT_PROPERTIES = NULL;
120 GstDebugCategory *GST_CAT_THREAD = NULL;
121 GstDebugCategory *GST_CAT_TYPES = NULL;
122 GstDebugCategory *GST_CAT_XML = NULL;
123 GstDebugCategory *GST_CAT_NEGOTIATION = NULL;
124 GstDebugCategory *GST_CAT_REFCOUNTING = NULL;
125 GstDebugCategory *GST_CAT_EVENT = NULL;
126 GstDebugCategory *GST_CAT_PARAMS = NULL;
127 GstDebugCategory *GST_CAT_CALL_TRACE = NULL;
128 GstDebugCategory *GST_CAT_SEEK = NULL;
133 * Initializes the debugging system.
134 * Normally you don't want to call this, because gst_init does it for you.
136 void _gst_debug_init (void)
138 gst_atomic_int_init (&__default_level, GST_LEVEL_DEFAULT);
139 gst_atomic_int_init (&__use_color, 1);
141 /* do NOT use a single debug function before this line has been run */
142 GST_CAT_DEFAULT = _gst_debug_category_new ("default",
145 GST_CAT_DEBUG = _gst_debug_category_new ("GST_DEBUG",
146 GST_DEBUG_BOLD | GST_DEBUG_FG_YELLOW,
147 "debugging subsystem");
149 gst_debug_add_log_function (gst_debug_log_default, NULL);
151 /* FIXME: add descriptions here */
152 GST_CAT_GST_INIT = _gst_debug_category_new ("GST_INIT",
153 GST_DEBUG_BOLD | GST_DEBUG_FG_RED,
155 GST_CAT_COTHREADS = _gst_debug_category_new ("GST_COTHREADS",
156 GST_DEBUG_BOLD | GST_DEBUG_FG_GREEN,
158 GST_CAT_COTHREAD_SWITCH = _gst_debug_category_new ("GST_COTHREAD_SWITCH",
159 GST_DEBUG_BOLD | GST_DEBUG_FG_WHITE | GST_DEBUG_BG_GREEN,
161 GST_CAT_AUTOPLUG = _gst_debug_category_new ("GST_AUTOPLUG",
162 GST_DEBUG_BOLD | GST_DEBUG_FG_BLUE,
164 GST_CAT_AUTOPLUG_ATTEMPT = _gst_debug_category_new ("GST_AUTOPLUG_ATTEMPT",
165 GST_DEBUG_BOLD | GST_DEBUG_FG_CYAN | GST_DEBUG_BG_BLUE,
167 GST_CAT_PARENTAGE = _gst_debug_category_new ("GST_PARENTAGE",
168 GST_DEBUG_BOLD | GST_DEBUG_FG_WHITE | GST_DEBUG_BG_RED,
170 GST_CAT_STATES = _gst_debug_category_new ("GST_STATES",
171 GST_DEBUG_BOLD | GST_DEBUG_FG_RED,
173 GST_CAT_PLANNING = _gst_debug_category_new ("GST_PLANNING",
174 GST_DEBUG_BOLD | GST_DEBUG_FG_MAGENTA,
176 GST_CAT_SCHEDULING = _gst_debug_category_new ("GST_SCHEDULING",
177 GST_DEBUG_BOLD | GST_DEBUG_FG_MAGENTA,
179 GST_CAT_DATAFLOW = _gst_debug_category_new ("GST_DATAFLOW",
180 GST_DEBUG_BOLD | GST_DEBUG_FG_GREEN,
182 GST_CAT_BUFFER = _gst_debug_category_new ("GST_BUFFER",
183 GST_DEBUG_BOLD | GST_DEBUG_FG_GREEN,
185 GST_CAT_CAPS = _gst_debug_category_new ("GST_CAPS",
186 GST_DEBUG_BOLD | GST_DEBUG_FG_BLUE,
188 GST_CAT_CLOCK = _gst_debug_category_new ("GST_CLOCK",
189 GST_DEBUG_BOLD | GST_DEBUG_FG_YELLOW,
191 GST_CAT_ELEMENT_PADS = _gst_debug_category_new ("GST_ELEMENT_PADS",
192 GST_DEBUG_BOLD | GST_DEBUG_FG_WHITE | GST_DEBUG_BG_RED,
194 GST_CAT_PADS = _gst_debug_category_new ("GST_PADS",
195 GST_DEBUG_BOLD | GST_DEBUG_FG_WHITE | GST_DEBUG_BG_RED,
197 GST_CAT_PIPELINE = _gst_debug_category_new ("GST_PIPELINE",
198 GST_DEBUG_BOLD | GST_DEBUG_FG_WHITE | GST_DEBUG_BG_RED,
200 GST_CAT_PLUGIN_LOADING = _gst_debug_category_new ("GST_PLUGIN_LOADING",
201 GST_DEBUG_BOLD | GST_DEBUG_FG_CYAN,
203 GST_CAT_PLUGIN_INFO = _gst_debug_category_new ("GST_PLUGIN_INFO",
204 GST_DEBUG_BOLD | GST_DEBUG_FG_CYAN,
206 GST_CAT_PROPERTIES = _gst_debug_category_new ("GST_PROPERTIES",
207 GST_DEBUG_BOLD | GST_DEBUG_FG_WHITE | GST_DEBUG_BG_BLUE,
209 GST_CAT_THREAD = _gst_debug_category_new ("GST_THREAD",
210 GST_DEBUG_BOLD | GST_DEBUG_FG_RED,
212 GST_CAT_TYPES = _gst_debug_category_new ("GST_TYPES",
213 GST_DEBUG_BOLD | GST_DEBUG_FG_WHITE | GST_DEBUG_BG_RED,
215 GST_CAT_XML = _gst_debug_category_new ("GST_XML",
216 GST_DEBUG_BOLD | GST_DEBUG_FG_WHITE | GST_DEBUG_BG_RED,
218 GST_CAT_NEGOTIATION = _gst_debug_category_new ("GST_NEGOTIATION",
219 GST_DEBUG_BOLD | GST_DEBUG_FG_BLUE,
221 GST_CAT_REFCOUNTING = _gst_debug_category_new ("GST_REFCOUNTING",
222 GST_DEBUG_BOLD | GST_DEBUG_FG_BLUE | GST_DEBUG_BG_GREEN,
224 GST_CAT_EVENT = _gst_debug_category_new ("GST_EVENT",
225 GST_DEBUG_BOLD | GST_DEBUG_FG_WHITE | GST_DEBUG_BG_RED,
227 GST_CAT_PARAMS = _gst_debug_category_new ("GST_PARAMS",
228 GST_DEBUG_BOLD | GST_DEBUG_FG_BLACK | GST_DEBUG_BG_YELLOW,
230 GST_CAT_CALL_TRACE = _gst_debug_category_new ("GST_CALL_TRACE",
233 GST_CAT_SEEK = _gst_debug_category_new ("GST_SEEK",
235 "plugins reacting to seek events");
238 /* we can't do this further above, because we initialize the GST_CAT_DEFAULT struct */
239 #define GST_CAT_DEFAULT GST_CAT_DEBUG
243 * @category: category to log
244 * @level: level of the message is in
245 * @file: the file that emitted the message, usually the __FILE__ identifier
246 * @function: the function that emitted the message
247 * @line: the line from that the message was emitted, usually __LINE__
248 * @object: the object this message relates to or NULL if none
249 * @format: a printf style format string
250 * @...: optional arguments for the format
252 * Logs the given message using the currently registered debugging handlers.
254 void gst_debug_log (GstDebugCategory *category, GstDebugLevel level,
255 const gchar *file, const gchar *function, gint line,
256 GObject *object, gchar *format, ...)
260 va_start (var_args, format);
261 gst_debug_log_valist (category, level, file, function, line, object, format, var_args);
265 * gst_debug_log_valist:
266 * @category: category to log
267 * @level: level of the message is in
268 * @file: the file that emitted the message, usually the __FILE__ identifier
269 * @function: the function that emitted the message
270 * @line: the line from that the message was emitted, usually __LINE__
271 * @object: the object this message relates to or NULL if none
272 * @format: a printf style format string
273 * @args: optional arguments for the format
275 * Logs the given message using the currently registered debugging handlers.
277 void gst_debug_log_valist (GstDebugCategory *category, GstDebugLevel level,
278 const gchar *file, const gchar *function, gint line,
279 GObject *object, gchar *format, va_list args)
285 g_return_if_fail (category != NULL);
286 g_return_if_fail (file != NULL);
287 g_return_if_fail (function != NULL);
288 g_return_if_fail (format != NULL);
290 message = g_strdup_vprintf (format, args);
291 handler = __log_functions;
293 entry = handler->data;
294 handler = g_slist_next (handler);
295 entry->func (category, level, file, function, line, object, message, entry->user_data);
300 * gst_debug_construct_term_color:
301 * @colorinfo: the color info
303 * Constructs a string that can be used for getting the desired color in color
305 * You need to free the string after use.
307 * Returns: a string containing the color definition
310 gst_debug_construct_term_color (guint colorinfo)
315 color = g_string_new ("\033[00");
317 if (colorinfo & GST_DEBUG_BOLD) {
318 g_string_append (color, ";01");
320 if (colorinfo & GST_DEBUG_UNDERLINE) {
321 g_string_append (color, ";04");
323 if (colorinfo & GST_DEBUG_FG_MASK) {
324 g_string_append_printf (color, ";3%1d", colorinfo & GST_DEBUG_FG_MASK);
326 if (colorinfo & GST_DEBUG_BG_MASK) {
327 g_string_append_printf (color, ";4%1d", (colorinfo & GST_DEBUG_BG_MASK) >> 4);
329 g_string_append (color, "m");
332 g_string_free (color, FALSE);
336 * gst_debug_log_default:
337 * @category: category to log
338 * @level: level of the message
339 * @file: the file that emitted the message, usually the __FILE__ identifier
340 * @function: the function that emitted the message
341 * @line: the line from that the message was emitted, usually __LINE__
342 * @message: the actual message
343 * @object: the object this message relates to or NULL if none
344 * @unused: an unused variable, reserved for some user_data.
346 * The default logging handler used by GStreamer. Logging functions get called
347 * whenever a macro like GST_DEBUG or similar is used. This function outputs the
348 * message and additional info using the glib error handler.
349 * You can add other handlers by using #gst_debug_add_log_function.
350 * And you can remove this handler by calling
351 * gst_debug_remove_log_function (gst_debug_log_default);
354 gst_debug_log_default (GstDebugCategory *category, GstDebugLevel level,
355 const gchar *file, const gchar *function, gint line,
356 GObject *object, gchar *message, gpointer unused)
364 if (level > gst_debug_category_get_threshold (category))
370 if (gst_debug_is_colored ()) {
371 color = gst_debug_construct_term_color (gst_debug_category_get_color (category));
373 pidcolor = g_strdup_printf ("\033[3%1dm", pid % 6 + 31);
375 color = g_strdup ("");
377 pidcolor = g_strdup ("");
379 /* nicely printed object */
380 if (object == NULL) {
382 } else if (GST_IS_PAD (object) && GST_OBJECT_NAME (object)) {
383 obj = g_strdup_printf (" [%s:%s]", GST_DEBUG_PAD_NAME (object));
384 } else if (GST_IS_OBJECT (object) && GST_OBJECT_NAME (object)) {
385 obj = g_strdup_printf (" [%s]", GST_OBJECT_NAME (object));
387 obj = g_strdup_printf (" [%s@%p]", G_OBJECT_TYPE_NAME(object), object);
390 g_printerr ("%s %s%15s%s(%s%5d%s) %s%s(%d):%s:%s%s %s\n",
391 gst_debug_level_get_name (level),
392 color, gst_debug_category_get_name (category), clear,
393 pidcolor, pid, clear,
394 color, file, line, function, obj, clear,
402 * gst_debug_level_get_name:
403 * @level: the level to get the name for
405 * Get the string trepresentation of a debugging level
410 gst_debug_level_get_name (GstDebugLevel level)
413 case GST_LEVEL_NONE: return "";
414 case GST_LEVEL_ERROR: return "ERROR";
415 case GST_LEVEL_WARNING: return "WARN ";
416 case GST_LEVEL_INFO: return "INFO ";
417 case GST_LEVEL_DEBUG: return "DEBUG";
418 case GST_LEVEL_LOG: return "LOG ";
420 g_warning ("invalid level specified for gst_debug_level_get_name");
425 * gst_debug_add_log_function:
426 * @func: the function to use
429 * Adds the logging function to the list of logging functions.
430 * Be sure to use G_GNUC_NO_INSTRUMENT on that function, it is needed.
433 gst_debug_add_log_function (GstLogFunction func, gpointer data)
438 g_return_if_fail (func != NULL);
440 entry = g_new (LogFuncEntry, 1);
442 entry->user_data = data;
443 /* FIXME: we leak the old list here - other threads might access it right now
444 * in gst_debug_logv. Another solution is to lock the mutex in gst_debug_logv,
445 * but that is waaay costly.
446 * It'd probably be clever to use some kind of RCU here, but I don't know
447 * anything about that.
449 g_static_mutex_lock (&__log_func_mutex);
450 list = g_slist_copy (__log_functions);
451 __log_functions = g_slist_prepend (list, entry);
452 g_static_mutex_unlock (&__log_func_mutex);
454 GST_DEBUG ("prepended log function %p (user data %p) to log functions",
458 gst_debug_compare_log_function_by_func (gconstpointer entry, gconstpointer func)
460 gpointer entryfunc = ((LogFuncEntry *) entry)->func;
462 return (entryfunc < func) ? -1 : (entryfunc > func) ? 1 : 0;
465 gst_debug_compare_log_function_by_data (gconstpointer entry, gconstpointer data)
467 gpointer entrydata = ((LogFuncEntry *) entry)->user_data;
469 return (entrydata < data) ? -1 : (entrydata > data) ? 1 : 0;
472 gst_debug_remove_with_compare_func (GCompareFunc func, gpointer data)
477 g_static_mutex_lock (&__log_func_mutex);
478 new = __log_functions;
479 while ((found = g_slist_find_custom (new, data, func))) {
480 if (new == __log_functions) {
481 new = g_slist_copy (new);
484 g_free (found->data);
485 new = g_slist_delete_link (new, found);
488 /* FIXME: We leak the old list here. See _add_log_function for why. */
489 __log_functions = new;
490 g_static_mutex_unlock (&__log_func_mutex);
495 * gst_debug_remove_log_function:
496 * @func: the log function to remove
498 * Removes all registrered instances of the given logging functions.
500 * Returns: How many instances of the function were removed
503 gst_debug_remove_log_function (GstLogFunction func)
507 g_return_val_if_fail (func != NULL, 0);
509 removals = gst_debug_remove_with_compare_func (gst_debug_compare_log_function_by_func, func);
510 GST_DEBUG ("removed log function %p %d times from log function list",
516 * gst_debug_remove_log_function_by_data:
517 * @data: user data of the log function to remove
519 * Removes all registrered instances of log functions with the given user data.
521 * Returns: How many instances of the function were removed
524 gst_debug_remove_log_function_by_data (gpointer data)
528 removals = gst_debug_remove_with_compare_func (gst_debug_compare_log_function_by_data, data);
529 GST_DEBUG ("removed %d log functions with user data %p from log function list",
535 * gst_debug_set_colored:
536 * @colored: Whether to use colored output or not
538 * Sets or unsets the use of coloured debugging output.
541 gst_debug_set_colored (gboolean colored)
543 gst_atomic_int_set (&__use_color, colored ? 1 : 0);
546 * gst_debug_is_colored:
548 * Checks if the debugging output should be colored.
550 * Returns: TRUE, if the debug output should be colored.
553 gst_debug_is_colored (void)
555 return gst_atomic_int_read (&__use_color) == 0 ? FALSE : TRUE;
558 * gst_debug_set_active:
559 * @active: Whether to use debugging output or not
561 * If activated, debugging messages are sent to the debugging
563 * It makes sense to deactivate it for speed issues.
564 * <note><para>This function is not threadsafe. It makes sense to only call it
565 * during initialization.</para></note>
568 gst_debug_set_active (gboolean active)
570 __gst_debug_enabled = active;
573 * gst_debug_is_active:
575 * Checks if debugging output is activated.
577 * Returns: TRUE, if debugging is activated
580 gst_debug_is_active (void)
582 return __gst_debug_enabled;
585 * gst_debug_set_default_threshold:
586 * @level: level to set
588 * Sets the default threshold to the given level and updates all categories to
589 * use this threshold.
592 gst_debug_set_default_threshold (GstDebugLevel level)
594 gst_atomic_int_set (&__default_level, level);
595 gst_debug_reset_all_thresholds ();
598 * gst_debug_get_default_threshold:
600 * Returns the default threshold that is used for new categories.
602 * Returns: the default threshold level
605 gst_debug_get_default_threshold (void)
607 return (GstDebugLevel) gst_atomic_int_read (&__default_level);
610 gst_debug_reset_threshold (gpointer category, gpointer unused)
612 GstDebugCategory *cat = (GstDebugCategory *) category;
615 g_static_mutex_lock (&__level_name_mutex);
618 LevelNameEntry *entry = walk->data;
619 walk = g_slist_next (walk);
620 if (g_pattern_match_string (entry->pat, cat->name)) {
621 GST_LOG ("category %s matches pattern %p - gets set to level %d",
622 cat->name, entry->pat, entry->level);
623 gst_debug_category_set_threshold (cat, entry->level);
627 gst_debug_category_set_threshold (cat, gst_debug_get_default_threshold ());
630 g_static_mutex_unlock (&__level_name_mutex);
633 gst_debug_reset_all_thresholds (void)
635 g_static_mutex_lock (&__cat_mutex);
636 g_slist_foreach (__categories, gst_debug_reset_threshold, NULL);
637 g_static_mutex_unlock (&__cat_mutex);
640 for_each_threshold_by_entry (gpointer data, gpointer user_data)
642 GstDebugCategory *cat = (GstDebugCategory *) data;
643 LevelNameEntry *entry = (LevelNameEntry *) user_data;
645 if (g_pattern_match_string (entry->pat, cat->name)) {
646 GST_LOG ("category %s matches pattern %p - gets set to level %d",
647 cat->name, entry->pat, entry->level);
648 gst_debug_category_set_threshold (cat, entry->level);
652 * gst_debug_set_threshold_for_name:
653 * @name: name of the categories to set
654 * @level: level to set them to
656 * Sets all categories which match the gven glob style pattern to the given
660 gst_debug_set_threshold_for_name (const gchar *name, GstDebugLevel level)
663 LevelNameEntry *entry;
665 g_return_if_fail (name != NULL);
667 pat = g_pattern_spec_new (name);
668 entry = g_new (LevelNameEntry, 1);
670 entry->level = level;
671 g_static_mutex_lock (&__level_name_mutex);
672 __level_name = g_slist_prepend (__level_name, entry);
673 g_static_mutex_unlock (&__level_name_mutex);
674 g_static_mutex_lock (&__cat_mutex);
675 g_slist_foreach (__categories, for_each_threshold_by_entry, entry);
676 g_static_mutex_unlock (&__cat_mutex);
679 * gst_debug_unset_threshold_for_name:
680 * @name: name of the categories to set
682 * Resets all categories with the given name back to the default level.
685 gst_debug_unset_threshold_for_name (const gchar *name)
690 g_return_if_fail (name != NULL);
692 pat = g_pattern_spec_new (name);
693 g_static_mutex_lock (&__level_name_mutex);
695 /* improve this if you want, it's mighty slow */
697 LevelNameEntry *entry = walk->data;
698 if (g_pattern_spec_equal (entry->pat, pat)) {
699 __level_name = g_slist_remove_link (__level_name, walk);
700 g_pattern_spec_free (entry->pat);
702 g_slist_free_1 (walk);
706 g_static_mutex_unlock (&__level_name_mutex);
707 g_pattern_spec_free (pat);
708 gst_debug_reset_all_thresholds ();
711 _gst_debug_category_new (gchar *name, guint color, gchar *description)
713 GstDebugCategory *cat;
715 g_return_val_if_fail (name != NULL, NULL);
717 cat = g_new (GstDebugCategory, 1);
718 cat->name = g_strdup (name);
720 if (description != NULL) {
721 cat->description = g_strdup (description);
723 cat->description = g_strdup ("no description");
725 cat->threshold = g_new (GstAtomicInt, 1);
726 gst_atomic_int_init (cat->threshold, 0);
727 gst_debug_reset_threshold (cat, NULL);
729 /* add to category list */
730 g_static_mutex_lock (&__cat_mutex);
731 __categories = g_slist_prepend (__categories, cat);
732 g_static_mutex_unlock (&__cat_mutex);
737 * gst_debug_category_free:
738 * @category: #GstDebugCategory to free.
740 * Removes and frees the category and all associated resources.
743 gst_debug_category_free (GstDebugCategory *category)
745 if (category == NULL) return;
747 /* remove from category list */
748 g_static_mutex_lock (&__cat_mutex);
749 __categories = g_slist_remove (__categories, category);
750 g_static_mutex_unlock (&__cat_mutex);
752 g_free ((gpointer) category->name);
753 g_free ((gpointer) category->description);
754 gst_atomic_int_destroy (category->threshold);
755 g_free (category->threshold);
760 * gst_debug_category_set_threshold:
761 * @category: a #GstDebugCategory to set threshold of.
762 * @level: the #GstDebugLevel threshold to set.
764 * Sets the threshold of the category to the given level. Debug information will
765 * only be output if the threshold is lower or equal to the level of the
768 * Do not use this function in production code, because other functions may
769 * change the threshold of categories as side effect. It is however a nice
770 * function to use when debugging (even from gdb).
774 gst_debug_category_set_threshold (GstDebugCategory *category, GstDebugLevel level)
776 g_return_if_fail (category != NULL);
778 gst_atomic_int_set (category->threshold, level);
782 * gst_debug_category_reset_threshold:
783 * @category: a #GstDebugCategory to reset threshold of.
785 * Resets the threshold of the category to the default level. Debug information
786 * will only be output if the threshold is lower or equal to the level of the
788 * Use this function to set the threshold back to where it was after using
789 * gst_debug_category_set_threshold().
792 gst_debug_category_reset_threshold (GstDebugCategory *category)
794 gst_debug_reset_threshold (category, NULL);
798 * gst_debug_category_get_threshold:
799 * @category: a #GstDebugCategory to get threshold of.
801 * Returns the threshold of a #GstCategory.
803 * Returns: the #GstDebugLevel that is used as threshold.
806 gst_debug_category_get_threshold (GstDebugCategory *category)
808 return gst_atomic_int_read (category->threshold);
812 * gst_debug_category_get_name:
813 * @category: a #GstDebugCategory to get name of.
815 * Returns the name of a debug category.
817 * Returns: the name of the category.
820 gst_debug_category_get_name (GstDebugCategory *category)
822 return category->name;
826 * gst_debug_category_get_color:
827 * @category: a #GstDebugCategory to get the color of.
829 * Returns the color of a debug category used when printing output in this
832 * Returns: the color of the category.
835 gst_debug_category_get_color (GstDebugCategory *category)
837 return category->color;
841 * gst_debug_category_get_description:
842 * @category: a #GstDebugCategory to get the description of.
844 * Returns the description of a debug category.
846 * Returns: the description of the category.
849 gst_debug_category_get_description (GstDebugCategory *category)
851 return category->description;
854 * gst_debug_get_all_categories:
856 * Returns a snapshot of a all categories that are currently in use . This list
857 * may change anytime.
858 * The caller has to free the list after use.
859 * <emphasis>This function is not threadsafe, so only use it while only the
860 * main thread is running.</emphasis>
862 * Returns: the list of categories
865 gst_debug_get_all_categories (void)
869 g_static_mutex_lock (&__cat_mutex);
870 ret = g_slist_copy (__categories);
871 g_static_mutex_unlock (&__cat_mutex);
876 /*** FUNCTION POINTERS ********************************************************/
878 GHashTable *__gst_function_pointers = NULL;
879 const gchar *_gst_debug_nameof_funcptr (void *ptr) G_GNUC_NO_INSTRUMENT;
881 /* This function MUST NOT return NULL */
883 _gst_debug_nameof_funcptr (void *ptr)
890 if (__gst_function_pointers && (ptrname = g_hash_table_lookup(__gst_function_pointers,ptr))) {
893 /* we need to create an entry in the hash table for this one so we don't leak
896 if (dladdr(ptr,&dlinfo) && dlinfo.dli_sname) {
897 gchar *name = g_strdup (dlinfo.dli_sname);
898 _gst_debug_register_funcptr (ptr, name);
903 gchar *name = g_strdup_printf ("%p", ptr);
904 _gst_debug_register_funcptr (ptr, name);
910 _gst_debug_register_funcptr (void *ptr, gchar *ptrname)
912 if (!__gst_function_pointers)
913 __gst_function_pointers = g_hash_table_new (g_direct_hash, g_direct_equal);
914 if (!g_hash_table_lookup (__gst_function_pointers, ptr))
915 g_hash_table_insert (__gst_function_pointers, ptr, ptrname);
920 #endif /* GST_DISABLE_GST_DEBUG */
922 #ifdef GST_ENABLE_FUNC_INSTRUMENTATION
923 /* FIXME make this thread specific */
924 static GSList *stack_trace = NULL;
926 void __cyg_profile_func_enter(void *this_fn,void *call_site) G_GNUC_NO_INSTRUMENT;
927 void __cyg_profile_func_enter(void *this_fn,void *call_site)
929 gchar *name = _gst_debug_nameof_funcptr (this_fn);
930 gchar *site = _gst_debug_nameof_funcptr (call_site);
932 GST_CAT_DEBUG(GST_CAT_CALL_TRACE, "entering function %s from %s", name, site);
933 stack_trace = g_slist_prepend (stack_trace, g_strdup_printf ("%8p in %s from %p (%s)", this_fn, name, call_site, site));
939 void __cyg_profile_func_exit(void *this_fn,void *call_site) G_GNUC_NO_INSTRUMENT;
940 void __cyg_profile_func_exit(void *this_fn,void *call_site)
942 gchar *name = _gst_debug_nameof_funcptr (this_fn);
944 GST_CAT_DEBUG(GST_CAT_CALL_TRACE, "leaving function %s", name);
945 g_free (stack_trace->data);
946 stack_trace = g_slist_delete_link (stack_trace, stack_trace);
952 gst_debug_print_stack_trace (void)
954 GSList *walk = stack_trace;
958 walk = g_slist_next (walk);
961 gchar *name = (gchar *) walk->data;
963 g_print ("#%-2d %s\n", count++, name);
965 walk = g_slist_next (walk);
970 gst_debug_print_stack_trace (void)
972 /* nothing because it's compiled out */
975 #endif /* GST_ENABLE_FUNC_INTSTRUMENTATION */