stats: print thread key for stats and filter empty pad-sections
authorStefan Sauer <ensonic@users.sf.net>
Sun, 17 Nov 2013 10:37:14 +0000 (11:37 +0100)
committerStefan Sauer <ensonic@users.sf.net>
Mon, 5 Oct 2015 18:59:39 +0000 (20:59 +0200)
tools/gst-stats.c

index c7c550e..8c03eca 100644 (file)
@@ -363,6 +363,14 @@ do_query_stats (GstStructure * s)
 
 /* reporting */
 
+static gint
+find_pad_stats_for_thread (gconstpointer value, gconstpointer user_data)
+{
+  const GstPadStats *stats = (const GstPadStats *) value;
+
+  return (stats->thread_id == GPOINTER_TO_UINT (user_data)) ? 0 : 1;
+}
+
 static void
 print_pad_stats (gpointer value, gpointer user_data)
 {
@@ -404,7 +412,7 @@ print_pad_stats (gpointer value, gpointer user_data)
 static void
 print_thread_stats (gpointer key, gpointer value, gpointer user_data)
 {
-  GSList *list = user_data;
+  GSList *list = user_data, *node;
 #if 0
   GstThreadStats *stats = (GstThreadStats *) value;
   guint cpuload = 0;
@@ -422,18 +430,19 @@ print_thread_stats (gpointer key, gpointer value, gpointer user_data)
     total = gst_util_uint64_scale (tusersys, G_GINT64_CONSTANT (100), last_ts);
     cpuload = gst_util_uint64_scale (total, stats->treal, last_ts);
   }
+#endif
 
   printf ("Thread %p Statistics:\n", key);
+#if 0
   printf ("  Time: %" GST_TIME_FORMAT ", %u %%\n", GST_TIME_ARGS (stats->treal),
       (guint) time_percent);
   printf ("  Avg/Max CPU load: %u %%, %u %%\n", cpuload, stats->max_cpuload);
 #endif
-  /* FIXME: would be nice to skip, if there are no pads for that thread
-   * (e.g. a pipeline), we would need to pass as struct to
-   * g_hash_table_foreach::user_data
-   */
-  puts ("  Pad Statistics:");
-  g_slist_foreach (list, print_pad_stats, key);
+  /* skip stats if there are no pads for that thread (e.g. a pipeline) */
+  if ((node = g_slist_find_custom (list, key, find_pad_stats_for_thread))) {
+    puts ("  Pad Statistics:");
+    g_slist_foreach (node, print_pad_stats, key);
+  }
 }
 
 static void