info: Reset patterns with set_threshold_from_string

TLDR: Make `gst_set_threshold_from_string ("", TRUE)` reset *all*
threshold settings, including those set by previous invocations of
`gst_debug_set_threshold_from_string`.

The docs say:

    @reset: %TRUE to clear all previously-set debug levels before setting
        new thresholds

What actually happens is it sets the default threshold to `ERROR`,
leaves the patterns in place and calls
`gst_debug_category_reset_threshold` on each category.

In effect, any category that is matched by a pattern gets reset to that
threshold if the app changed it by directly invoking
`gst_debug_category_set_threshold`. All other categories are reset to
`ERROR`.

In my opinion this parameter currently has little value, as the same
effect can be achieved by including `ERROR` (without a pattern) in the
string, as in `"foo*:WARNING,*bar:INFO,ERROR"`.

What I actually expect it to do is reset *all* threshold settings,
including those set by previous invocations of
`gst_debug_set_threshold_from_string`, starting off with a clean slate
for the patterns provided with the call.

Otherwise there is no API to do this, besides:

  - Painfully removing patterns one-by-one via
    `gst_debug_unset_threshold_for_name` *if* you know what the patterns
    are.
  - Adding a `*:FOO` pattern to affect all categories, which makes the
    default threshold useless and practically leaks all the old
    patterns.

In my opinion this also makes it fit better into the layers of threshold
config, which is:

1. Temporary:
  - `gst_debug_category_set_threshold`
  - `gst_debug_category_reset_threshold`
2. Patterns:
  - `gst_debug_set_threshold_for_name`
  - `gst_debug_unset_threshold_for_name`
  - `gst_debug_set_threshold_from_string`
  - `GST_DEBUG`
3. Default:
  - `gst_debug_set_default_threshold`

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/605>
This commit is contained in:
Jan Alexander Steffens (heftig) 2020-08-22 22:41:15 +02:00 committed by GStreamer Marge Bot
parent b22093be3c
commit 58013b4b21

View file

@ -316,6 +316,8 @@ typedef struct
}
LevelNameEntry;
static void clear_level_names (void);
/* list of all categories */
static GMutex __cat_mutex;
static GSList *__categories = NULL;
@ -2171,8 +2173,10 @@ gst_debug_set_threshold_from_string (const gchar * list, gboolean reset)
g_assert (list);
if (reset)
if (reset) {
clear_level_names ();
gst_debug_set_default_threshold (GST_LEVEL_DEFAULT);
}
split = g_strsplit (list, ",", 0);
@ -2272,6 +2276,19 @@ _gst_debug_register_funcptr (GstDebugFuncPtr func, const gchar * ptrname)
g_mutex_unlock (&__dbg_functions_mutex);
}
static void
clear_level_names (void)
{
g_mutex_lock (&__level_name_mutex);
while (__level_name) {
LevelNameEntry *level_name_entry = __level_name->data;
g_pattern_spec_free (level_name_entry->pat);
g_slice_free (LevelNameEntry, level_name_entry);
__level_name = g_slist_delete_link (__level_name, __level_name);
}
g_mutex_unlock (&__level_name_mutex);
}
void
_priv_gst_debug_cleanup (void)
{
@ -2294,14 +2311,7 @@ _priv_gst_debug_cleanup (void)
}
g_mutex_unlock (&__cat_mutex);
g_mutex_lock (&__level_name_mutex);
while (__level_name) {
LevelNameEntry *level_name_entry = __level_name->data;
g_pattern_spec_free (level_name_entry->pat);
g_slice_free (LevelNameEntry, level_name_entry);
__level_name = g_slist_delete_link (__level_name, __level_name);
}
g_mutex_unlock (&__level_name_mutex);
clear_level_names ();
g_mutex_lock (&__log_func_mutex);
while (__log_functions) {