Skip to content

Instantly share code, notes, and snippets.

@kaechele
Last active February 23, 2024 01:20
Show Gist options
  • Save kaechele/f10aef2c5cebc0abb8ab29bbfc283ebc to your computer and use it in GitHub Desktop.
Save kaechele/f10aef2c5cebc0abb8ab29bbfc283ebc to your computer and use it in GitHub Desktop.
Visualize ALSA ASoC DAPM routings on remote Android devices via ADB
#!/bin/bash
#
# Copyright 2011, 2012, 2013 Wolfson Microelectronics plc
# Author: Dimitris Papastamos <dp@opensource.wolfsonmicro.com>
#
# 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 outfile[.png]" 1>&2
echo "" 1>&2
echo " If the outfile ends with .png then a PNG file is created" 1>&2
echo " using dot executable, otherwise the outfile will contain" 1>&2
echo " the dot representation." 1>&2
exit 1
fi
widgets="$1"
outfile="$2"
graphviztmp=$(mktemp)
trap "{ rm -f $graphviztmp; exit 1; }" SIGINT SIGTERM EXIT
widget_active() {
local w="$1"
adb shell 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"
adb shell find \"$widgets\" -type f | while read widget; do
echo -n "Parsing widget $widget..."
adb shell -n cat \"$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")
sink=$(basename "$widget")
if [ "$active" -eq 1 ]; then
echo -e "\t\"$source\" [color = green]" >>"$graphviztmp"
echo -e "\t\"$sink\" [color = green]" >>"$graphviztmp"
else
echo -e "\t\"$source\" [color = red]" >>"$graphviztmp"
echo -e "\t\"$sink\" [color = red]" >>"$graphviztmp"
fi
echo -e "\t\"$source\" -> \"$sink\"" >>"$graphviztmp"
done
echo "OK!"
done
echo "}" >>"$graphviztmp"
echo ""
if [ "${outfile##*.}" = "png" ]; then
echo -n "Generating $outfile..."
dot -Kfdp -Tpng "$graphviztmp" -o "$outfile"
echo "OK!"
else
mv "$graphviztmp" "$outfile"
chmod a=rw "$outfile"
echo "Generate PNG with:"
echo "dot -Kfdp -Tpng $outfile -o $outfile.png"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment