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.
26 * @short_description: Debugging and logging facilities
27 * @see_also: #GstConfig, #Gst for command line parameters
28 * and environment variables that affect the debugging output.
30 * GStreamer's debugging subsystem is an easy way to get information about what
31 * the application is doing. It is not meant for programming errors. Use GLib
32 * methods (g_warning and friends) for that.
34 * The debugging subsystem works only after GStreamer has been initialized
35 * - for example by calling gst_init().
37 * The debugging subsystem is used to log informational messages while the
38 * application runs. Each messages has some properties attached to it. Among
39 * these properties are the debugging category, the severity (called "level"
40 * here) and an optional #GObject it belongs to. Each of these messages is sent
41 * to all registered debugging handlers, which then handle the messages.
42 * GStreamer attaches a default handler on startup, which outputs requested
45 * Messages are output by using shortcut macros like #GST_DEBUG,
46 * #GST_CAT_ERROR_OBJECT or similar. These all expand to calling gst_debug_log()
47 * with the right parameters.
48 * The only thing a developer will probably want to do is define his own
49 * categories. This is easily done with 3 lines. At the top of your code,
51 * the variables and set the default category.
54 * GST_DEBUG_CATEGORY_STATIC (my_category); // define category (statically)
55 * &hash;define GST_CAT_DEFAULT my_category // set as default
58 * After that you only need to initialize the category.
61 * GST_DEBUG_CATEGORY_INIT (my_category, "my category",
62 * 0, "This is my very own");
65 * Initialization must be done before the category is used first.
67 * in their plugin_init function, libraries and applications should do that
68 * during their initialization.
70 * The whole debugging subsystem can be disabled at build time with passing the
71 * --disable-gst-debug switch to configure. If this is done, every function,
72 * macro and even structs described in this file evaluate to default values or
74 * So don't take addresses of these functions or use other tricks.
75 * If you must do that for some reason, there is still an option.
77 * subsystem was compiled out, #GST_DISABLE_GST_DEBUG is defined in
79 * so you can check that before doing your trick.
80 * Disabling the debugging subsystem will give you a slight (read: unnoticeable)
81 * speed increase and will reduce the size of your compiled code. The GStreamer
82 * library itself becomes around 10% smaller.
84 * Please note that there are naming conventions for the names of debugging
85 * categories. These are explained at GST_DEBUG_CATEGORY_INIT().
89 #include "gst_private.h"
92 #ifndef GST_DISABLE_GST_DEBUG
97 #ifdef HAVE_PRINTF_EXTENSION
100 #include <stdio.h> /* fprintf */
102 # include <unistd.h> /* getpid on UNIX */
104 #ifdef HAVE_PROCESS_H
105 # include <process.h> /* getpid on win32 */
107 #include <string.h> /* G_VA_COPY */
109 # define WIN32_LEAN_AND_MEAN /* prevents from including too many things */
110 # include <windows.h> /* GetStdHandle, windows console */
113 #include "gst_private.h"
114 #include "gstutils.h"
115 #include "gstsegment.h"
116 #ifdef HAVE_VALGRIND_H
117 # include <valgrind/valgrind.h>
119 #include <glib/gprintf.h> /* g_sprintf */
121 /* underscore is to prevent conflict with GST_CAT_DEBUG define */
122 GST_DEBUG_CATEGORY_STATIC (_GST_CAT_DEBUG);
124 /* time of initialization, so we get useful debugging output times
125 * FIXME: we use this in gstdebugutils.c, what about a function + macro to
126 * get the running time: GST_DEBUG_RUNNING_TIME
128 GstClockTime _priv_gst_info_start_time;
132 #include <rld_interface.h>
133 typedef struct DL_INFO
135 const char *dli_fname;
137 const char *dli_sname;
141 long dli_reserved[4];
145 #define _RLD_DLADDR 14
146 int dladdr (void *address, Dl_info * dl);
149 dladdr (void *address, Dl_info * dl)
153 v = _rld_new_interface (_RLD_DLADDR, address, dl);
159 static void gst_debug_reset_threshold (gpointer category, gpointer unused);
160 static void gst_debug_reset_all_thresholds (void);
162 #ifdef HAVE_PRINTF_EXTENSION
163 static int _gst_info_printf_extension_ptr (FILE * stream,
164 const struct printf_info *info, const void *const *args);
165 static int _gst_info_printf_extension_segment (FILE * stream,
166 const struct printf_info *info, const void *const *args);
167 #if HAVE_REGISTER_PRINTF_SPECIFIER
168 static int _gst_info_printf_extension_arginfo (const struct printf_info *info,
169 size_t n, int *argtypes, int *size);
171 static int _gst_info_printf_extension_arginfo (const struct printf_info *info,
172 size_t n, int *argtypes);
176 struct _GstDebugMessage
183 /* list of all name/level pairs from --gst-debug and GST_DEBUG */
184 static GStaticMutex __level_name_mutex = G_STATIC_MUTEX_INIT;
185 static GSList *__level_name = NULL;
193 /* list of all categories */
194 static GStaticMutex __cat_mutex = G_STATIC_MUTEX_INIT;
195 static GSList *__categories = NULL;
197 /* all registered debug handlers */
204 static GStaticMutex __log_func_mutex = G_STATIC_MUTEX_INIT;
205 static GSList *__log_functions = NULL;
207 static gint __default_level;
208 static gint __use_color;
210 /* disabled by default, as soon as some threshold is set > NONE,
211 * it becomes enabled. */
212 gboolean __gst_debug_enabled = FALSE;
213 GstDebugLevel __gst_debug_min = GST_LEVEL_NONE;
215 GstDebugCategory *GST_CAT_DEFAULT = NULL;
217 GstDebugCategory *GST_CAT_GST_INIT = NULL;
218 GstDebugCategory *GST_CAT_AUTOPLUG = NULL;
219 GstDebugCategory *GST_CAT_AUTOPLUG_ATTEMPT = NULL;
220 GstDebugCategory *GST_CAT_PARENTAGE = NULL;
221 GstDebugCategory *GST_CAT_STATES = NULL;
222 GstDebugCategory *GST_CAT_SCHEDULING = NULL;
224 GstDebugCategory *GST_CAT_BUFFER = NULL;
225 GstDebugCategory *GST_CAT_BUFFER_LIST = NULL;
226 GstDebugCategory *GST_CAT_BUS = NULL;
227 GstDebugCategory *GST_CAT_CAPS = NULL;
228 GstDebugCategory *GST_CAT_CLOCK = NULL;
229 GstDebugCategory *GST_CAT_ELEMENT_PADS = NULL;
230 GstDebugCategory *GST_CAT_PADS = NULL;
231 GstDebugCategory *GST_CAT_PIPELINE = NULL;
232 GstDebugCategory *GST_CAT_PLUGIN_LOADING = NULL;
233 GstDebugCategory *GST_CAT_PLUGIN_INFO = NULL;
234 GstDebugCategory *GST_CAT_PROPERTIES = NULL;
235 GstDebugCategory *GST_CAT_TYPES = NULL;
236 GstDebugCategory *GST_CAT_XML = NULL;
237 GstDebugCategory *GST_CAT_NEGOTIATION = NULL;
238 GstDebugCategory *GST_CAT_REFCOUNTING = NULL;
239 GstDebugCategory *GST_CAT_ERROR_SYSTEM = NULL;
240 GstDebugCategory *GST_CAT_EVENT = NULL;
241 GstDebugCategory *GST_CAT_MESSAGE = NULL;
242 GstDebugCategory *GST_CAT_PARAMS = NULL;
243 GstDebugCategory *GST_CAT_CALL_TRACE = NULL;
244 GstDebugCategory *GST_CAT_SIGNAL = NULL;
245 GstDebugCategory *GST_CAT_PROBE = NULL;
246 GstDebugCategory *GST_CAT_REGISTRY = NULL;
247 GstDebugCategory *GST_CAT_QOS = NULL;
249 /* FIXME: export this? */
251 _priv_gst_in_valgrind (void)
259 in_valgrind = GST_VG_UNCHECKED;
261 if (in_valgrind == GST_VG_UNCHECKED) {
262 #ifdef HAVE_VALGRIND_H
263 if (RUNNING_ON_VALGRIND) {
264 GST_CAT_INFO (GST_CAT_GST_INIT, "we're running inside valgrind");
265 printf ("GStreamer has detected that it is running inside valgrind.\n");
266 printf ("It might now take different code paths to ease debugging.\n");
267 printf ("Of course, this may also lead to different bugs.\n");
268 in_valgrind = GST_VG_INSIDE;
270 GST_CAT_LOG (GST_CAT_GST_INIT, "not doing extra valgrind stuff");
271 in_valgrind = GST_VG_NO_VALGRIND;
274 in_valgrind = GST_VG_NO_VALGRIND;
276 g_assert (in_valgrind == GST_VG_NO_VALGRIND ||
277 in_valgrind == GST_VG_INSIDE);
279 return (in_valgrind == GST_VG_INSIDE) ? TRUE : FALSE;
285 * Initializes the debugging system.
286 * Normally you don't want to call this, because gst_init() does it for you.
289 _gst_debug_init (void)
291 g_atomic_int_set (&__default_level, GST_LEVEL_DEFAULT);
292 g_atomic_int_set (&__use_color, 1);
294 /* get time we started for debugging messages */
295 _priv_gst_info_start_time = gst_util_get_timestamp ();
297 #ifdef HAVE_PRINTF_EXTENSION
298 #if HAVE_REGISTER_PRINTF_SPECIFIER
299 register_printf_specifier (GST_PTR_FORMAT[0], _gst_info_printf_extension_ptr,
300 _gst_info_printf_extension_arginfo);
301 register_printf_specifier (GST_SEGMENT_FORMAT[0],
302 _gst_info_printf_extension_segment, _gst_info_printf_extension_arginfo);
304 register_printf_function (GST_PTR_FORMAT[0], _gst_info_printf_extension_ptr,
305 _gst_info_printf_extension_arginfo);
306 register_printf_function (GST_SEGMENT_FORMAT[0],
307 _gst_info_printf_extension_segment, _gst_info_printf_extension_arginfo);
311 /* do NOT use a single debug function before this line has been run */
312 GST_CAT_DEFAULT = _gst_debug_category_new ("default",
313 GST_DEBUG_UNDERLINE, NULL);
314 _GST_CAT_DEBUG = _gst_debug_category_new ("GST_DEBUG",
315 GST_DEBUG_BOLD | GST_DEBUG_FG_YELLOW, "debugging subsystem");
317 gst_debug_add_log_function (gst_debug_log_default, NULL);
319 /* FIXME: add descriptions here */
320 GST_CAT_GST_INIT = _gst_debug_category_new ("GST_INIT",
321 GST_DEBUG_BOLD | GST_DEBUG_FG_RED, NULL);
322 GST_CAT_AUTOPLUG = _gst_debug_category_new ("GST_AUTOPLUG",
323 GST_DEBUG_BOLD | GST_DEBUG_FG_BLUE, NULL);
324 GST_CAT_AUTOPLUG_ATTEMPT = _gst_debug_category_new ("GST_AUTOPLUG_ATTEMPT",
325 GST_DEBUG_BOLD | GST_DEBUG_FG_CYAN | GST_DEBUG_BG_BLUE, NULL);
326 GST_CAT_PARENTAGE = _gst_debug_category_new ("GST_PARENTAGE",
327 GST_DEBUG_BOLD | GST_DEBUG_FG_WHITE | GST_DEBUG_BG_RED, NULL);
328 GST_CAT_STATES = _gst_debug_category_new ("GST_STATES",
329 GST_DEBUG_BOLD | GST_DEBUG_FG_RED, NULL);
330 GST_CAT_SCHEDULING = _gst_debug_category_new ("GST_SCHEDULING",
331 GST_DEBUG_BOLD | GST_DEBUG_FG_MAGENTA, NULL);
332 GST_CAT_BUFFER = _gst_debug_category_new ("GST_BUFFER",
333 GST_DEBUG_BOLD | GST_DEBUG_BG_GREEN, NULL);
334 GST_CAT_BUFFER_LIST = _gst_debug_category_new ("GST_BUFFER_LIST",
335 GST_DEBUG_BOLD | GST_DEBUG_BG_GREEN, NULL);
336 GST_CAT_BUS = _gst_debug_category_new ("GST_BUS", GST_DEBUG_BG_YELLOW, NULL);
337 GST_CAT_CAPS = _gst_debug_category_new ("GST_CAPS",
338 GST_DEBUG_BOLD | GST_DEBUG_FG_BLUE, NULL);
339 GST_CAT_CLOCK = _gst_debug_category_new ("GST_CLOCK",
340 GST_DEBUG_BOLD | GST_DEBUG_FG_YELLOW, NULL);
341 GST_CAT_ELEMENT_PADS = _gst_debug_category_new ("GST_ELEMENT_PADS",
342 GST_DEBUG_BOLD | GST_DEBUG_FG_WHITE | GST_DEBUG_BG_RED, NULL);
343 GST_CAT_PADS = _gst_debug_category_new ("GST_PADS",
344 GST_DEBUG_BOLD | GST_DEBUG_FG_WHITE | GST_DEBUG_BG_RED, NULL);
345 GST_CAT_PIPELINE = _gst_debug_category_new ("GST_PIPELINE",
346 GST_DEBUG_BOLD | GST_DEBUG_FG_WHITE | GST_DEBUG_BG_RED, NULL);
347 GST_CAT_PLUGIN_LOADING = _gst_debug_category_new ("GST_PLUGIN_LOADING",
348 GST_DEBUG_BOLD | GST_DEBUG_FG_CYAN, NULL);
349 GST_CAT_PLUGIN_INFO = _gst_debug_category_new ("GST_PLUGIN_INFO",
350 GST_DEBUG_BOLD | GST_DEBUG_FG_CYAN, NULL);
351 GST_CAT_PROPERTIES = _gst_debug_category_new ("GST_PROPERTIES",
352 GST_DEBUG_BOLD | GST_DEBUG_FG_WHITE | GST_DEBUG_BG_BLUE, NULL);
353 GST_CAT_TYPES = _gst_debug_category_new ("GST_TYPES",
354 GST_DEBUG_BOLD | GST_DEBUG_FG_WHITE | GST_DEBUG_BG_RED, NULL);
355 GST_CAT_XML = _gst_debug_category_new ("GST_XML",
356 GST_DEBUG_BOLD | GST_DEBUG_FG_WHITE | GST_DEBUG_BG_RED, NULL);
357 GST_CAT_NEGOTIATION = _gst_debug_category_new ("GST_NEGOTIATION",
358 GST_DEBUG_BOLD | GST_DEBUG_FG_BLUE, NULL);
359 GST_CAT_REFCOUNTING = _gst_debug_category_new ("GST_REFCOUNTING",
360 GST_DEBUG_BOLD | GST_DEBUG_FG_RED | GST_DEBUG_BG_BLUE, NULL);
361 GST_CAT_ERROR_SYSTEM = _gst_debug_category_new ("GST_ERROR_SYSTEM",
362 GST_DEBUG_BOLD | GST_DEBUG_FG_RED | GST_DEBUG_BG_WHITE, NULL);
364 GST_CAT_EVENT = _gst_debug_category_new ("GST_EVENT",
365 GST_DEBUG_BOLD | GST_DEBUG_FG_BLUE, NULL);
366 GST_CAT_MESSAGE = _gst_debug_category_new ("GST_MESSAGE",
367 GST_DEBUG_BOLD | GST_DEBUG_FG_WHITE | GST_DEBUG_BG_RED, NULL);
368 GST_CAT_PARAMS = _gst_debug_category_new ("GST_PARAMS",
369 GST_DEBUG_BOLD | GST_DEBUG_FG_BLACK | GST_DEBUG_BG_YELLOW, NULL);
370 GST_CAT_CALL_TRACE = _gst_debug_category_new ("GST_CALL_TRACE",
371 GST_DEBUG_BOLD, NULL);
372 GST_CAT_SIGNAL = _gst_debug_category_new ("GST_SIGNAL",
373 GST_DEBUG_BOLD | GST_DEBUG_FG_WHITE | GST_DEBUG_BG_RED, NULL);
374 GST_CAT_PROBE = _gst_debug_category_new ("GST_PROBE",
375 GST_DEBUG_BOLD | GST_DEBUG_FG_GREEN, "pad probes");
376 GST_CAT_REGISTRY = _gst_debug_category_new ("GST_REGISTRY", 0, "registry");
377 GST_CAT_QOS = _gst_debug_category_new ("GST_QOS", 0, "QoS");
380 /* print out the valgrind message if we're in valgrind */
381 _priv_gst_in_valgrind ();
384 /* we can't do this further above, because we initialize the GST_CAT_DEFAULT struct */
385 #define GST_CAT_DEFAULT _GST_CAT_DEBUG
389 * @category: category to log
390 * @level: level of the message is in
391 * @file: the file that emitted the message, usually the __FILE__ identifier
392 * @function: the function that emitted the message
393 * @line: the line from that the message was emitted, usually __LINE__
394 * @object: the object this message relates to or NULL if none
395 * @format: a printf style format string
396 * @...: optional arguments for the format
398 * Logs the given message using the currently registered debugging handlers.
401 gst_debug_log (GstDebugCategory * category, GstDebugLevel level,
402 const gchar * file, const gchar * function, gint line,
403 GObject * object, const gchar * format, ...)
407 va_start (var_args, format);
408 gst_debug_log_valist (category, level, file, function, line, object, format,
414 * gst_debug_log_valist:
415 * @category: category to log
416 * @level: level of the message is in
417 * @file: the file that emitted the message, usually the __FILE__ identifier
418 * @function: the function that emitted the message
419 * @line: the line from that the message was emitted, usually __LINE__
420 * @object: the object this message relates to or NULL if none
421 * @format: a printf style format string
422 * @args: optional arguments for the format
424 * Logs the given message using the currently registered debugging handlers.
427 gst_debug_log_valist (GstDebugCategory * category, GstDebugLevel level,
428 const gchar * file, const gchar * function, gint line,
429 GObject * object, const gchar * format, va_list args)
431 GstDebugMessage message;
436 gchar *file_basename;
439 g_return_if_fail (category != NULL);
440 g_return_if_fail (file != NULL);
441 g_return_if_fail (function != NULL);
442 g_return_if_fail (format != NULL);
446 * The predefined macro __FILE__ is always the exact path given to the
447 * compiler with MSVC, which may or may not be the basename. We work
448 * around it at runtime to improve the readability.
450 file = file_basename = g_path_get_basename (file);
453 message.message = NULL;
454 message.format = format;
455 G_VA_COPY (message.arguments, args);
457 handler = __log_functions;
459 entry = handler->data;
460 handler = g_slist_next (handler);
461 entry->func (category, level, file, function, line, object, &message,
464 g_free (message.message);
465 va_end (message.arguments);
468 g_free (file_basename);
473 * gst_debug_message_get:
474 * @message: a debug message
476 * Gets the string representation of a #GstDebugMessage. This function is used
477 * in debug handlers to extract the message.
479 * Returns: the string representation of a #GstDebugMessage.
482 gst_debug_message_get (GstDebugMessage * message)
484 if (message->message == NULL) {
485 message->message = g_strdup_vprintf (message->format, message->arguments);
487 return message->message;
492 gst_debug_print_object (gpointer ptr)
494 GObject *object = (GObject *) ptr;
497 /* This is a cute trick to detect unmapped memory, but is unportable,
498 * slow, screws around with madvise, and not actually that useful. */
502 ret = madvise ((void *) ((unsigned long) ptr & (~0xfff)), 4096, 0);
503 if (ret == -1 && errno == ENOMEM) {
504 buffer = g_strdup_printf ("%p (unmapped memory)", ptr);
509 /* nicely printed object */
510 if (object == NULL) {
511 return g_strdup ("(NULL)");
513 if (*(GType *) ptr == GST_TYPE_CAPS) {
514 return gst_caps_to_string ((GstCaps *) ptr);
516 if (*(GType *) ptr == GST_TYPE_STRUCTURE) {
517 return gst_structure_to_string ((GstStructure *) ptr);
520 if (*(guint32 *) ptr == 0xffffffff) {
521 return g_strdup_printf ("<poisoned@%p>", ptr);
524 if (GST_IS_PAD (object) && GST_OBJECT_NAME (object)) {
525 return g_strdup_printf ("<%s:%s>", GST_DEBUG_PAD_NAME (object));
527 if (GST_IS_OBJECT (object) && GST_OBJECT_NAME (object)) {
528 return g_strdup_printf ("<%s>", GST_OBJECT_NAME (object));
530 if (G_IS_OBJECT (object)) {
531 return g_strdup_printf ("<%s@%p>", G_OBJECT_TYPE_NAME (object), object);
533 if (GST_IS_MESSAGE (object)) {
534 GstMessage *msg = GST_MESSAGE_CAST (object);
537 if (msg->structure) {
538 s = gst_structure_to_string (msg->structure);
540 s = g_strdup ("(NULL)");
543 ret = g_strdup_printf ("%s message from element '%s': %s",
544 GST_MESSAGE_TYPE_NAME (msg), (msg->src != NULL) ?
545 GST_ELEMENT_NAME (msg->src) : "(NULL)", s);
549 if (GST_IS_QUERY (object)) {
550 GstQuery *query = GST_QUERY_CAST (object);
552 if (query->structure) {
553 return gst_structure_to_string (query->structure);
555 const gchar *query_type_name;
557 query_type_name = gst_query_type_get_name (query->type);
558 if (G_LIKELY (query_type_name != NULL)) {
559 return g_strdup_printf ("%s query", query_type_name);
561 return g_strdup_printf ("query of unknown type %d", query->type);
566 return g_strdup_printf ("%p", ptr);
569 #ifdef HAVE_PRINTF_EXTENSION
572 gst_debug_print_segment (gpointer ptr)
574 GstSegment *segment = (GstSegment *) ptr;
576 /* nicely printed segment */
577 if (segment == NULL) {
578 return g_strdup ("(NULL)");
581 switch (segment->format) {
582 case GST_FORMAT_UNDEFINED:{
583 return g_strdup_printf ("UNDEFINED segment");
585 case GST_FORMAT_TIME:{
586 return g_strdup_printf ("time segment start=%" GST_TIME_FORMAT
587 ", stop=%" GST_TIME_FORMAT ", last_stop=%" GST_TIME_FORMAT
588 ", duration=%" GST_TIME_FORMAT ", rate=%f, applied_rate=%f"
589 ", flags=0x%02x, time=%" GST_TIME_FORMAT ", accum=%" GST_TIME_FORMAT,
590 GST_TIME_ARGS (segment->start), GST_TIME_ARGS (segment->stop),
591 GST_TIME_ARGS (segment->last_stop), GST_TIME_ARGS (segment->duration),
592 segment->rate, segment->applied_rate, (guint) segment->flags,
593 GST_TIME_ARGS (segment->time), GST_TIME_ARGS (segment->accum));
596 const gchar *format_name;
598 format_name = gst_format_get_name (segment->format);
599 if (G_UNLIKELY (format_name == NULL))
600 format_name = "(UNKNOWN FORMAT)";
601 return g_strdup_printf ("%s segment start=%" G_GINT64_FORMAT
602 ", stop=%" G_GINT64_FORMAT ", last_stop=%" G_GINT64_FORMAT
603 ", duration=%" G_GINT64_FORMAT ", rate=%f, applied_rate=%f"
604 ", flags=0x%02x, time=%" GST_TIME_FORMAT ", accum=%" GST_TIME_FORMAT,
605 format_name, segment->start, segment->stop, segment->last_stop,
606 segment->duration, segment->rate, segment->applied_rate,
607 (guint) segment->flags, GST_TIME_ARGS (segment->time),
608 GST_TIME_ARGS (segment->accum));
613 #endif /* HAVE_PRINTF_EXTENSION */
616 * gst_debug_construct_term_color:
617 * @colorinfo: the color info
619 * Constructs a string that can be used for getting the desired color in color
621 * You need to free the string after use.
623 * Returns: a string containing the color definition
626 gst_debug_construct_term_color (guint colorinfo)
630 color = g_string_new ("\033[00");
632 if (colorinfo & GST_DEBUG_BOLD) {
633 g_string_append_len (color, ";01", 3);
635 if (colorinfo & GST_DEBUG_UNDERLINE) {
636 g_string_append_len (color, ";04", 3);
638 if (colorinfo & GST_DEBUG_FG_MASK) {
639 g_string_append_printf (color, ";3%1d", colorinfo & GST_DEBUG_FG_MASK);
641 if (colorinfo & GST_DEBUG_BG_MASK) {
642 g_string_append_printf (color, ";4%1d",
643 (colorinfo & GST_DEBUG_BG_MASK) >> 4);
645 g_string_append_c (color, 'm');
647 return g_string_free (color, FALSE);
651 * gst_debug_construct_win_color:
652 * @colorinfo: the color info
654 * Constructs an integer that can be used for getting the desired color in
655 * windows' terminals (cmd.exe). As there is no mean to underline, we simply
656 * ignore this attribute.
658 * This function returns 0 on non-windows machines.
660 * Returns: an integer containing the color definition
665 gst_debug_construct_win_color (guint colorinfo)
669 static const guchar ansi_to_win_fg[8] = {
671 FOREGROUND_RED, /* red */
672 FOREGROUND_GREEN, /* green */
673 FOREGROUND_RED | FOREGROUND_GREEN, /* yellow */
674 FOREGROUND_BLUE, /* blue */
675 FOREGROUND_RED | FOREGROUND_BLUE, /* magenta */
676 FOREGROUND_GREEN | FOREGROUND_BLUE, /* cyan */
677 FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE /* white */
679 static const guchar ansi_to_win_bg[8] = {
683 BACKGROUND_RED | BACKGROUND_GREEN,
685 BACKGROUND_RED | BACKGROUND_BLUE,
686 BACKGROUND_GREEN | FOREGROUND_BLUE,
687 BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE
690 /* we draw black as white, as cmd.exe can only have black bg */
691 if (colorinfo == 0) {
692 return ansi_to_win_fg[7];
695 if (colorinfo & GST_DEBUG_BOLD) {
696 color |= FOREGROUND_INTENSITY;
698 if (colorinfo & GST_DEBUG_FG_MASK) {
699 color |= ansi_to_win_fg[colorinfo & GST_DEBUG_FG_MASK];
701 if (colorinfo & GST_DEBUG_BG_MASK) {
702 color |= ansi_to_win_bg[(colorinfo & GST_DEBUG_BG_MASK) >> 4];
708 /* width of %p varies depending on actual value of pointer, which can make
709 * output unevenly aligned if multiple threads are involved, hence the %14p
710 * (should really be %18p, but %14p seems a good compromise between too many
711 * white spaces and likely unalignment on my system) */
712 #if defined (GLIB_SIZEOF_VOID_P) && GLIB_SIZEOF_VOID_P == 8
713 #define PTR_FMT "%14p"
715 #define PTR_FMT "%10p"
717 #define PID_FMT "%5d"
718 #define CAT_FMT "%20s %s:%d:%s:%s"
721 static const guchar levelcolormap[GST_LEVEL_COUNT] = {
723 FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE,
724 /* GST_LEVEL_ERROR */
725 FOREGROUND_RED | FOREGROUND_INTENSITY,
726 /* GST_LEVEL_WARNING */
727 FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY,
729 FOREGROUND_GREEN | FOREGROUND_INTENSITY,
730 /* GST_LEVEL_DEBUG */
731 FOREGROUND_GREEN | FOREGROUND_BLUE,
733 FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE,
734 /* GST_LEVEL_FIXME */
735 FOREGROUND_RED | FOREGROUND_GREEN,
736 /* placeholder for log level 7 */
738 /* placeholder for log level 8 */
740 /* GST_LEVEL_MEMDUMP */
741 FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE
744 static const guchar available_colors[] = {
745 FOREGROUND_RED, FOREGROUND_GREEN, FOREGROUND_RED | FOREGROUND_GREEN,
746 FOREGROUND_BLUE, FOREGROUND_RED | FOREGROUND_BLUE,
747 FOREGROUND_GREEN | FOREGROUND_BLUE,
750 static const gchar *levelcolormap[GST_LEVEL_COUNT] = {
751 "\033[37m", /* GST_LEVEL_NONE */
752 "\033[31;01m", /* GST_LEVEL_ERROR */
753 "\033[33;01m", /* GST_LEVEL_WARNING */
754 "\033[32;01m", /* GST_LEVEL_INFO */
755 "\033[36m", /* GST_LEVEL_DEBUG */
756 "\033[37m", /* GST_LEVEL_LOG */
757 "\033[33;01m", /* GST_LEVEL_FIXME */
758 "\033[37m", /* placeholder for log level 7 */
759 "\033[37m", /* placeholder for log level 8 */
760 "\033[37m" /* GST_LEVEL_MEMDUMP */
765 * gst_debug_log_default:
766 * @category: category to log
767 * @level: level of the message
768 * @file: the file that emitted the message, usually the __FILE__ identifier
769 * @function: the function that emitted the message
770 * @line: the line from that the message was emitted, usually __LINE__
771 * @message: the actual message
772 * @object: the object this message relates to or NULL if none
773 * @unused: an unused variable, reserved for some user_data.
775 * The default logging handler used by GStreamer. Logging functions get called
776 * whenever a macro like GST_DEBUG or similar is used. This function outputs the
777 * message and additional info using the glib error handler.
778 * You can add other handlers by using gst_debug_add_log_function().
779 * And you can remove this handler by calling
780 * gst_debug_remove_log_function(gst_debug_log_default);
783 gst_debug_log_default (GstDebugCategory * category, GstDebugLevel level,
784 const gchar * file, const gchar * function, gint line,
785 GObject * object, GstDebugMessage * message, gpointer unused)
788 GstClockTime elapsed;
790 gboolean free_obj = TRUE;
793 if (level > gst_debug_category_get_threshold (category))
797 is_colored = gst_debug_is_colored ();
799 elapsed = GST_CLOCK_DIFF (_priv_gst_info_start_time,
800 gst_util_get_timestamp ());
803 obj = gst_debug_print_object (object);
811 /* colors, non-windows */
815 const gchar *levelcolor;
817 color = gst_debug_construct_term_color (gst_debug_category_get_color
820 g_sprintf (pidcolor, "\033[3%1dm", pid % 6 + 31);
821 levelcolor = levelcolormap[level];
823 #define PRINT_FMT " %s"PID_FMT"%s "PTR_FMT" %s%s%s %s"CAT_FMT"%s %s\n"
824 g_printerr ("%" GST_TIME_FORMAT PRINT_FMT, GST_TIME_ARGS (elapsed),
825 pidcolor, pid, clear, g_thread_self (), levelcolor,
826 gst_debug_level_get_name (level), clear, color,
827 gst_debug_category_get_name (category), file, line, function, obj,
828 clear, gst_debug_message_get (message));
832 /* colors, windows. We take a lock to keep colors and content together.
833 * Maybe there is a better way but for now this will do the right
835 static GStaticMutex win_print_mutex = G_STATIC_MUTEX_INIT;
836 const gint clear = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE;
837 #define SET_COLOR(c) \
838 SetConsoleTextAttribute (GetStdHandle (STD_ERROR_HANDLE), (c));
839 g_static_mutex_lock (&win_print_mutex);
841 g_printerr ("%" GST_TIME_FORMAT " ", GST_TIME_ARGS (elapsed));
843 SET_COLOR (available_colors[pid % G_N_ELEMENTS (available_colors)]);
844 g_printerr (PID_FMT, pid);
847 g_printerr (" " PTR_FMT " ", g_thread_self ());
849 SET_COLOR (levelcolormap[level]);
850 g_printerr ("%s ", gst_debug_level_get_name (level));
852 SET_COLOR (gst_debug_construct_win_color (gst_debug_category_get_color
854 g_printerr (CAT_FMT, gst_debug_category_get_name (category),
855 file, line, function, obj);
858 g_printerr (" %s\n", gst_debug_message_get (message));
859 g_static_mutex_unlock (&win_print_mutex);
862 /* no color, all platforms */
863 #define PRINT_FMT " "PID_FMT" "PTR_FMT" %s "CAT_FMT" %s\n"
864 g_printerr ("%" GST_TIME_FORMAT PRINT_FMT, GST_TIME_ARGS (elapsed), pid,
865 g_thread_self (), gst_debug_level_get_name (level),
866 gst_debug_category_get_name (category), file, line, function, obj,
867 gst_debug_message_get (message));
876 * gst_debug_level_get_name:
877 * @level: the level to get the name for
879 * Get the string representation of a debugging level
884 gst_debug_level_get_name (GstDebugLevel level)
889 case GST_LEVEL_ERROR:
891 case GST_LEVEL_WARNING:
895 case GST_LEVEL_DEBUG:
899 case GST_LEVEL_FIXME:
901 case GST_LEVEL_MEMDUMP:
904 g_warning ("invalid level specified for gst_debug_level_get_name");
910 * gst_debug_add_log_function:
911 * @func: the function to use
914 * Adds the logging function to the list of logging functions.
915 * Be sure to use G_GNUC_NO_INSTRUMENT on that function, it is needed.
918 gst_debug_add_log_function (GstLogFunction func, gpointer data)
923 g_return_if_fail (func != NULL);
925 entry = g_new (LogFuncEntry, 1);
927 entry->user_data = data;
928 /* FIXME: we leak the old list here - other threads might access it right now
929 * in gst_debug_logv. Another solution is to lock the mutex in gst_debug_logv,
930 * but that is waaay costly.
931 * It'd probably be clever to use some kind of RCU here, but I don't know
932 * anything about that.
934 g_static_mutex_lock (&__log_func_mutex);
935 list = g_slist_copy (__log_functions);
936 __log_functions = g_slist_prepend (list, entry);
937 g_static_mutex_unlock (&__log_func_mutex);
939 GST_DEBUG ("prepended log function %p (user data %p) to log functions",
944 gst_debug_compare_log_function_by_func (gconstpointer entry, gconstpointer func)
946 gpointer entryfunc = (gpointer) (((LogFuncEntry *) entry)->func);
948 return (entryfunc < func) ? -1 : (entryfunc > func) ? 1 : 0;
952 gst_debug_compare_log_function_by_data (gconstpointer entry, gconstpointer data)
954 gpointer entrydata = ((LogFuncEntry *) entry)->user_data;
956 return (entrydata < data) ? -1 : (entrydata > data) ? 1 : 0;
960 gst_debug_remove_with_compare_func (GCompareFunc func, gpointer data)
966 g_static_mutex_lock (&__log_func_mutex);
967 new = __log_functions;
968 while ((found = g_slist_find_custom (new, data, func))) {
969 if (new == __log_functions) {
970 /* make a copy when we have the first hit, so that we modify the copy and
971 * make that the new list later */
972 new = g_slist_copy (new);
975 g_free (found->data);
976 new = g_slist_delete_link (new, found);
979 /* FIXME: We leak the old list here. See _add_log_function for why. */
980 __log_functions = new;
981 g_static_mutex_unlock (&__log_func_mutex);
987 * gst_debug_remove_log_function:
988 * @func: the log function to remove
990 * Removes all registered instances of the given logging functions.
992 * Returns: How many instances of the function were removed
995 gst_debug_remove_log_function (GstLogFunction func)
999 g_return_val_if_fail (func != NULL, 0);
1002 gst_debug_remove_with_compare_func
1003 (gst_debug_compare_log_function_by_func, (gpointer) func);
1004 GST_DEBUG ("removed log function %p %d times from log function list", func,
1011 * gst_debug_remove_log_function_by_data:
1012 * @data: user data of the log function to remove
1014 * Removes all registered instances of log functions with the given user data.
1016 * Returns: How many instances of the function were removed
1019 gst_debug_remove_log_function_by_data (gpointer data)
1024 gst_debug_remove_with_compare_func
1025 (gst_debug_compare_log_function_by_data, data);
1027 ("removed %d log functions with user data %p from log function list",
1034 * gst_debug_set_colored:
1035 * @colored: Whether to use colored output or not
1037 * Sets or unsets the use of coloured debugging output.
1040 gst_debug_set_colored (gboolean colored)
1042 g_atomic_int_set (&__use_color, colored ? 1 : 0);
1046 * gst_debug_is_colored:
1048 * Checks if the debugging output should be colored.
1050 * Returns: TRUE, if the debug output should be colored.
1053 gst_debug_is_colored (void)
1055 return g_atomic_int_get (&__use_color) == 0 ? FALSE : TRUE;
1059 * gst_debug_set_active:
1060 * @active: Whether to use debugging output or not
1062 * If activated, debugging messages are sent to the debugging
1064 * It makes sense to deactivate it for speed issues.
1065 * <note><para>This function is not threadsafe. It makes sense to only call it
1066 * during initialization.</para></note>
1069 gst_debug_set_active (gboolean active)
1071 __gst_debug_enabled = active;
1073 __gst_debug_min = GST_LEVEL_COUNT;
1075 __gst_debug_min = GST_LEVEL_NONE;
1079 * gst_debug_is_active:
1081 * Checks if debugging output is activated.
1083 * Returns: TRUE, if debugging is activated
1086 gst_debug_is_active (void)
1088 return __gst_debug_enabled;
1092 * gst_debug_set_default_threshold:
1093 * @level: level to set
1095 * Sets the default threshold to the given level and updates all categories to
1096 * use this threshold.
1099 gst_debug_set_default_threshold (GstDebugLevel level)
1101 g_atomic_int_set (&__default_level, level);
1102 gst_debug_reset_all_thresholds ();
1106 * gst_debug_get_default_threshold:
1108 * Returns the default threshold that is used for new categories.
1110 * Returns: the default threshold level
1113 gst_debug_get_default_threshold (void)
1115 return (GstDebugLevel) g_atomic_int_get (&__default_level);
1119 gst_debug_reset_threshold (gpointer category, gpointer unused)
1121 GstDebugCategory *cat = (GstDebugCategory *) category;
1124 g_static_mutex_lock (&__level_name_mutex);
1125 walk = __level_name;
1127 LevelNameEntry *entry = walk->data;
1129 walk = g_slist_next (walk);
1130 if (g_pattern_match_string (entry->pat, cat->name)) {
1131 GST_LOG ("category %s matches pattern %p - gets set to level %d",
1132 cat->name, entry->pat, entry->level);
1133 gst_debug_category_set_threshold (cat, entry->level);
1137 gst_debug_category_set_threshold (cat, gst_debug_get_default_threshold ());
1140 g_static_mutex_unlock (&__level_name_mutex);
1144 gst_debug_reset_all_thresholds (void)
1146 g_static_mutex_lock (&__cat_mutex);
1147 g_slist_foreach (__categories, gst_debug_reset_threshold, NULL);
1148 g_static_mutex_unlock (&__cat_mutex);
1152 for_each_threshold_by_entry (gpointer data, gpointer user_data)
1154 GstDebugCategory *cat = (GstDebugCategory *) data;
1155 LevelNameEntry *entry = (LevelNameEntry *) user_data;
1157 if (g_pattern_match_string (entry->pat, cat->name)) {
1158 GST_LOG ("category %s matches pattern %p - gets set to level %d",
1159 cat->name, entry->pat, entry->level);
1160 gst_debug_category_set_threshold (cat, entry->level);
1165 * gst_debug_set_threshold_for_name:
1166 * @name: name of the categories to set
1167 * @level: level to set them to
1169 * Sets all categories which match the given glob style pattern to the given
1173 gst_debug_set_threshold_for_name (const gchar * name, GstDebugLevel level)
1176 LevelNameEntry *entry;
1178 g_return_if_fail (name != NULL);
1180 pat = g_pattern_spec_new (name);
1181 entry = g_new (LevelNameEntry, 1);
1183 entry->level = level;
1184 g_static_mutex_lock (&__level_name_mutex);
1185 __level_name = g_slist_prepend (__level_name, entry);
1186 g_static_mutex_unlock (&__level_name_mutex);
1187 g_static_mutex_lock (&__cat_mutex);
1188 g_slist_foreach (__categories, for_each_threshold_by_entry, entry);
1189 g_static_mutex_unlock (&__cat_mutex);
1193 * gst_debug_unset_threshold_for_name:
1194 * @name: name of the categories to set
1196 * Resets all categories with the given name back to the default level.
1199 gst_debug_unset_threshold_for_name (const gchar * name)
1204 g_return_if_fail (name != NULL);
1206 pat = g_pattern_spec_new (name);
1207 g_static_mutex_lock (&__level_name_mutex);
1208 walk = __level_name;
1209 /* improve this if you want, it's mighty slow */
1211 LevelNameEntry *entry = walk->data;
1213 if (g_pattern_spec_equal (entry->pat, pat)) {
1214 __level_name = g_slist_remove_link (__level_name, walk);
1215 g_pattern_spec_free (entry->pat);
1217 g_slist_free_1 (walk);
1218 walk = __level_name;
1221 g_static_mutex_unlock (&__level_name_mutex);
1222 g_pattern_spec_free (pat);
1223 gst_debug_reset_all_thresholds ();
1227 _gst_debug_category_new (const gchar * name, guint color,
1228 const gchar * description)
1230 GstDebugCategory *cat;
1232 g_return_val_if_fail (name != NULL, NULL);
1234 cat = g_new (GstDebugCategory, 1);
1235 cat->name = g_strdup (name);
1237 if (description != NULL) {
1238 cat->description = g_strdup (description);
1240 cat->description = g_strdup ("no description");
1242 g_atomic_int_set (&cat->threshold, 0);
1243 gst_debug_reset_threshold (cat, NULL);
1245 /* add to category list */
1246 g_static_mutex_lock (&__cat_mutex);
1247 __categories = g_slist_prepend (__categories, cat);
1248 g_static_mutex_unlock (&__cat_mutex);
1254 * gst_debug_category_free:
1255 * @category: #GstDebugCategory to free.
1257 * Removes and frees the category and all associated resources.
1260 gst_debug_category_free (GstDebugCategory * category)
1262 if (category == NULL)
1265 /* remove from category list */
1266 g_static_mutex_lock (&__cat_mutex);
1267 __categories = g_slist_remove (__categories, category);
1268 g_static_mutex_unlock (&__cat_mutex);
1270 g_free ((gpointer) category->name);
1271 g_free ((gpointer) category->description);
1276 * gst_debug_category_set_threshold:
1277 * @category: a #GstDebugCategory to set threshold of.
1278 * @level: the #GstDebugLevel threshold to set.
1280 * Sets the threshold of the category to the given level. Debug information will
1281 * only be output if the threshold is lower or equal to the level of the
1282 * debugging message.
1284 * Do not use this function in production code, because other functions may
1285 * change the threshold of categories as side effect. It is however a nice
1286 * function to use when debugging (even from gdb).
1290 gst_debug_category_set_threshold (GstDebugCategory * category,
1291 GstDebugLevel level)
1293 g_return_if_fail (category != NULL);
1295 if (level > __gst_debug_min) {
1296 __gst_debug_enabled = TRUE;
1297 __gst_debug_min = level;
1300 g_atomic_int_set (&category->threshold, level);
1304 * gst_debug_category_reset_threshold:
1305 * @category: a #GstDebugCategory to reset threshold of.
1307 * Resets the threshold of the category to the default level. Debug information
1308 * will only be output if the threshold is lower or equal to the level of the
1309 * debugging message.
1310 * Use this function to set the threshold back to where it was after using
1311 * gst_debug_category_set_threshold().
1314 gst_debug_category_reset_threshold (GstDebugCategory * category)
1316 gst_debug_reset_threshold (category, NULL);
1320 * gst_debug_category_get_threshold:
1321 * @category: a #GstDebugCategory to get threshold of.
1323 * Returns the threshold of a #GstDebugCategory.
1325 * Returns: the #GstDebugLevel that is used as threshold.
1328 gst_debug_category_get_threshold (GstDebugCategory * category)
1330 return g_atomic_int_get (&category->threshold);
1334 * gst_debug_category_get_name:
1335 * @category: a #GstDebugCategory to get name of.
1337 * Returns the name of a debug category.
1339 * Returns: the name of the category.
1342 gst_debug_category_get_name (GstDebugCategory * category)
1344 return category->name;
1348 * gst_debug_category_get_color:
1349 * @category: a #GstDebugCategory to get the color of.
1351 * Returns the color of a debug category used when printing output in this
1354 * Returns: the color of the category.
1357 gst_debug_category_get_color (GstDebugCategory * category)
1359 return category->color;
1363 * gst_debug_category_get_description:
1364 * @category: a #GstDebugCategory to get the description of.
1366 * Returns the description of a debug category.
1368 * Returns: the description of the category.
1371 gst_debug_category_get_description (GstDebugCategory * category)
1373 return category->description;
1377 * gst_debug_get_all_categories:
1379 * Returns a snapshot of a all categories that are currently in use . This list
1380 * may change anytime.
1381 * The caller has to free the list after use.
1383 * Returns: the list of categories
1386 gst_debug_get_all_categories (void)
1390 g_static_mutex_lock (&__cat_mutex);
1391 ret = g_slist_copy (__categories);
1392 g_static_mutex_unlock (&__cat_mutex);
1397 /*** FUNCTION POINTERS ********************************************************/
1399 static GHashTable *__gst_function_pointers; /* NULL */
1400 static GStaticMutex __dbg_functions_mutex = G_STATIC_MUTEX_INIT;
1403 _gst_debug_nameof_funcptr (GstDebugFuncPtr ptr)
1404 G_GNUC_NO_INSTRUMENT;
1406 /* This function MUST NOT return NULL */
1407 const gchar *_gst_debug_nameof_funcptr (GstDebugFuncPtr func)
1415 if (G_UNLIKELY (func == NULL))
1418 g_static_mutex_lock (&__dbg_functions_mutex);
1419 if (G_LIKELY (__gst_function_pointers)) {
1420 ptrname = g_hash_table_lookup (__gst_function_pointers, (gpointer) func);
1421 g_static_mutex_unlock (&__dbg_functions_mutex);
1422 if (G_LIKELY (ptrname))
1425 g_static_mutex_unlock (&__dbg_functions_mutex);
1427 /* we need to create an entry in the hash table for this one so we don't leak
1430 if (dladdr ((gpointer) func, &dl_info) && dl_info.dli_sname) {
1431 gchar *name = g_strdup (dl_info.dli_sname);
1433 _gst_debug_register_funcptr (func, name);
1438 gchar *name = g_strdup_printf ("%p", (gpointer) func);
1440 _gst_debug_register_funcptr (func, name);
1446 _gst_debug_register_funcptr (GstDebugFuncPtr func, const gchar * ptrname)
1448 gpointer ptr = (gpointer) func;
1450 g_static_mutex_lock (&__dbg_functions_mutex);
1452 if (!__gst_function_pointers)
1453 __gst_function_pointers = g_hash_table_new (g_direct_hash, g_direct_equal);
1454 if (!g_hash_table_lookup (__gst_function_pointers, ptr))
1455 g_hash_table_insert (__gst_function_pointers, ptr, (gpointer) ptrname);
1457 g_static_mutex_unlock (&__dbg_functions_mutex);
1460 /*** PRINTF EXTENSIONS ********************************************************/
1462 #ifdef HAVE_PRINTF_EXTENSION
1464 _gst_info_printf_extension_ptr (FILE * stream, const struct printf_info *info,
1465 const void *const *args)
1472 ptr = *(void **) args[0];
1474 buffer = gst_debug_print_object (ptr);
1475 len = fprintf (stream, "%*s", (info->left ? -info->width : info->width),
1483 _gst_info_printf_extension_segment (FILE * stream,
1484 const struct printf_info *info, const void *const *args)
1491 ptr = *(void **) args[0];
1493 buffer = gst_debug_print_segment (ptr);
1494 len = fprintf (stream, "%*s", (info->left ? -info->width : info->width),
1501 #if HAVE_REGISTER_PRINTF_SPECIFIER
1503 _gst_info_printf_extension_arginfo (const struct printf_info *info, size_t n,
1504 int *argtypes, int *size)
1507 _gst_info_printf_extension_arginfo (const struct printf_info *info, size_t n,
1512 argtypes[0] = PA_POINTER;
1513 #if HAVE_REGISTER_PRINTF_SPECIFIER
1514 *size = sizeof (gpointer);
1519 #endif /* HAVE_PRINTF_EXTENSION */
1522 gst_info_dump_mem_line (gchar * linebuf, gsize linebuf_size,
1523 const guint8 * mem, gsize mem_offset, gsize mem_size)
1525 gchar hexstr[50], ascstr[18], digitstr[4];
1537 while (i < mem_size) {
1538 ascstr[i] = (g_ascii_isprint (mem[i])) ? mem[i] : '.';
1539 g_snprintf (digitstr, sizeof (digitstr), "%02x ", mem[i]);
1540 g_strlcat (hexstr, digitstr, sizeof (hexstr));
1546 g_snprintf (linebuf, linebuf_size, "%08x: %-48.48s %-16.16s",
1547 (guint) mem_offset, hexstr, ascstr);
1551 _gst_debug_dump_mem (GstDebugCategory * cat, const gchar * file,
1552 const gchar * func, gint line, GObject * obj, const gchar * msg,
1553 const guint8 * data, guint length)
1557 gst_debug_log ((cat), GST_LEVEL_MEMDUMP, file, func, line, obj, "--------"
1558 "-------------------------------------------------------------------");
1560 if (msg != NULL && *msg != '\0') {
1561 gst_debug_log ((cat), GST_LEVEL_MEMDUMP, file, func, line, obj, msg);
1564 while (off < length) {
1567 /* gst_info_dump_mem_line will process 16 bytes at most */
1568 gst_info_dump_mem_line (buf, sizeof (buf), data, off, length - off);
1569 gst_debug_log (cat, GST_LEVEL_MEMDUMP, file, func, line, obj, "%s", buf);
1573 gst_debug_log ((cat), GST_LEVEL_MEMDUMP, file, func, line, obj, "--------"
1574 "-------------------------------------------------------------------");
1577 #else /* !GST_DISABLE_GST_DEBUG */
1578 #ifndef GST_REMOVE_DISABLED
1580 gst_debug_log (GstDebugCategory * category, GstDebugLevel level,
1581 const gchar * file, const gchar * function, gint line,
1582 GObject * object, const gchar * format, ...)
1587 gst_debug_log_valist (GstDebugCategory * category, GstDebugLevel level,
1588 const gchar * file, const gchar * function, gint line,
1589 GObject * object, const gchar * format, va_list args)
1594 gst_debug_message_get (GstDebugMessage * message)
1600 gst_debug_log_default (GstDebugCategory * category, GstDebugLevel level,
1601 const gchar * file, const gchar * function, gint line,
1602 GObject * object, GstDebugMessage * message, gpointer unused)
1606 G_CONST_RETURN gchar *
1607 gst_debug_level_get_name (GstDebugLevel level)
1613 gst_debug_add_log_function (GstLogFunction func, gpointer data)
1618 gst_debug_remove_log_function (GstLogFunction func)
1624 gst_debug_remove_log_function_by_data (gpointer data)
1630 gst_debug_set_active (gboolean active)
1635 gst_debug_is_active (void)
1641 gst_debug_set_colored (gboolean colored)
1646 gst_debug_is_colored (void)
1652 gst_debug_set_default_threshold (GstDebugLevel level)
1657 gst_debug_get_default_threshold (void)
1659 return GST_LEVEL_NONE;
1663 gst_debug_set_threshold_for_name (const gchar * name, GstDebugLevel level)
1668 gst_debug_unset_threshold_for_name (const gchar * name)
1673 gst_debug_category_free (GstDebugCategory * category)
1678 gst_debug_category_set_threshold (GstDebugCategory * category,
1679 GstDebugLevel level)
1684 gst_debug_category_reset_threshold (GstDebugCategory * category)
1689 gst_debug_category_get_threshold (GstDebugCategory * category)
1691 return GST_LEVEL_NONE;
1694 G_CONST_RETURN gchar *
1695 gst_debug_category_get_name (GstDebugCategory * category)
1701 gst_debug_category_get_color (GstDebugCategory * category)
1706 G_CONST_RETURN gchar *
1707 gst_debug_category_get_description (GstDebugCategory * category)
1713 gst_debug_get_all_categories (void)
1719 gst_debug_construct_term_color (guint colorinfo)
1721 return g_strdup ("00");
1725 gst_debug_construct_win_color (guint colorinfo)
1731 _priv_gst_in_valgrind (void)
1737 _gst_debug_dump_mem (GstDebugCategory * cat, const gchar * file,
1738 const gchar * func, gint line, GObject * obj, const gchar * msg,
1739 const guint8 * data, guint length)
1742 #endif /* GST_REMOVE_DISABLED */
1743 #endif /* GST_DISABLE_GST_DEBUG */
1746 #ifdef GST_ENABLE_FUNC_INSTRUMENTATION
1747 /* FIXME make this thread specific */
1748 static GSList *stack_trace = NULL;
1751 __cyg_profile_func_enter (void *this_fn, void *call_site)
1752 G_GNUC_NO_INSTRUMENT;
1753 void __cyg_profile_func_enter (void *this_fn, void *call_site)
1755 gchar *name = _gst_debug_nameof_funcptr (this_fn);
1756 gchar *site = _gst_debug_nameof_funcptr (call_site);
1758 GST_CAT_DEBUG (GST_CAT_CALL_TRACE, "entering function %s from %s", name,
1761 g_slist_prepend (stack_trace, g_strdup_printf ("%8p in %s from %p (%s)",
1762 this_fn, name, call_site, site));
1769 __cyg_profile_func_exit (void *this_fn, void *call_site)
1770 G_GNUC_NO_INSTRUMENT;
1771 void __cyg_profile_func_exit (void *this_fn, void *call_site)
1773 gchar *name = _gst_debug_nameof_funcptr (this_fn);
1775 GST_CAT_DEBUG (GST_CAT_CALL_TRACE, "leaving function %s", name);
1776 g_free (stack_trace->data);
1777 stack_trace = g_slist_delete_link (stack_trace, stack_trace);
1783 * gst_debug_print_stack_trace:
1785 * If GST_ENABLE_FUNC_INSTRUMENTATION is defined a stacktrace is available for
1786 * gstreamer code, which can be printed with this function.
1789 gst_debug_print_stack_trace (void)
1791 GSList *walk = stack_trace;
1795 walk = g_slist_next (walk);
1798 gchar *name = (gchar *) walk->data;
1800 g_print ("#%-2d %s\n", count++, name);
1802 walk = g_slist_next (walk);
1807 gst_debug_print_stack_trace (void)
1809 /* nothing because it's compiled out */
1812 #endif /* GST_ENABLE_FUNC_INSTRUMENTATION */