#!/bin/bash # # Copyright 2011, 2012, 2013 Wolfson Microelectronics plc # Author: Dimitris Papastamos # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License version 2 as # published by the Free Software Foundation. # # A tool to generate a visual graph of the current DAPM configuration. # Active paths are shown in green, inactive in red. # # This program requires `graphviz' to be installed. if [ $# -ne 2 ]; then echo "usage: $(basename $0) dapm-debugfs-path out-png" 1>&2 exit 1 fi widgets="$1" outpng="$2" graphviztmp=$(mktemp) trap "{ rm -f $graphviztmp; exit 1; }" SIGINT SIGTERM EXIT widget_active() { local w="$1" head -1 "$w" | grep -q ': On' if [ "$?" -eq 0 ]; then echo 1 else echo 0 fi } echo "digraph G {" > "$graphviztmp" echo -e "\tbgcolor = grey" >> "$graphviztmp" cd "$widgets" for widget in *; do echo -n "Parsing widget $widget..." while read line; do echo "${line}" | grep -q '^in' if [ ! "$?" -eq 0 ]; then continue fi source=$(echo "$line" | awk -F\" '{print $4}') active=$(widget_active "$widget") if [ "$active" -eq 1 ]; then echo -e "\t\"$source\" [color = green]" >> "$graphviztmp" echo -e "\t\"$widget\" [color = green]" >> "$graphviztmp" else echo -e "\t\"$source\" [color = red]" >> "$graphviztmp" echo -e "\t\"$widget\" [color = red]" >> "$graphviztmp" fi echo -e "\t\"$source\" -> \"$widget\"" >> "$graphviztmp" done < "$widget" echo "OK!" done cd - >/dev/null echo "}" >> "$graphviztmp" echo -n "Generating $outpng..." dot -Kfdp -Tpng "$graphviztmp" -o "$outpng" echo "OK!"