diff options
author | Laurent Pinchart <laurent.pinchart@ideasonboard.com> | 2010-05-21 16:38:55 +0200 |
---|---|---|
committer | Laurent Pinchart <laurent.pinchart@ideasonboard.com> | 2010-05-21 16:38:55 +0200 |
commit | 293ec4a8813e6d7d68dc147dff102d3a61396515 (patch) | |
tree | 3eef8b74bd68bde1258d27123a44e42e74f9ad51 /media.c | |
parent | 23a9a40c33d284ee280b330b1ced9a7b6bcffd89 (diff) |
Add --print-dot option to print topology as a dot graph
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Diffstat (limited to 'media.c')
-rw-r--r-- | media.c | 81 |
1 files changed, 80 insertions, 1 deletions
@@ -201,7 +201,78 @@ int media_reset_links(struct media_device *media) return 0; } -void media_print_topology(struct media_device *media) +static void media_print_topology_dot(struct media_device *media) +{ + unsigned int i, j; + + printf("digraph board {\n"); + printf("\trankdir=TB\n"); + + for (i = 0; i < media->entities_count; ++i) { + struct media_entity *entity = &media->entities[i]; + unsigned int npads; + + switch (entity->info.type) { + case MEDIA_ENTITY_TYPE_NODE: + printf("\tn%08x [label=\"%s\", shape=box, style=filled, " + "fillcolor=yellow]\n", + entity->info.id, entity->info.name); + break; + + case MEDIA_ENTITY_TYPE_SUBDEV: + printf("\tn%08x [label=\"{{", entity->info.id); + + for (j = 0, npads = 0; j < entity->info.pads; ++j) { + if (entity->pads[j].type != MEDIA_PAD_TYPE_INPUT) + continue; + + printf("%s<port%u> %u", npads ? " | " : "", j, j); + npads++; + } + + printf("} | %s | {", entity->info.name); + + for (j = 0, npads = 0; j < entity->info.pads; ++j) { + if (entity->pads[j].type != MEDIA_PAD_TYPE_OUTPUT) + continue; + + printf("%s<port%u> %u", npads ? " | " : "", j, j); + npads++; + } + + printf("}}\", shape=Mrecord, style=filled, fillcolor=green]\n"); + break; + + default: + continue; + } + + for (j = 0; j < entity->info.links; j++) { + struct media_entity_link *link = &entity->links[j]; + + if (link->source->entity != entity) + continue; + + printf("\tn%08x", link->source->entity->info.id); + if (link->source->entity->info.type == MEDIA_ENTITY_TYPE_SUBDEV) + printf(":port%u", link->source->index); + printf(" -> "); + printf("n%08x", link->sink->entity->info.id); + if (link->sink->entity->info.type == MEDIA_ENTITY_TYPE_SUBDEV) + printf(":port%u", link->sink->index); + + if (link->flags & MEDIA_LINK_FLAG_IMMUTABLE) + printf(" [style=bold]"); + else if (!(link->flags & MEDIA_LINK_FLAG_ACTIVE)) + printf(" [style=dashed]"); + printf("\n"); + } + } + + printf("}\n"); +} + +static void media_print_topology_text(struct media_device *media) { unsigned int i, j, k; unsigned int padding; @@ -244,6 +315,14 @@ void media_print_topology(struct media_device *media) } } +void media_print_topology(struct media_device *media, int dot) +{ + if (dot) + media_print_topology_dot(media); + else + media_print_topology_text(media); +} + static int media_enum_links(struct media_device *media) { __u32 id; |