dump2dot: make caps in DOT debug graphs more readable. Fixes 574484
[platform/upstream/gstreamer.git] / gst / gstdebugutils.c
1 /* GStreamer
2  * Copyright (C) 2007 Stefan Kost <ensonic@users.sf.net>
3  *
4  * gstdebugutils.c: debugging and analysis utillities
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library; if not, write to the
18  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  */
21 /* TODO:
22  * edge [ constraint=false ];
23  *   this creates strange graphs ("minlen=0" is better)
24  * try puting src/sink ghostpads for each bin into invisible clusters
25  *
26  * for more compact nodes, try
27  * - changing node-shape from box into record
28  * - use labels like : element [ label="{element | <src> src | <sink> sink}"]
29  * - point to record-connectors : element1:src -> element2:sink
30  */
31
32 #include "gst_private.h"
33 #include "gstdebugutils.h"
34
35 #ifndef GST_DISABLE_GST_DEBUG
36
37 #include <stdlib.h>
38 #include <stdio.h>
39 #include <string.h>
40 #include <errno.h>
41
42 #include "gstinfo.h"
43 #include "gstbin.h"
44 #include "gstobject.h"
45 #include "gstghostpad.h"
46 #include "gstpad.h"
47 #include "gstutils.h"
48 #include "gstvalue.h"
49
50 /*** PIPELINE GRAPHS **********************************************************/
51
52 const gchar *priv_gst_dump_dot_dir;     /* NULL *//* set from gst.c */
53
54 extern GstClockTime _priv_gst_info_start_time;
55
56 static gchar *
57 debug_dump_make_object_name (GstObject * element)
58 {
59   return g_strcanon (g_strdup_printf ("%s_%p", GST_OBJECT_NAME (element),
60           element), G_CSET_A_2_Z G_CSET_a_2_z G_CSET_DIGITS "_", '_');
61 }
62
63 static gchar *
64 debug_dump_get_element_state (GstElement * element)
65 {
66   gchar *state_name = NULL;
67   const gchar *state_icons = "~0-=>";
68   GstState state = 0, pending = 0;
69
70   gst_element_get_state (element, &state, &pending, 0);
71   if (pending == GST_STATE_VOID_PENDING) {
72     state_name = g_strdup_printf ("\\n[%c]", state_icons[state]);
73   } else {
74     state_name = g_strdup_printf ("\\n[%c] -> [%c]", state_icons[state],
75         state_icons[pending]);
76   }
77   return state_name;
78 }
79
80 static gchar *
81 debug_dump_get_element_params (GstElement * element)
82 {
83   gchar *param_name = NULL;
84   GParamSpec **properties, *property;
85   GValue value = { 0, };
86   guint i, number_of_properties;
87   gchar *tmp, *value_str;
88
89   /* get paramspecs and show non-default properties */
90   properties =
91       g_object_class_list_properties (G_OBJECT_CLASS (GST_ELEMENT_GET_CLASS
92           (element)), &number_of_properties);
93   if (properties) {
94     for (i = 0; i < number_of_properties; i++) {
95       property = properties[i];
96
97       /* ski some properties */
98       if (!(property->flags & G_PARAM_READABLE))
99         continue;
100       if (!strcmp (property->name, "name"))
101         continue;
102
103       g_value_init (&value, property->value_type);
104       g_object_get_property (G_OBJECT (element), property->name, &value);
105       if (!(g_param_value_defaults (property, &value))) {
106         tmp = g_strdup_value_contents (&value);
107         value_str = g_strescape (tmp, NULL);
108         g_free (tmp);
109         if (param_name) {
110           tmp = param_name;
111           param_name = g_strdup_printf ("%s\\n%s=%s",
112               tmp, property->name, value_str);
113           g_free (tmp);
114         } else {
115           param_name = g_strdup_printf ("\\n%s=%s", property->name, value_str);
116         }
117         g_free (value_str);
118       }
119       g_value_unset (&value);
120     }
121     g_free (properties);
122   }
123   return param_name;
124 }
125
126 static void
127 debug_dump_element_pad (GstPad * pad, GstElement * element,
128     GstDebugGraphDetails details, FILE * out, const gint indent)
129 {
130   GstElement *target_element;
131   GstPad *target_pad, *tmp_pad;
132   GstPadDirection dir;
133   GstPadTemplate *pad_templ;
134   GstPadPresence presence;
135   gchar *pad_name, *element_name;
136   gchar *target_pad_name, *target_element_name;
137   gchar *color_name, *style_name;
138   gchar *spc = NULL;
139
140   spc = g_malloc (1 + indent * 2);
141   memset (spc, 32, indent * 2);
142   spc[indent * 2] = '\0';
143
144   dir = gst_pad_get_direction (pad);
145   pad_name = debug_dump_make_object_name (GST_OBJECT (pad));
146   element_name = debug_dump_make_object_name (GST_OBJECT (element));
147   if (GST_IS_GHOST_PAD (pad)) {
148     color_name =
149         (dir == GST_PAD_SRC) ? "#ffdddd" : ((dir ==
150             GST_PAD_SINK) ? "#ddddff" : "#ffffff");
151     /* output target-pad so that it belongs to this element */
152     if ((tmp_pad = gst_ghost_pad_get_target (GST_GHOST_PAD (pad)))) {
153       if ((target_pad = gst_pad_get_peer (tmp_pad))) {
154         target_pad_name = debug_dump_make_object_name (GST_OBJECT (target_pad));
155         if ((target_element = gst_pad_get_parent_element (target_pad))) {
156           target_element_name =
157               debug_dump_make_object_name (GST_OBJECT (target_element));
158         } else {
159           target_element_name = "";
160         }
161         style_name = "filled,solid";
162         if ((pad_templ = gst_pad_get_pad_template (target_pad))) {
163           presence = GST_PAD_TEMPLATE_PRESENCE (pad_templ);
164           if (presence == GST_PAD_SOMETIMES) {
165             style_name = "filled,dotted";
166           } else if (presence == GST_PAD_REQUEST) {
167             style_name = "filled,dashed";
168           }
169         }
170         fprintf (out,
171             "%s  %s_%s [color=black, fillcolor=\"%s\", label=\"%s\", height=\"0.2\", style=\"%s\"];\n",
172             spc, target_element_name, target_pad_name, color_name,
173             GST_OBJECT_NAME (target_pad), style_name);
174         g_free (target_pad_name);
175         if (target_element) {
176           g_free (target_element_name);
177           gst_object_unref (target_element);
178         }
179         gst_object_unref (target_pad);
180       }
181       gst_object_unref (tmp_pad);
182     }
183   } else {
184     color_name =
185         (dir == GST_PAD_SRC) ? "#ffaaaa" : ((dir ==
186             GST_PAD_SINK) ? "#aaaaff" : "#cccccc");
187   }
188   /* pads */
189   style_name = "filled,solid";
190   if ((pad_templ = gst_pad_get_pad_template (pad))) {
191     presence = GST_PAD_TEMPLATE_PRESENCE (pad_templ);
192     if (presence == GST_PAD_SOMETIMES) {
193       style_name = "filled,dotted";
194     } else if (presence == GST_PAD_REQUEST) {
195       style_name = "filled,dashed";
196     }
197   }
198   fprintf (out,
199       "%s  %s_%s [color=black, fillcolor=\"%s\", label=\"%s\", height=\"0.2\", style=\"%s\"];\n",
200       spc, element_name, pad_name, color_name, GST_OBJECT_NAME (pad),
201       style_name);
202
203   g_free (pad_name);
204   g_free (element_name);
205   g_free (spc);
206 }
207
208 static gboolean
209 string_append_field (GQuark field, const GValue * value, gpointer ptr)
210 {
211   GString *str = (GString *) ptr;
212   gchar *value_str = gst_value_serialize (value);
213
214   g_string_append_printf (str, "  %15s: %s\\l", g_quark_to_string (field),
215       value_str);
216
217   g_free (value_str);
218   return TRUE;
219 }
220
221 static gchar *
222 debug_dump_describe_caps (GstCaps * caps, GstDebugGraphDetails details,
223     gboolean * need_free)
224 {
225   gchar *media = NULL;
226
227   if (details & GST_DEBUG_GRAPH_SHOW_CAPS_DETAILS) {
228
229     if (gst_caps_is_any (caps) || gst_caps_is_empty (caps)) {
230       media = gst_caps_to_string (caps);
231       *need_free = TRUE;
232
233     } else {
234       GString *str = NULL;
235       guint i;
236       guint slen = 0;
237
238       for (i = 0; i < gst_caps_get_size (caps); i++) {
239         slen +=
240             STRUCTURE_ESTIMATED_STRING_LEN (gst_caps_get_structure (caps, i));
241       }
242
243       str = g_string_sized_new (slen);
244       for (i = 0; i < gst_caps_get_size (caps); i++) {
245         GstStructure *structure = gst_caps_get_structure (caps, i);
246
247         g_string_append (str, gst_structure_get_name (structure));
248         g_string_append (str, "\\l");
249
250         gst_structure_foreach (structure, string_append_field, (gpointer) str);
251       }
252
253       media = g_string_free (str, FALSE);
254       *need_free = TRUE;
255     }
256
257   } else {
258     if (GST_CAPS_IS_SIMPLE (caps))
259       media =
260           (gchar *) gst_structure_get_name (gst_caps_get_structure (caps, 0));
261     else
262       media = "*";
263     *need_free = FALSE;
264   }
265   return media;
266 }
267
268 static void
269 debug_dump_element_pad_link (GstPad * pad, GstElement * element,
270     GstDebugGraphDetails details, FILE * out, const gint indent)
271 {
272   GstElement *peer_element, *target_element;
273   GstPad *peer_pad, *target_pad, *tmp_pad;
274   GstCaps *caps, *peer_caps;
275   gboolean free_caps, free_peer_caps, free_media;
276   gchar *media = NULL;
277   gchar *pad_name, *element_name;
278   gchar *peer_pad_name, *peer_element_name;
279   gchar *target_pad_name, *target_element_name;
280   gchar *spc = NULL;
281
282   spc = g_malloc (1 + indent * 2);
283   memset (spc, 32, indent * 2);
284   spc[indent * 2] = '\0';
285
286   if ((peer_pad = gst_pad_get_peer (pad))) {
287     free_media = FALSE;
288     if ((details & GST_DEBUG_GRAPH_SHOW_MEDIA_TYPE) ||
289         (details & GST_DEBUG_GRAPH_SHOW_CAPS_DETAILS)
290         ) {
291       if ((caps = gst_pad_get_negotiated_caps (pad))) {
292         free_caps = TRUE;
293       } else {
294         free_caps = FALSE;
295         if (!(caps = (GstCaps *)
296                 gst_pad_get_pad_template_caps (pad))) {
297           /* this should not happen */
298           media = "?";
299         }
300       }
301       if ((peer_caps = gst_pad_get_negotiated_caps (peer_pad))) {
302         free_peer_caps = TRUE;
303       } else {
304         free_peer_caps = FALSE;
305         peer_caps = (GstCaps *) gst_pad_get_pad_template_caps (peer_pad);
306       }
307       if (caps) {
308         media = debug_dump_describe_caps (caps, details, &free_media);
309         /* check if peer caps are different */
310         if (peer_caps && !gst_caps_is_equal (caps, peer_caps)) {
311           gchar *old_media = media;
312           gchar *tmp;
313           gboolean free_tmp;
314
315           tmp = debug_dump_describe_caps (peer_caps, details, &free_tmp);
316           if (gst_pad_get_direction (pad) == GST_PAD_SRC) {
317             media = g_strdup_printf ("%s\\n---\\n%s", media, tmp);
318           } else {
319             media = g_strdup_printf ("%s\\n---\\n%s", tmp, media);
320           }
321           if (free_media)
322             g_free (old_media);
323           if (free_tmp)
324             g_free (tmp);
325           free_media = TRUE;
326         }
327         if (free_caps) {
328           gst_caps_unref (caps);
329         }
330       }
331       if (free_peer_caps && peer_caps) {
332         gst_caps_unref (peer_caps);
333       }
334     }
335
336     pad_name = debug_dump_make_object_name (GST_OBJECT (pad));
337     if (element) {
338       element_name = debug_dump_make_object_name (GST_OBJECT (element));
339     } else {
340       element_name = "";
341     }
342     peer_pad_name = debug_dump_make_object_name (GST_OBJECT (peer_pad));
343     if ((peer_element = gst_pad_get_parent_element (peer_pad))) {
344       peer_element_name =
345           debug_dump_make_object_name (GST_OBJECT (peer_element));
346     } else {
347       peer_element_name = "";
348     }
349
350     if (GST_IS_GHOST_PAD (pad)) {
351       if ((tmp_pad = gst_ghost_pad_get_target (GST_GHOST_PAD (pad)))) {
352         if ((target_pad = gst_pad_get_peer (tmp_pad))) {
353           target_pad_name =
354               debug_dump_make_object_name (GST_OBJECT (target_pad));
355           if ((target_element = gst_pad_get_parent_element (target_pad))) {
356             target_element_name =
357                 debug_dump_make_object_name (GST_OBJECT (target_element));
358           } else {
359             target_element_name = "";
360           }
361           /* src ghostpad relationship */
362           fprintf (out, "%s%s_%s -> %s_%s [style=dashed, minlen=0]\n", spc,
363               target_element_name, target_pad_name, element_name, pad_name);
364
365           g_free (target_pad_name);
366           if (target_element) {
367             g_free (target_element_name);
368             gst_object_unref (target_element);
369           }
370           gst_object_unref (target_pad);
371         }
372         gst_object_unref (tmp_pad);
373       }
374     }
375     if (GST_IS_GHOST_PAD (peer_pad)) {
376       if ((tmp_pad = gst_ghost_pad_get_target (GST_GHOST_PAD (peer_pad)))) {
377         if ((target_pad = gst_pad_get_peer (tmp_pad))) {
378           target_pad_name =
379               debug_dump_make_object_name (GST_OBJECT (target_pad));
380           if ((target_element = gst_pad_get_parent_element (target_pad))) {
381             target_element_name =
382                 debug_dump_make_object_name (GST_OBJECT (target_element));
383           } else {
384             target_element_name = "";
385           }
386           /* sink ghostpad relationship */
387           fprintf (out, "%s%s_%s -> %s_%s [style=dashed, minlen=0]\n", spc,
388               peer_element_name, peer_pad_name,
389               target_element_name, target_pad_name);
390           /* FIXME: we are missing links from the proxy pad
391            * theoretically we need to:
392            * pad=gst_object_ref(target_pad);
393            * goto line 280: if ((peer_pad = gst_pad_get_peer (pad)))
394            * as this would e ugly we need to refactor ...
395            */
396           debug_dump_element_pad_link (target_pad, target_element, details, out,
397               indent);
398           g_free (target_pad_name);
399           if (target_element) {
400             g_free (target_element_name);
401             gst_object_unref (target_element);
402           }
403           gst_object_unref (target_pad);
404         }
405         gst_object_unref (tmp_pad);
406       }
407     }
408
409     /* pad link */
410     if (media) {
411       fprintf (out, "%s%s_%s -> %s_%s [label=\"%s\"]\n", spc,
412           element_name, pad_name, peer_element_name, peer_pad_name, media);
413       if (free_media) {
414         g_free (media);
415       }
416     } else {
417       fprintf (out, "%s%s_%s -> %s_%s\n", spc,
418           element_name, pad_name, peer_element_name, peer_pad_name);
419     }
420
421     g_free (pad_name);
422     if (element) {
423       g_free (element_name);
424     }
425     g_free (peer_pad_name);
426     if (peer_element) {
427       g_free (peer_element_name);
428       gst_object_unref (peer_element);
429     }
430     gst_object_unref (peer_pad);
431   }
432   g_free (spc);
433 }
434
435 /*
436  * debug_dump_element:
437  * @bin: the bin that should be analyzed
438  * @out: file to write to
439  * @indent: level of graph indentation
440  *
441  * Helper for _gst_debug_bin_to_dot_file() to recursively dump a pipeline.
442  */
443 static void
444 debug_dump_element (GstBin * bin, GstDebugGraphDetails details, FILE * out,
445     const gint indent)
446 {
447   GstIterator *element_iter, *pad_iter;
448   gboolean elements_done, pads_done;
449   GstElement *element;
450   GstPad *pad;
451   GstPadDirection dir;
452   guint src_pads, sink_pads;
453   gchar *element_name;
454   gchar *state_name = NULL;
455   gchar *param_name = NULL;
456   gchar *spc = NULL;
457
458   spc = g_malloc (1 + indent * 2);
459   memset (spc, 32, indent * 2);
460   spc[indent * 2] = '\0';
461
462   element_iter = gst_bin_iterate_elements (bin);
463   elements_done = FALSE;
464   while (!elements_done) {
465     switch (gst_iterator_next (element_iter, (gpointer) & element)) {
466       case GST_ITERATOR_OK:
467         element_name = debug_dump_make_object_name (GST_OBJECT (element));
468
469         if (details & GST_DEBUG_GRAPH_SHOW_STATES) {
470           state_name = debug_dump_get_element_state (GST_ELEMENT (element));
471         }
472         if (details & GST_DEBUG_GRAPH_SHOW_NON_DEFAULT_PARAMS) {
473           param_name = debug_dump_get_element_params (GST_ELEMENT (element));
474         }
475         /* elements */
476         fprintf (out, "%ssubgraph cluster_%s {\n", spc, element_name);
477         fprintf (out, "%s  fontname=\"Bitstream Vera Sans\";\n", spc);
478         fprintf (out, "%s  fontsize=\"8\";\n", spc);
479         fprintf (out, "%s  style=filled;\n", spc);
480         fprintf (out, "%s  color=black;\n\n", spc);
481         fprintf (out, "%s  label=\"%s\\n%s%s%s\";\n", spc,
482             G_OBJECT_TYPE_NAME (element), GST_OBJECT_NAME (element),
483             (state_name ? state_name : ""), (param_name ? param_name : "")
484             );
485         if (state_name) {
486           g_free (state_name);
487           state_name = NULL;
488         }
489         if (param_name) {
490           g_free (param_name);
491           param_name = NULL;
492         }
493         g_free (element_name);
494
495         src_pads = sink_pads = 0;
496         if ((pad_iter = gst_element_iterate_pads (element))) {
497           pads_done = FALSE;
498           while (!pads_done) {
499             switch (gst_iterator_next (pad_iter, (gpointer) & pad)) {
500               case GST_ITERATOR_OK:
501                 debug_dump_element_pad (pad, element, details, out, indent);
502                 dir = gst_pad_get_direction (pad);
503                 if (dir == GST_PAD_SRC)
504                   src_pads++;
505                 else if (dir == GST_PAD_SINK)
506                   sink_pads++;
507                 gst_object_unref (pad);
508                 break;
509               case GST_ITERATOR_RESYNC:
510                 gst_iterator_resync (pad_iter);
511                 break;
512               case GST_ITERATOR_ERROR:
513               case GST_ITERATOR_DONE:
514                 pads_done = TRUE;
515                 break;
516             }
517           }
518           gst_iterator_free (pad_iter);
519         }
520         if (GST_IS_BIN (element)) {
521           fprintf (out, "%s  fillcolor=\"#ffffff\";\n", spc);
522           /* recurse */
523           debug_dump_element (GST_BIN (element), details, out, indent + 1);
524         } else {
525           if (src_pads && !sink_pads)
526             fprintf (out, "%s  fillcolor=\"#ffaaaa\";\n", spc);
527           else if (!src_pads && sink_pads)
528             fprintf (out, "%s  fillcolor=\"#aaaaff\";\n", spc);
529           else if (src_pads && sink_pads)
530             fprintf (out, "%s  fillcolor=\"#aaffaa\";\n", spc);
531           else
532             fprintf (out, "%s  fillcolor=\"#ffffff\";\n", spc);
533         }
534         fprintf (out, "%s}\n\n", spc);
535         if ((pad_iter = gst_element_iterate_pads (element))) {
536           pads_done = FALSE;
537           while (!pads_done) {
538             switch (gst_iterator_next (pad_iter, (gpointer) & pad)) {
539               case GST_ITERATOR_OK:
540                 if (gst_pad_is_linked (pad)
541                     && gst_pad_get_direction (pad) == GST_PAD_SRC) {
542                   debug_dump_element_pad_link (pad, element, details, out,
543                       indent);
544                 }
545                 gst_object_unref (pad);
546                 break;
547               case GST_ITERATOR_RESYNC:
548                 gst_iterator_resync (pad_iter);
549                 break;
550               case GST_ITERATOR_ERROR:
551               case GST_ITERATOR_DONE:
552                 pads_done = TRUE;
553                 break;
554             }
555           }
556           gst_iterator_free (pad_iter);
557         }
558         gst_object_unref (element);
559         break;
560       case GST_ITERATOR_RESYNC:
561         gst_iterator_resync (element_iter);
562         break;
563       case GST_ITERATOR_ERROR:
564       case GST_ITERATOR_DONE:
565         elements_done = TRUE;
566         break;
567     }
568   }
569   gst_iterator_free (element_iter);
570   g_free (spc);
571 }
572
573 /*
574  * _gst_debug_bin_to_dot_file:
575  * @bin: the top-level pipeline that should be analyzed
576  * @file_name: output base filename (e.g. "myplayer")
577  *
578  * To aid debugging applications one can use this method to write out the whole
579  * network of gstreamer elements that form the pipeline into an dot file.
580  * This file can be processed with graphviz to get an image.
581  * <informalexample><programlisting>
582  *  dot -Tpng -oimage.png graph_lowlevel.dot
583  * </programlisting></informalexample>
584  */
585 void
586 _gst_debug_bin_to_dot_file (GstBin * bin, GstDebugGraphDetails details,
587     const gchar * file_name)
588 {
589   gchar *full_file_name = NULL;
590   FILE *out;
591
592   g_return_if_fail (GST_IS_BIN (bin));
593
594   if (G_LIKELY (priv_gst_dump_dot_dir == NULL))
595     return;
596
597   if (!file_name) {
598     file_name = g_get_application_name ();
599     if (!file_name)
600       file_name = "unnamed";
601   }
602
603   full_file_name = g_strdup_printf ("%s" G_DIR_SEPARATOR_S "%s.dot",
604       priv_gst_dump_dot_dir, file_name);
605
606   if ((out = fopen (full_file_name, "wb"))) {
607     gchar *state_name = NULL;
608     gchar *param_name = NULL;
609
610     if (details & GST_DEBUG_GRAPH_SHOW_STATES) {
611       state_name = debug_dump_get_element_state (GST_ELEMENT (bin));
612     }
613     if (details & GST_DEBUG_GRAPH_SHOW_NON_DEFAULT_PARAMS) {
614       param_name = debug_dump_get_element_params (GST_ELEMENT (bin));
615     }
616
617     /* write header */
618     fprintf (out,
619         "digraph pipeline {\n"
620         "  rankdir=LR;\n"
621         "  fontname=\"sans\";\n"
622         "  fontsize=\"8\";\n"
623         "  labelloc=t;\n"
624         "  nodesep=.1;\n"
625         "  ranksep=.2;\n"
626         "  label=\"<%s>\\n%s%s%s\";\n"
627         "  node [style=filled, shape=box, fontsize=\"7\", fontname=\"sans\", margin=\"0.0,0.0\"];\n"
628         "  edge [labelfontsize=\"7\", fontsize=\"7\", fontname=\"monospace\"];\n"
629         "\n", G_OBJECT_TYPE_NAME (bin), GST_OBJECT_NAME (bin),
630         (state_name ? state_name : ""), (param_name ? param_name : "")
631         );
632     if (state_name)
633       g_free (state_name);
634     if (param_name)
635       g_free (param_name);
636
637     debug_dump_element (bin, details, out, 1);
638
639     /* write footer */
640     fprintf (out, "}\n");
641     fclose (out);
642     GST_INFO ("wrote bin graph to : '%s'", full_file_name);
643   } else {
644     GST_WARNING ("Failed to open file '%s' for writing: %s", full_file_name,
645         g_strerror (errno));
646   }
647   g_free (full_file_name);
648 }
649
650 /*
651  * _gst_debug_bin_to_dot_file_with_ts:
652  * @bin: the top-level pipeline that should be analyzed
653  * @file_name: output base filename (e.g. "myplayer")
654  *
655  * This works like _gst_debug_bin_to_dot_file(), but adds the current timestamp
656  * to the filename, so that it can be used to take multiple snapshots.
657  */
658 void
659 _gst_debug_bin_to_dot_file_with_ts (GstBin * bin, GstDebugGraphDetails details,
660     const gchar * file_name)
661 {
662   gchar *ts_file_name = NULL;
663   GstClockTime elapsed;
664
665   g_return_if_fail (GST_IS_BIN (bin));
666
667   if (!file_name) {
668     file_name = g_get_application_name ();
669     if (!file_name)
670       file_name = "unnamed";
671   }
672
673   /* add timestamp */
674   elapsed = GST_CLOCK_DIFF (_priv_gst_info_start_time,
675       gst_util_get_timestamp ());
676
677   /* we don't use GST_TIME_FORMAT as such filenames would fail on some
678    * filesystems like fat */
679   ts_file_name =
680       g_strdup_printf ("%u.%02u.%02u.%09u-%s", GST_TIME_ARGS (elapsed),
681       file_name);
682
683   _gst_debug_bin_to_dot_file (bin, details, ts_file_name);
684   g_free (ts_file_name);
685 }
686
687 #endif /* GST_DISABLE_GST_DEBUG */