From 222a51738409b6f92720bd7f4e58d0d515339410 Mon Sep 17 00:00:00 2001 From: Mathieu Duponchelle Date: Wed, 1 Oct 2014 15:53:24 +0200 Subject: [PATCH] validate-report: Add the notion of master / shadow reports. A master report is a report that has been detected by a monitor to stem from the same issue. It thus contains a list of "shadow reports" which it will browse when printing itself. --- validate/gst/validate/gst-validate-report.c | 53 +++++++++++++++++++-- validate/gst/validate/gst-validate-report.h | 8 ++++ 2 files changed, 58 insertions(+), 3 deletions(-) diff --git a/validate/gst/validate/gst-validate-report.c b/validate/gst/validate/gst-validate-report.c index a3996bc50d..22174a4e86 100644 --- a/validate/gst/validate/gst-validate-report.c +++ b/validate/gst/validate/gst-validate-report.c @@ -50,6 +50,16 @@ GST_DEBUG_CATEGORY_STATIC (gst_validate_report_debug); #undef GST_CAT_DEFAULT #define GST_CAT_DEFAULT gst_validate_report_debug +#define GST_VALIDATE_REPORT_SHADOW_REPORTS_LOCK(r) \ + G_STMT_START { \ + (g_mutex_lock (&((GstValidateReport *) r)->shadow_reports_lock)); \ + } G_STMT_END + +#define GST_VALIDATE_REPORT_SHADOW_REPORTS_UNLOCK(r) \ + G_STMT_START { \ + (g_mutex_unlock (&((GstValidateReport *) r)->shadow_reports_lock)); \ + } G_STMT_END + G_DEFINE_BOXED_TYPE (GstValidateReport, gst_validate_report, (GBoxedCopyFunc) gst_validate_report_ref, (GBoxedFreeFunc) gst_validate_report_unref); @@ -422,6 +432,7 @@ gst_validate_report_new (GstValidateIssue * issue, report->issue = issue; report->reporter = reporter; /* TODO should we ref? */ report->message = g_strdup (message); + g_mutex_init (&report->shadow_reports_lock); report->timestamp = gst_util_get_timestamp () - _gst_validate_report_start_time; report->level = issue->default_level; @@ -436,7 +447,9 @@ gst_validate_report_unref (GstValidateReport * report) if (G_UNLIKELY (g_atomic_int_dec_and_test (&report->refcount))) { g_free (report->message); + g_list_free_full (report->shadow_reports, (GDestroyNotify) gst_validate_report_unref); g_slice_free (GstValidateReport, report); + g_mutex_clear (&report->shadow_reports_lock); } } @@ -605,17 +618,51 @@ gst_validate_printf_valist (gpointer source, const gchar * format, va_list args) g_string_free (string, TRUE); } +void +gst_validate_report_set_master_report (GstValidateReport * report, + GstValidateReport * master_report) +{ + GList *tmp; + gboolean add_shadow_report = TRUE; + + report->master_report = master_report; + + GST_VALIDATE_REPORT_SHADOW_REPORTS_LOCK (master_report); + for (tmp = master_report->shadow_reports; tmp; tmp = tmp->next) { + GstValidateReport *shadow_report = (GstValidateReport *) tmp->data; + if (report->reporter == shadow_report->reporter) { + add_shadow_report = FALSE; + break; + } + } + if (add_shadow_report) + master_report->shadow_reports = + g_list_append (master_report->shadow_reports, gst_validate_report_ref (report)); + GST_VALIDATE_REPORT_SHADOW_REPORTS_UNLOCK (master_report); +} + void gst_validate_report_printf (GstValidateReport * report) { + GList *tmp; + gst_validate_printf (NULL, "%10s : %s\n", gst_validate_report_level_get_name (report->level), report->issue->summary); - gst_validate_printf (NULL, "%*s Detected on <%s> at %" GST_TIME_FORMAT "\n", - 12, "", gst_validate_reporter_get_name (report->reporter), - GST_TIME_ARGS (report->timestamp)); + gst_validate_printf (NULL, "%*s Detected on <%s", + 12, "", gst_validate_reporter_get_name (report->reporter)); + + for (tmp = report->shadow_reports; tmp; tmp = tmp->next) { + GstValidateReport *shadow_report = (GstValidateReport *) tmp->data; + gst_validate_printf (NULL, ", %s", + gst_validate_reporter_get_name (shadow_report->reporter)); + } + + gst_validate_printf (NULL, ">\n"); + if (report->message) gst_validate_printf (NULL, "%*s Details : %s\n", 12, "", report->message); + if (report->issue->description) gst_validate_printf (NULL, "%*s Description : %s\n", 12, "", report->issue->description); diff --git a/validate/gst/validate/gst-validate-report.h b/validate/gst/validate/gst-validate-report.h index 3d5b66c2dd..b479aa0ec5 100644 --- a/validate/gst/validate/gst-validate-report.h +++ b/validate/gst/validate/gst-validate-report.h @@ -169,6 +169,13 @@ struct _GstValidateReport { /* message: issue-specific message. Gives more detail on the actual * issue. Can be NULL */ gchar *message; + + /* When reporter->intercept_report returns KEEP, the report is not + * added to the runner. It can be added as a "shadow_report" to + * the upstream report, which is tracked by the runner. */ + GMutex shadow_reports_lock; + GstValidateReport *master_report; + GList *shadow_reports; }; #define GST_VALIDATE_ISSUE_FORMAT G_GUINTPTR_FORMAT " (%s) : %s(%" G_GUINTPTR_FORMAT "): %s" @@ -212,6 +219,7 @@ void gst_validate_printf_valist (gpointer source, const gchar * format, va_list args) G_GNUC_NO_INSTRUMENT; gboolean gst_validate_report_should_print (GstValidateReport * report); +void gst_validate_report_set_master_report(GstValidateReport *report, GstValidateReport *master_report); G_END_DECLS