* the name */
#ifdef HAVE_DLADDR
if (dladdr ((gpointer) func, &dl_info) && dl_info.dli_sname) {
- gchar *name = g_strdup (dl_info.dli_sname);
+ const gchar *name = g_intern_string (dl_info.dli_sname);
_gst_debug_register_funcptr (func, name);
return name;
#endif
{
gchar *name = g_strdup_printf ("%p", (gpointer) func);
+ const gchar *iname = g_intern_string (name);
- _gst_debug_register_funcptr (func, name);
- return name;
+ g_free (name);
+
+ _gst_debug_register_funcptr (func, iname);
+ return iname;
}
}
if (!__gst_function_pointers)
__gst_function_pointers = g_hash_table_new (g_direct_hash, g_direct_equal);
- if (!g_hash_table_lookup (__gst_function_pointers, ptr))
+ if (!g_hash_table_lookup (__gst_function_pointers, ptr)) {
g_hash_table_insert (__gst_function_pointers, ptr, (gpointer) ptrname);
+ }
+
+ g_mutex_unlock (&__dbg_functions_mutex);
+}
+
+void
+_priv_gst_debug_cleanup (void)
+{
+ g_mutex_lock (&__dbg_functions_mutex);
+
+ if (__gst_function_pointers) {
+ g_hash_table_unref (__gst_function_pointers);
+ __gst_function_pointers = NULL;
+ }
g_mutex_unlock (&__dbg_functions_mutex);
}
}
void
+_priv_gst_debug_cleanup (void)
+{
+}
+
+void
gst_debug_log (GstDebugCategory * category, GstDebugLevel level,
const gchar * file, const gchar * function, gint line,
GObject * object, const gchar * format, ...)
gint64 now = g_get_monotonic_time ();
const gchar *message_str = gst_debug_message_get (message);
+ /* __FILE__ might be a file name or an absolute path or a
+ * relative path, irrespective of the exact compiler used,
+ * in which case we want to shorten it to the filename for
+ * readability. */
+ c = file[0];
+ if (c == '.' || c == '/' || c == '\\' || (c != '\0' && file[1] == ':')) {
+ file = gst_path_basename (file);
+ }
+
+ if (object) {
+ obj = gst_debug_print_object (object);
+ } else {
+ obj = (gchar *) "";
+ }
+
+ elapsed = GST_CLOCK_DIFF (_priv_gst_start_time, gst_util_get_timestamp ());
+ pid = getpid ();
+ thread = g_thread_self ();
+
+ /* no color, all platforms */
+#define PRINT_FMT " "PID_FMT" "PTR_FMT" %s "CAT_FMT" %s\n"
+ output =
+ g_strdup_printf ("%" GST_TIME_FORMAT PRINT_FMT, GST_TIME_ARGS (elapsed),
+ pid, thread, gst_debug_level_get_name (level),
+ gst_debug_category_get_name (category), file, line, function, obj,
+ message_str);
+#undef PRINT_FMT
+
+ output_len = strlen (output);
+
+ if (object != NULL)
+ g_free (obj);
+
G_LOCK (ring_buffer_logger);
if (logger->thread_timeout > 0) {
+ gchar *buf;
+
/* Remove all threads that saw no output since thread_timeout seconds.
* By construction these are all at the tail of the queue, and the queue
* is ordered by last use, so we just need to look at the tail.
break;
g_hash_table_remove (logger->thread_index, log->thread);
- while ((output = g_queue_pop_head (&log->log)))
- g_free (output);
+ while ((buf = g_queue_pop_head (&log->log)))
+ g_free (buf);
g_free (log);
g_queue_pop_tail (&logger->threads);
}
/* Get logger for this thread, and put it back at the
* head of the threads queue */
- thread = g_thread_self ();
log = g_hash_table_lookup (logger->thread_index, thread);
if (!log) {
log = g_new0 (GstRingBufferLog, 1);
}
log->last_use = now;
- /* __FILE__ might be a file name or an absolute path or a
- * relative path, irrespective of the exact compiler used,
- * in which case we want to shorten it to the filename for
- * readability. */
- c = file[0];
- if (c == '.' || c == '/' || c == '\\' || (c != '\0' && file[1] == ':')) {
- file = gst_path_basename (file);
- }
-
- pid = getpid ();
-
- if (object) {
- obj = gst_debug_print_object (object);
- } else {
- obj = (gchar *) "";
- }
-
- elapsed = GST_CLOCK_DIFF (_priv_gst_start_time, gst_util_get_timestamp ());
-
- /* no color, all platforms */
-#define PRINT_FMT " "PID_FMT" "PTR_FMT" %s "CAT_FMT" %s\n"
- output =
- g_strdup_printf ("%" GST_TIME_FORMAT PRINT_FMT, GST_TIME_ARGS (elapsed),
- pid, thread, gst_debug_level_get_name (level),
- gst_debug_category_get_name (category), file, line, function, obj,
- message_str);
-#undef PRINT_FMT
-
- output_len = strlen (output);
-
if (output_len < logger->max_size_per_thread) {
gchar *buf;
log->log_size = 0;
}
- if (object != NULL)
- g_free (obj);
-
G_UNLOCK (ring_buffer_logger);
}