Commit 8fadde9d authored by Arun Raghavan's avatar Arun Raghavan

debugutils: Add a gst_debug_bin_to_dot_data() method

This provides the dot file as a string, rather than dumping to a file.

https://bugzilla.gnome.org/show_bug.cgi?id=741425
parent ed151250
......@@ -137,7 +137,7 @@ debug_dump_get_element_params (GstElement * element)
static void
debug_dump_pad (GstPad * pad, const gchar * color_name,
const gchar * element_name, GstDebugGraphDetails details, FILE * out,
const gchar * element_name, GstDebugGraphDetails details, GString * str,
const gint indent)
{
GstPadTemplate *pad_templ;
......@@ -191,12 +191,12 @@ debug_dump_pad (GstPad * pad, const gchar * color_name,
GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_FLAG_BLOCKING) ? 'B' : 'b';
pad_flags[3] = '\0';
fprintf (out,
g_string_append_printf (str,
"%s %s_%s [color=black, fillcolor=\"%s\", label=\"%s\\n[%c][%s]%s\", height=\"0.2\", style=\"%s\"];\n",
spc, element_name, pad_name, color_name, GST_OBJECT_NAME (pad),
activation_mode[pad->mode], pad_flags, task_mode, style_name);
} else {
fprintf (out,
g_string_append_printf (str,
"%s %s_%s [color=black, fillcolor=\"%s\", label=\"%s\", height=\"0.2\", style=\"%s\"];\n",
spc, element_name, pad_name, color_name, GST_OBJECT_NAME (pad),
style_name);
......@@ -207,7 +207,7 @@ debug_dump_pad (GstPad * pad, const gchar * color_name,
static void
debug_dump_element_pad (GstPad * pad, GstElement * element,
GstDebugGraphDetails details, FILE * out, const gint indent)
GstDebugGraphDetails details, GString * str, const gint indent)
{
GstElement *target_element;
GstPad *target_pad, *tmp_pad;
......@@ -235,15 +235,17 @@ debug_dump_element_pad (GstPad * pad, GstElement * element,
target_element_name = g_strdup ("");
}
debug_dump_pad (target_pad, color_name, target_element_name, details,
out, indent);
str, indent);
/* src ghostpad relationship */
pad_name = debug_dump_make_object_name (GST_OBJECT (pad));
target_pad_name = debug_dump_make_object_name (GST_OBJECT (target_pad));
if (dir == GST_PAD_SRC) {
fprintf (out, "%s%s_%s -> %s_%s [style=dashed, minlen=0]\n", spc,
g_string_append_printf (str,
"%s%s_%s -> %s_%s [style=dashed, minlen=0]\n", spc,
target_element_name, target_pad_name, element_name, pad_name);
} else {
fprintf (out, "%s%s_%s -> %s_%s [style=dashed, minlen=0]\n", spc,
g_string_append_printf (str,
"%s%s_%s -> %s_%s [style=dashed, minlen=0]\n", spc,
element_name, pad_name, target_element_name, target_pad_name);
}
g_free (target_pad_name);
......@@ -261,7 +263,7 @@ debug_dump_element_pad (GstPad * pad, GstElement * element,
GST_PAD_SINK) ? "#aaaaff" : "#cccccc");
}
/* pads */
debug_dump_pad (pad, color_name, element_name, details, out, indent);
debug_dump_pad (pad, color_name, element_name, details, str, indent);
g_free (element_name);
}
......@@ -357,7 +359,7 @@ debug_dump_describe_caps (GstCaps * caps, GstDebugGraphDetails details)
static void
debug_dump_element_pad_link (GstPad * pad, GstElement * element,
GstDebugGraphDetails details, FILE * out, const gint indent)
GstDebugGraphDetails details, GString * str, const gint indent)
{
GstElement *peer_element;
GstPad *peer_pad;
......@@ -414,13 +416,14 @@ debug_dump_element_pad_link (GstPad * pad, GstElement * element,
/* pad link */
if (media) {
fprintf (out, "%s%s_%s -> %s_%s [label=\"%s\"]\n", spc,
g_string_append_printf (str, "%s%s_%s -> %s_%s [label=\"%s\"]\n", spc,
element_name, pad_name, peer_element_name, peer_pad_name, media);
g_free (media);
} else if (media_src && media_sink) {
/* dot has some issues with placement of head and taillabels,
* we need an empty label to make space */
fprintf (out, "%s%s_%s -> %s_%s [labeldistance=\"10\", labelangle=\"0\", "
g_string_append_printf (str,
"%s%s_%s -> %s_%s [labeldistance=\"10\", labelangle=\"0\", "
"label=\" \", "
"taillabel=\"%s\", headlabel=\"%s\"]\n",
spc, element_name, pad_name, peer_element_name, peer_pad_name,
......@@ -428,7 +431,7 @@ debug_dump_element_pad_link (GstPad * pad, GstElement * element,
g_free (media_src);
g_free (media_sink);
} else {
fprintf (out, "%s%s_%s -> %s_%s\n", spc,
g_string_append_printf (str, "%s%s_%s -> %s_%s\n", spc,
element_name, pad_name, peer_element_name, peer_pad_name);
}
......@@ -444,7 +447,7 @@ debug_dump_element_pad_link (GstPad * pad, GstElement * element,
static void
debug_dump_element_pads (GstIterator * pad_iter, GstPad * pad,
GstElement * element, GstDebugGraphDetails details, FILE * out,
GstElement * element, GstDebugGraphDetails details, GString * str,
const gint indent, guint * src_pads, guint * sink_pads)
{
GValue item = { 0, };
......@@ -456,7 +459,7 @@ debug_dump_element_pads (GstIterator * pad_iter, GstPad * pad,
switch (gst_iterator_next (pad_iter, &item)) {
case GST_ITERATOR_OK:
pad = g_value_get_object (&item);
debug_dump_element_pad (pad, element, details, out, indent);
debug_dump_element_pad (pad, element, details, str, indent);
dir = gst_pad_get_direction (pad);
if (dir == GST_PAD_SRC)
(*src_pads)++;
......@@ -484,8 +487,8 @@ debug_dump_element_pads (GstIterator * pad_iter, GstPad * pad,
* Helper for gst_debug_bin_to_dot_file() to recursively dump a pipeline.
*/
static void
debug_dump_element (GstBin * bin, GstDebugGraphDetails details, FILE * out,
const gint indent)
debug_dump_element (GstBin * bin, GstDebugGraphDetails details,
GString * str, const gint indent)
{
GstIterator *element_iter, *pad_iter;
gboolean elements_done, pads_done;
......@@ -514,12 +517,14 @@ debug_dump_element (GstBin * bin, GstDebugGraphDetails details, FILE * out,
param_name = debug_dump_get_element_params (GST_ELEMENT (element));
}
/* elements */
fprintf (out, "%ssubgraph cluster_%s {\n", spc, element_name);
fprintf (out, "%s fontname=\"Bitstream Vera Sans\";\n", spc);
fprintf (out, "%s fontsize=\"8\";\n", spc);
fprintf (out, "%s style=filled;\n", spc);
fprintf (out, "%s color=black;\n\n", spc);
fprintf (out, "%s label=\"%s\\n%s%s%s\";\n", spc,
g_string_append_printf (str, "%ssubgraph cluster_%s {\n", spc,
element_name);
g_string_append_printf (str, "%s fontname=\"Bitstream Vera Sans\";\n",
spc);
g_string_append_printf (str, "%s fontsize=\"8\";\n", spc);
g_string_append_printf (str, "%s style=filled;\n", spc);
g_string_append_printf (str, "%s color=black;\n\n", spc);
g_string_append_printf (str, "%s label=\"%s\\n%s%s%s\";\n", spc,
G_OBJECT_TYPE_NAME (element), GST_OBJECT_NAME (element),
(state_name ? state_name : ""), (param_name ? param_name : "")
);
......@@ -535,30 +540,30 @@ debug_dump_element (GstBin * bin, GstDebugGraphDetails details, FILE * out,
src_pads = sink_pads = 0;
if ((pad_iter = gst_element_iterate_sink_pads (element))) {
debug_dump_element_pads (pad_iter, pad, element, details, out, indent,
&src_pads, &sink_pads);
debug_dump_element_pads (pad_iter, pad, element, details, str,
indent, &src_pads, &sink_pads);
gst_iterator_free (pad_iter);
}
if ((pad_iter = gst_element_iterate_src_pads (element))) {
debug_dump_element_pads (pad_iter, pad, element, details, out, indent,
&src_pads, &sink_pads);
debug_dump_element_pads (pad_iter, pad, element, details, str,
indent, &src_pads, &sink_pads);
gst_iterator_free (pad_iter);
}
if (GST_IS_BIN (element)) {
fprintf (out, "%s fillcolor=\"#ffffff\";\n", spc);
g_string_append_printf (str, "%s fillcolor=\"#ffffff\";\n", spc);
/* recurse */
debug_dump_element (GST_BIN (element), details, out, indent + 1);
debug_dump_element (GST_BIN (element), details, str, indent + 1);
} else {
if (src_pads && !sink_pads)
fprintf (out, "%s fillcolor=\"#ffaaaa\";\n", spc);
g_string_append_printf (str, "%s fillcolor=\"#ffaaaa\";\n", spc);
else if (!src_pads && sink_pads)
fprintf (out, "%s fillcolor=\"#aaaaff\";\n", spc);
g_string_append_printf (str, "%s fillcolor=\"#aaaaff\";\n", spc);
else if (src_pads && sink_pads)
fprintf (out, "%s fillcolor=\"#aaffaa\";\n", spc);
g_string_append_printf (str, "%s fillcolor=\"#aaffaa\";\n", spc);
else
fprintf (out, "%s fillcolor=\"#ffffff\";\n", spc);
g_string_append_printf (str, "%s fillcolor=\"#ffffff\";\n", spc);
}
fprintf (out, "%s}\n\n", spc);
g_string_append_printf (str, "%s}\n\n", spc);
if ((pad_iter = gst_element_iterate_pads (element))) {
pads_done = FALSE;
while (!pads_done) {
......@@ -567,7 +572,7 @@ debug_dump_element (GstBin * bin, GstDebugGraphDetails details, FILE * out,
pad = g_value_get_object (&item2);
if (gst_pad_is_linked (pad)) {
if (gst_pad_get_direction (pad) == GST_PAD_SRC) {
debug_dump_element_pad_link (pad, element, details, out,
debug_dump_element_pad_link (pad, element, details, str,
indent);
} else {
GstPad *peer_pad = gst_pad_get_peer (pad);
......@@ -576,7 +581,7 @@ debug_dump_element (GstBin * bin, GstDebugGraphDetails details, FILE * out,
if (!GST_IS_GHOST_PAD (peer_pad)
&& GST_IS_PROXY_PAD (peer_pad)) {
debug_dump_element_pad_link (peer_pad, NULL, details,
out, indent);
str, indent);
}
gst_object_unref (peer_pad);
}
......@@ -612,6 +617,80 @@ debug_dump_element (GstBin * bin, GstDebugGraphDetails details, FILE * out,
gst_iterator_free (element_iter);
}
static void
debug_dump_header (GstBin * bin, GstDebugGraphDetails details, GString * str)
{
gchar *state_name = NULL;
gchar *param_name = NULL;
if (details & GST_DEBUG_GRAPH_SHOW_STATES) {
state_name = debug_dump_get_element_state (GST_ELEMENT (bin));
}
if (details & GST_DEBUG_GRAPH_SHOW_NON_DEFAULT_PARAMS) {
param_name = debug_dump_get_element_params (GST_ELEMENT (bin));
}
/* write header */
g_string_append_printf (str,
"digraph pipeline {\n"
" rankdir=LR;\n"
" fontname=\"sans\";\n"
" fontsize=\"10\";\n"
" labelloc=t;\n"
" nodesep=.1;\n"
" ranksep=.2;\n"
" label=\"<%s>\\n%s%s%s\";\n"
" node [style=filled, shape=box, fontsize=\"9\", fontname=\"sans\", margin=\"0.0,0.0\"];\n"
" edge [labelfontsize=\"6\", fontsize=\"9\", fontname=\"monospace\"];\n"
" \n"
" legend [\n"
" pos=\"0,0!\",\n"
" margin=\"0.05,0.05\",\n"
" label=\"Legend\\lElement-States: [~] void-pending, [0] null, [-] ready, [=] paused, [>] playing\\lPad-Activation: [-] none, [>] push, [<] pull\\lPad-Flags: [b]locked, [f]lushing, [b]locking; upper-case is set\\lPad-Task: [T] has started task, [t] has paused task\\l\"\n,"
" ];"
"\n", G_OBJECT_TYPE_NAME (bin), GST_OBJECT_NAME (bin),
(state_name ? state_name : ""), (param_name ? param_name : "")
);
if (state_name)
g_free (state_name);
if (param_name)
g_free (param_name);
}
static void
debug_dump_footer (GString * str)
{
g_string_append_printf (str, "}\n");
}
/*
* gst_debug_bin_to_dot_data:
* @bin: the top-level pipeline that should be analyzed
*
* To aid debugging applications one can use this method to obtain the whole
* network of gstreamer elements that form the pipeline into an dot file.
* This data can be processed with graphviz to get an image.
*
* Returns: (transfer full): a string containing the pipeline in graphviz
* dot format.
*/
gchar *
gst_debug_bin_to_dot_data (GstBin * bin, GstDebugGraphDetails details)
{
GString *str;
g_return_if_fail (GST_IS_BIN (bin));
str = g_string_new (NULL);
debug_dump_header (bin, details, str);
debug_dump_element (bin, details, str, 1);
debug_dump_footer (str);
return g_string_free (str, FALSE);
}
/*
* gst_debug_bin_to_dot_file:
* @bin: the top-level pipeline that should be analyzed
......@@ -646,47 +725,14 @@ gst_debug_bin_to_dot_file (GstBin * bin, GstDebugGraphDetails details,
priv_gst_dump_dot_dir, file_name);
if ((out = fopen (full_file_name, "wb"))) {
gchar *state_name = NULL;
gchar *param_name = NULL;
gchar *buf;
if (details & GST_DEBUG_GRAPH_SHOW_STATES) {
state_name = debug_dump_get_element_state (GST_ELEMENT (bin));
}
if (details & GST_DEBUG_GRAPH_SHOW_NON_DEFAULT_PARAMS) {
param_name = debug_dump_get_element_params (GST_ELEMENT (bin));
}
buf = gst_debug_bin_to_dot_data (bin, details);
fputs (buf, out);
/* write header */
fprintf (out,
"digraph pipeline {\n"
" rankdir=LR;\n"
" fontname=\"sans\";\n"
" fontsize=\"10\";\n"
" labelloc=t;\n"
" nodesep=.1;\n"
" ranksep=.2;\n"
" label=\"<%s>\\n%s%s%s\";\n"
" node [style=filled, shape=box, fontsize=\"9\", fontname=\"sans\", margin=\"0.0,0.0\"];\n"
" edge [labelfontsize=\"6\", fontsize=\"9\", fontname=\"monospace\"];\n"
" \n"
" legend [\n"
" pos=\"0,0!\",\n"
" margin=\"0.05,0.05\",\n"
" label=\"Legend\\lElement-States: [~] void-pending, [0] null, [-] ready, [=] paused, [>] playing\\lPad-Activation: [-] none, [>] push, [<] pull\\lPad-Flags: [b]locked, [f]lushing, [b]locking; upper-case is set\\lPad-Task: [T] has started task, [t] has paused task\\l\"\n,"
" ];"
"\n", G_OBJECT_TYPE_NAME (bin), GST_OBJECT_NAME (bin),
(state_name ? state_name : ""), (param_name ? param_name : "")
);
if (state_name)
g_free (state_name);
if (param_name)
g_free (param_name);
debug_dump_element (bin, details, out, 1);
/* write footer */
fprintf (out, "}\n");
g_free (buf);
fclose (out);
GST_INFO ("wrote bin graph to : '%s'", full_file_name);
} else {
GST_WARNING ("Failed to open file '%s' for writing: %s", full_file_name,
......
......@@ -51,6 +51,7 @@ typedef enum {
/********** pipeline graphs **********/
gchar * gst_debug_bin_to_dot_data (GstBin *bin, GstDebugGraphDetails details);
void gst_debug_bin_to_dot_file (GstBin *bin, GstDebugGraphDetails details, const gchar *file_name);
void gst_debug_bin_to_dot_file_with_ts (GstBin *bin, GstDebugGraphDetails details, const gchar *file_name);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment