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
34 #include "gst_private.h"
35 #include "gstelement.h"
37 #include "gstscheduler.h"
38 #include "gst_private.h"
40 GST_DEBUG_CATEGORY_STATIC(GST_CAT_DEBUG);
43 #include <rld_interface.h>
44 typedef struct DL_INFO {
45 const char * dli_fname;
47 const char * dli_sname;
53 #define _RLD_DLADDR 14
54 int dladdr(void *address, Dl_info *dl);
56 int dladdr(void *address, Dl_info *dl)
59 v = _rld_new_interface(_RLD_DLADDR,address,dl);
64 extern gchar *_gst_progname;
66 static void gst_debug_reset_threshold (gpointer category,
68 static void gst_debug_reset_all_thresholds (void);
70 /* list of all name/level pairs from --gst-debug and GST_DEBUG */
71 static GStaticMutex __level_name_mutex = G_STATIC_MUTEX_INIT;
72 static GSList *__level_name = NULL;
78 /* list of all categories */
79 static GStaticMutex __cat_mutex = G_STATIC_MUTEX_INIT;
80 static GSList *__categories = NULL;
82 /* all registered debug handlers */
87 static GStaticMutex __log_func_mutex = G_STATIC_MUTEX_INIT;
88 static GSList *__log_functions = NULL;
90 static GstAtomicInt __default_level;
91 static GstAtomicInt __use_color;
92 static GstAtomicInt __enabled;
95 GstDebugCategory *GST_CAT_DEFAULT = NULL;
97 GstDebugCategory *GST_CAT_GST_INIT = NULL;
98 GstDebugCategory *GST_CAT_COTHREADS = NULL;
99 GstDebugCategory *GST_CAT_COTHREAD_SWITCH = NULL;
100 GstDebugCategory *GST_CAT_AUTOPLUG = NULL;
101 GstDebugCategory *GST_CAT_AUTOPLUG_ATTEMPT = NULL;
102 GstDebugCategory *GST_CAT_PARENTAGE = NULL;
103 GstDebugCategory *GST_CAT_STATES = NULL;
104 GstDebugCategory *GST_CAT_PLANNING = NULL;
105 GstDebugCategory *GST_CAT_SCHEDULING = NULL;
106 GstDebugCategory *GST_CAT_DATAFLOW = NULL;
107 GstDebugCategory *GST_CAT_BUFFER = NULL;
108 GstDebugCategory *GST_CAT_CAPS = NULL;
109 GstDebugCategory *GST_CAT_CLOCK = NULL;
110 GstDebugCategory *GST_CAT_ELEMENT_PADS = NULL;
111 GstDebugCategory *GST_CAT_ELEMENT_FACTORY = NULL;
112 GstDebugCategory *GST_CAT_PADS = NULL;
113 GstDebugCategory *GST_CAT_PIPELINE = NULL;
114 GstDebugCategory *GST_CAT_PLUGIN_LOADING = NULL;
115 GstDebugCategory *GST_CAT_PLUGIN_INFO = NULL;
116 GstDebugCategory *GST_CAT_PROPERTIES = NULL;
117 GstDebugCategory *GST_CAT_THREAD = NULL;
118 GstDebugCategory *GST_CAT_TYPES = NULL;
119 GstDebugCategory *GST_CAT_XML = NULL;
120 GstDebugCategory *GST_CAT_NEGOTIATION = NULL;
121 GstDebugCategory *GST_CAT_REFCOUNTING = NULL;
122 GstDebugCategory *GST_CAT_EVENT = NULL;
123 GstDebugCategory *GST_CAT_PARAMS = NULL;
124 GstDebugCategory *GST_CAT_CALL_TRACE = NULL;
129 * Initializes the debugging system.
130 * Normally you don't want to call this, because gst_init does it for you.
132 void _gst_debug_init (void)
134 gst_atomic_int_init (&__default_level, GST_LEVEL_DEFAULT);
135 gst_atomic_int_init (&__use_color, 1);
136 gst_atomic_int_init (&__enabled, 1);
138 /* do NOT use a single debug function before this line has been run */
139 GST_CAT_DEFAULT = _gst_debug_category_new ("default",
142 GST_CAT_DEBUG = _gst_debug_category_new ("GST_DEBUG",
143 GST_DEBUG_BOLD | GST_DEBUG_FG_YELLOW,
144 "debugging subsystem");
146 gst_debug_add_log_function (gst_debug_log_default, NULL);
148 /* FIXME: add descriptions here */
149 GST_CAT_GST_INIT = _gst_debug_category_new ("GST_INIT",
150 GST_DEBUG_BOLD | GST_DEBUG_FG_RED,
152 GST_CAT_COTHREADS = _gst_debug_category_new ("GST_COTHREADS",
153 GST_DEBUG_BOLD | GST_DEBUG_FG_GREEN,
155 GST_CAT_COTHREAD_SWITCH = _gst_debug_category_new ("GST_COTHREAD_SWITCH",
156 GST_DEBUG_BOLD | GST_DEBUG_FG_WHITE | GST_DEBUG_BG_GREEN,
158 GST_CAT_AUTOPLUG = _gst_debug_category_new ("GST_AUTOPLUG",
159 GST_DEBUG_BOLD | GST_DEBUG_FG_BLUE,
161 GST_CAT_AUTOPLUG_ATTEMPT = _gst_debug_category_new ("GST_AUTOPLUG_ATTEMPT",
162 GST_DEBUG_BOLD | GST_DEBUG_FG_CYAN | GST_DEBUG_BG_BLUE,
164 GST_CAT_PARENTAGE = _gst_debug_category_new ("GST_PARENTAGE",
165 GST_DEBUG_BOLD | GST_DEBUG_FG_WHITE | GST_DEBUG_BG_RED,
167 GST_CAT_STATES = _gst_debug_category_new ("GST_STATES",
168 GST_DEBUG_BOLD | GST_DEBUG_FG_RED,
170 GST_CAT_PLANNING = _gst_debug_category_new ("GST_PLANNING",
171 GST_DEBUG_BOLD | GST_DEBUG_FG_MAGENTA,
173 GST_CAT_SCHEDULING = _gst_debug_category_new ("GST_SCHEDULING",
174 GST_DEBUG_BOLD | GST_DEBUG_FG_MAGENTA,
176 GST_CAT_DATAFLOW = _gst_debug_category_new ("GST_DATAFLOW",
177 GST_DEBUG_BOLD | GST_DEBUG_FG_GREEN,
179 GST_CAT_BUFFER = _gst_debug_category_new ("GST_BUFFER",
180 GST_DEBUG_BOLD | GST_DEBUG_FG_GREEN,
182 GST_CAT_CAPS = _gst_debug_category_new ("GST_CAPS",
183 GST_DEBUG_BOLD | GST_DEBUG_FG_BLUE,
185 GST_CAT_CLOCK = _gst_debug_category_new ("GST_CLOCK",
186 GST_DEBUG_BOLD | GST_DEBUG_FG_YELLOW,
188 GST_CAT_ELEMENT_PADS = _gst_debug_category_new ("GST_ELEMENT_PADS",
189 GST_DEBUG_BOLD | GST_DEBUG_FG_WHITE | GST_DEBUG_BG_RED,
191 GST_CAT_ELEMENT_FACTORY = _gst_debug_category_new ("GST_ELEMENT_FACTORY",
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",
235 /* we can't do this further above, because we initialize the GST_CAT_DEFAULT struct */
236 #define GST_CAT_DEFAULT GST_CAT_DEBUG
240 * @category: category to log
241 * @level: level of the message is in
242 * @file: the file that emitted the message, usually the __FILE__ identifier
243 * @function: the function that emitted the message
244 * @line: the line from that the message was emitted, usually __LINE__
245 * @object: the object this message relates to or NULL if none
246 * @format: a printf style format string
247 * @...: optional arguments for the format
249 * Logs the given message using the currently registered debugging handlers.
251 void gst_debug_log (GstDebugCategory *category, GstDebugLevel level,
252 const gchar *file, const gchar *function, gint line,
253 GObject *object, gchar *format, ...)
257 va_start (var_args, format);
258 gst_debug_logv (category, level, file, function, line, object, format, var_args);
263 * @category: category to log
264 * @level: level of the message is in
265 * @file: the file that emitted the message, usually the __FILE__ identifier
266 * @function: the function that emitted the message
267 * @line: the line from that the message was emitted, usually __LINE__
268 * @object: the object this message relates to or NULL if none
269 * @format: a printf style format string
270 * @args: optional arguments for the format
272 * Logs the given message using the currently registered debugging handlers.
274 void gst_debug_logv (GstDebugCategory *category, GstDebugLevel level,
275 const gchar *file, const gchar *function, gint line,
276 GObject *object, gchar *format, va_list args)
282 g_return_if_fail (category != NULL);
283 g_return_if_fail (file != NULL);
284 g_return_if_fail (function != NULL);
285 g_return_if_fail (format != NULL);
287 message = g_strdup_vprintf (format, args);
288 g_static_mutex_lock (&__log_func_mutex);
289 handler = __log_functions;
291 entry = handler->data;
292 handler = g_slist_next (handler);
293 entry->func (category, level, file, function, line, object, message, entry->user_data);
295 g_static_mutex_unlock (&__log_func_mutex);
299 * gst_debug_construct_term_color:
300 * @colorinfo: the color info
302 * Constructs a string that can be used for getting the desired color in color
304 * You need to free the string after use.
306 * Returns: a string containing the color definition
309 gst_debug_construct_term_color (guint colorinfo)
314 color = g_string_new ("\033[00");
316 if (colorinfo & GST_DEBUG_BOLD) {
317 g_string_append (color, ";01");
319 if (colorinfo & GST_DEBUG_UNDERLINE) {
320 g_string_append (color, ";04");
322 if (colorinfo & GST_DEBUG_FG_MASK) {
323 g_string_append_printf (color, ";3%1d", colorinfo & GST_DEBUG_FG_MASK);
325 if (colorinfo & GST_DEBUG_BG_MASK) {
326 g_string_append_printf (color, ";4%1d", (colorinfo & GST_DEBUG_BG_MASK) >> 4);
328 g_string_append (color, "m");
331 g_string_free (color, FALSE);
335 * gst_debug_log_default:
336 * @category: category to log
337 * @level: level of the message
338 * @file: the file that emitted the message, usually the __FILE__ identifier
339 * @function: the function that emitted the message
340 * @line: the line from that the message was emitted, usually __LINE__
341 * @message: the actual message
342 * @object: the object this message relates to or NULL if none
343 * @unused: an unused variable, reserved for some user_data.
345 * The default logging handler used by GStreamer. Logging functions get called
346 * whenever a macro like GST_DEBUG or similar is used. This function outputs the
347 * message and additional info using the glib error handler.
348 * You can add other handlers by using #gst_debug_add_log_function.
349 * And you can remove this handler by calling
350 * gst_debug_remove_log_function (gst_debug_log_default);
353 gst_debug_log_default (GstDebugCategory *category, GstDebugLevel level,
354 const gchar *file, const gchar *function, gint line,
355 GObject *object, gchar *message, gpointer unused)
363 if (level > gst_debug_category_get_threshold (category))
369 if (gst_debug_is_colored ()) {
370 color = gst_debug_construct_term_color (gst_debug_category_get_color (category));
372 pidcolor = g_strdup_printf ("\033[3%1dm", pid % 6 + 31);
374 color = g_strdup ("");
376 pidcolor = g_strdup ("");
378 /* nicely printed object */
379 if (object == NULL) {
381 } else if (GST_IS_PAD (object) && GST_OBJECT_NAME (object)) {
382 obj = g_strdup_printf (" [%s:%s]", GST_DEBUG_PAD_NAME (object));
383 } else if (GST_IS_OBJECT (object) && GST_OBJECT_NAME (object)) {
384 obj = g_strdup_printf (" [%s]", GST_OBJECT_NAME (object));
386 obj = g_strdup_printf (" [%s@%p]", G_OBJECT_TYPE_NAME(object), object);
389 g_printerr ("%s %s%15s%s(%s%5d%s) %s%s(%d):%s:%s%s %s\n",
390 gst_debug_level_get_name (level),
391 color, gst_debug_category_get_name (category), clear,
392 pidcolor, pid, clear,
393 color, file, line, function, obj, clear,
401 * gst_debug_level_get_name:
402 * @level: the level to get the name for
404 * Get the string trepresentation of a debugging level
409 gst_debug_level_get_name (GstDebugLevel level)
412 case GST_LEVEL_NONE: return "";
413 case GST_LEVEL_ERROR: return "ERROR";
414 case GST_LEVEL_WARNING: return "WARN ";
415 case GST_LEVEL_INFO: return "INFO ";
416 case GST_LEVEL_DEBUG: return "DEBUG";
417 case GST_LEVEL_LOG: return "LOG ";
419 g_warning ("invalid level specified for gst_debug_level_get_name");
424 * gst_debug_add_log_function:
425 * @func: the function to use
428 * Adds the logging function to the list of logging functions.
429 * Be sure to use G_GNUC_NO_INSTRUMENT on that function, it is needed.
432 gst_debug_add_log_function (GstLogFunction func, gpointer data)
436 g_return_if_fail (func != NULL);
438 entry = g_new (LogFuncEntry, 1);
440 entry->user_data = data;
441 g_static_mutex_lock (&__log_func_mutex);
442 __log_functions = g_slist_prepend (__log_functions, entry);
443 g_static_mutex_unlock (&__log_func_mutex);
445 GST_DEBUG ("prepended log function %p (user data %p) to log functions",
449 gst_debug_compare_log_function_by_func (gconstpointer entry, gconstpointer func)
451 gpointer entryfunc = ((LogFuncEntry *) entry)->func;
453 return (entryfunc < func) ? -1 : (entryfunc > func) ? 1 : 0;
456 gst_debug_compare_log_function_by_data (gconstpointer entry, gconstpointer data)
458 gpointer entrydata = ((LogFuncEntry *) entry)->user_data;
460 return (entrydata < data) ? -1 : (entrydata > data) ? 1 : 0;
463 * gst_debug_remove_log_function:
464 * @func: the log function to remove
466 * Removes all registrered instances of the given logging functions.
468 * Returns: How many instances of the function were removed
471 gst_debug_remove_log_function (GstLogFunction func)
476 g_return_val_if_fail (func != NULL, 0);
478 g_static_mutex_lock (&__log_func_mutex);
479 while ((found = g_slist_find_custom (__log_functions, func,
480 gst_debug_compare_log_function_by_func))) {
481 g_free (found->data);
482 __log_functions = g_slist_delete_link (__log_functions, found);
485 g_static_mutex_unlock (&__log_func_mutex);
486 GST_DEBUG ("removed log function %p %d times from log function list",
492 * gst_debug_remove_log_function_by_data:
493 * @data: user data of the log function to remove
495 * Removes all registrered instances of log functions with the given user data.
497 * Returns: How many instances of the function were removed
500 gst_debug_remove_log_function_by_data (gpointer data)
505 g_static_mutex_lock (&__log_func_mutex);
506 while ((found = g_slist_find_custom (__log_functions, data,
507 gst_debug_compare_log_function_by_data))) {
508 g_free (found->data);
509 __log_functions = g_slist_delete_link (__log_functions, found);
512 g_static_mutex_unlock (&__log_func_mutex);
513 GST_DEBUG ("removed %d log functions with user data %p from log function list",
519 * gst_debug_set_colored:
520 * @colored: Whether to use colored output or not
522 * Sets or unsets the use of coloured debugging output.
525 gst_debug_set_colored (gboolean colored)
527 gst_atomic_int_set (&__use_color, colored ? 1 : 0);
530 * gst_debug_is_colored:
532 * Checks if the debugging output should be colored.
534 * Returns: TRUE, if the debug output should be colored.
537 gst_debug_is_colored (void)
539 return gst_atomic_int_read (&__use_color) == 0 ? FALSE : TRUE;
542 * gst_debug_set_active:
543 * @active: Whether to use debugging output or not
545 * If activated, debugging messages are sent to the debugging
547 * It makes sense to deactivate it for speed issues.
550 gst_debug_set_active (gboolean active)
552 gst_atomic_int_set (&__enabled, active ? 1 : 0);
555 * gst_debug_is_active:
557 * Checks if debugging output is activated.
559 * Returns: TRUE, if debugging is activated
562 gst_debug_is_active (void)
564 return gst_atomic_int_read (&__enabled) == 0 ? FALSE : TRUE;
567 * gst_debug_set_default_threshold:
568 * @level: level to set
570 * Sets the default threshold to the given level and updates all categories to
571 * use this threshold.
574 gst_debug_set_default_threshold (GstDebugLevel level)
576 gst_atomic_int_set (&__default_level, level);
577 gst_debug_reset_all_thresholds ();
580 * gst_debug_get_default_threshold:
582 * Returns the default threshold that is used for new categories.
584 * Returns: the default threshold level
587 gst_debug_get_default_threshold (void)
589 return (GstDebugLevel) gst_atomic_int_read (&__default_level);
592 gst_debug_reset_threshold (gpointer category, gpointer unused)
594 GstDebugCategory *cat = (GstDebugCategory *) category;
597 g_static_mutex_lock (&__level_name_mutex);
600 LevelNameEntry *entry = walk->data;
601 walk = g_slist_next (walk);
602 if (g_pattern_match_string (entry->pat, cat->name)) {
603 GST_LOG ("category %s matches pattern %p - gets set to level %d",
604 cat->name, entry->pat, entry->level);
605 gst_debug_category_set_threshold (cat, entry->level);
609 gst_debug_category_set_threshold (cat, gst_debug_get_default_threshold ());
612 g_static_mutex_unlock (&__level_name_mutex);
615 gst_debug_reset_all_thresholds (void)
617 g_static_mutex_lock (&__cat_mutex);
618 g_slist_foreach (__categories, gst_debug_reset_threshold, NULL);
619 g_static_mutex_unlock (&__cat_mutex);
622 for_each_threshold_by_entry (gpointer data, gpointer user_data)
624 GstDebugCategory *cat = (GstDebugCategory *) data;
625 LevelNameEntry *entry = (LevelNameEntry *) user_data;
627 if (g_pattern_match_string (entry->pat, cat->name)) {
628 GST_LOG ("category %s matches pattern %p - gets set to level %d",
629 cat->name, entry->pat, entry->level);
630 gst_debug_category_set_threshold (cat, entry->level);
634 * gst_debug_set_threshold_for_name:
635 * @name: name of the categories to set
636 * @level: level to set them to
638 * Sets all categories which match the gven glob style pattern to the given
642 gst_debug_set_threshold_for_name (const gchar *name, GstDebugLevel level)
645 LevelNameEntry *entry;
647 g_return_if_fail (name != NULL);
649 pat = g_pattern_spec_new (name);
650 entry = g_new (LevelNameEntry, 1);
652 entry->level = level;
653 g_static_mutex_lock (&__level_name_mutex);
654 __level_name = g_slist_prepend (__level_name, entry);
655 g_static_mutex_unlock (&__level_name_mutex);
656 g_static_mutex_lock (&__cat_mutex);
657 g_slist_foreach (__categories, for_each_threshold_by_entry, entry);
658 g_static_mutex_unlock (&__cat_mutex);
661 * gst_debug_unset_threshold_for_name:
662 * @name: name of the categories to set
664 * Resets all categories with the given name back to the default level.
667 gst_debug_unset_threshold_for_name (const gchar *name)
672 g_return_if_fail (name != NULL);
674 pat = g_pattern_spec_new (name);
675 g_static_mutex_lock (&__level_name_mutex);
677 /* improve this if you want, it's mighty slow */
679 LevelNameEntry *entry = walk->data;
680 if (g_pattern_spec_equal (entry->pat, pat)) {
681 __level_name = g_slist_remove_link (__level_name, walk);
682 g_pattern_spec_free (entry->pat);
684 g_slist_free_1 (walk);
688 g_static_mutex_unlock (&__level_name_mutex);
689 g_pattern_spec_free (pat);
690 gst_debug_reset_all_thresholds ();
693 _gst_debug_category_new (gchar *name, guint color, gchar *description)
695 GstDebugCategory *cat;
697 g_return_val_if_fail (name != NULL, NULL);
699 cat = g_new (GstDebugCategory, 1);
700 cat->name = g_strdup (name);
702 if (description != NULL) {
703 cat->description = g_strdup (description);
705 cat->description = g_strdup ("no description");
707 cat->threshold = g_new (GstAtomicInt, 1);
708 gst_atomic_int_init (cat->threshold, 0);
709 gst_debug_reset_threshold (cat, NULL);
711 /* add to category list */
712 g_static_mutex_lock (&__cat_mutex);
713 __categories = g_slist_prepend (__categories, cat);
714 g_static_mutex_unlock (&__cat_mutex);
719 * gst_debug_category_free:
720 * @category: category to remove
722 * Removes and frees the category and all associated ressources.
725 gst_debug_category_free (GstDebugCategory *category)
727 if (category == NULL) return;
729 /* remove from category list */
730 g_static_mutex_lock (&__cat_mutex);
731 __categories = g_slist_remove (__categories, category);
732 g_static_mutex_unlock (&__cat_mutex);
734 g_free ((gpointer) category->name);
735 g_free ((gpointer) category->description);
736 gst_atomic_int_destroy (category->threshold);
737 g_free (category->threshold);
741 * gst_debug_category_set_threshold:
742 * @category: category to set threshold for
743 * @level: the threshold to set
745 * Sets the threshold of the category to the given level. Debug information will
746 * only be output if the threshold is lower or equal to the level of the
749 * Do not use this function in production code, because other functions may
750 * change the threshold of categories as side effect. It is however a nice
751 * function to use when debugging (even from gdb).
755 gst_debug_category_set_threshold (GstDebugCategory *category, GstDebugLevel level)
757 g_return_if_fail (category != NULL);
759 gst_atomic_int_set (category->threshold, level);
762 * gst_debug_category_reset_threshold:
763 * @category: category to set threshold for
765 * Resets the threshold of the category to the default level. Debug information
766 * will only be output if the threshold is lower or equal to the level of the
768 * Use this function to set the threshold back to where it was after using
769 * gst_debug_category_set_threshold().
772 gst_debug_category_reset_threshold (GstDebugCategory *category)
774 gst_debug_reset_threshold (category, NULL);
777 * gst_debug_category_get_threshold:
778 * @category: category to get threshold for
780 * Returns the threshold of a #GstCategory.
782 * Returns: the level that is used as threshold
785 gst_debug_category_get_threshold (GstDebugCategory *category)
787 return gst_atomic_int_read (category->threshold);
790 * gst_debug_category_get_name:
791 * @category: category to get name for
793 * Returns the name of a #GstCategory.
795 * Returns: the name of the category
798 gst_debug_category_get_name (GstDebugCategory *category)
800 return category->name;
803 * gst_debug_category_get_color:
804 * @category: category to get color for
806 * Returns the color of a #GstCategory to use when outputting this.
808 * Returns: the color of the category
811 gst_debug_category_get_color (GstDebugCategory *category)
813 return category->color;
816 * gst_debug_category_get_description:
817 * @category: category to get description for
819 * Returns the description of a #GstCategory
821 * Returns: the description of the category
824 gst_debug_category_get_description (GstDebugCategory *category)
826 return category->description;
829 * gst_debug_get_all_categories:
831 * Returns a snapshot of a all categories that are currently in use . This list
832 * may change anytime.
833 * The caller has to free the list after use.
834 * <emphasis>This function is not threadsafe, so only use it while only the
835 * main thread is running.</emphasis>
837 * Returns: the list of categories
840 gst_debug_get_all_categories (void)
844 g_static_mutex_lock (&__cat_mutex);
845 ret = g_slist_copy (__categories);
846 g_static_mutex_unlock (&__cat_mutex);
851 /*** FUNCTION POINTERS ********************************************************/
853 GHashTable *__gst_function_pointers = NULL;
854 gchar *_gst_debug_nameof_funcptr (void *ptr) G_GNUC_NO_INSTRUMENT;
856 /* This function MUST NOT return NULL */
858 _gst_debug_nameof_funcptr (void *ptr)
862 if (__gst_function_pointers && (ptrname = g_hash_table_lookup(__gst_function_pointers,ptr))) {
863 return g_strdup(ptrname);
864 } else if (dladdr(ptr,&dlinfo) && dlinfo.dli_sname) {
865 return g_strdup(dlinfo.dli_sname);
867 return g_strdup_printf("%p",ptr);
871 _gst_debug_register_funcptr (void *ptr, gchar *ptrname)
873 if (!__gst_function_pointers)
874 __gst_function_pointers = g_hash_table_new (g_direct_hash, g_direct_equal);
875 if (!g_hash_table_lookup (__gst_function_pointers, ptr))
876 g_hash_table_insert (__gst_function_pointers, ptr, ptrname);
881 #endif /* GST_DISABLE_GST_DEBUG */
883 #ifdef GST_ENABLE_FUNC_INSTRUMENTATION
884 /* FIXME make this thread specific */
885 static GSList *stack_trace = NULL;
887 void __cyg_profile_func_enter(void *this_fn,void *call_site) G_GNUC_NO_INSTRUMENT;
888 void __cyg_profile_func_enter(void *this_fn,void *call_site)
890 gchar *name = _gst_debug_nameof_funcptr (this_fn);
891 gchar *site = _gst_debug_nameof_funcptr (call_site);
893 GST_CAT_DEBUG(GST_CAT_CALL_TRACE, "entering function %s from %s", name, site);
894 stack_trace = g_slist_prepend (stack_trace, g_strdup_printf ("%8p in %s from %p (%s)", this_fn, name, call_site, site));
900 void __cyg_profile_func_exit(void *this_fn,void *call_site) G_GNUC_NO_INSTRUMENT;
901 void __cyg_profile_func_exit(void *this_fn,void *call_site)
903 gchar *name = _gst_debug_nameof_funcptr (this_fn);
905 GST_CAT_DEBUG(GST_CAT_CALL_TRACE, "leaving function %s", name);
906 g_free (stack_trace->data);
907 stack_trace = g_slist_delete_link (stack_trace, stack_trace);
913 gst_debug_print_stack_trace (void)
915 GSList *walk = stack_trace;
919 walk = g_slist_next (walk);
922 gchar *name = (gchar *) walk->data;
924 g_print ("#%-2d %s\n", count++, name);
926 walk = g_slist_next (walk);
931 gst_debug_print_stack_trace (void)
933 /* nothing because it's compiled out */
936 #endif /* GST_ENABLE_FUNC_INTSTRUMENTATION */