Skip to content

Instantly share code, notes, and snippets.

@lzrd
Created September 29, 2022 20:21
Show Gist options
  • Select an option

  • Save lzrd/2d686c1a38473cd7ecb7906412547391 to your computer and use it in GitHub Desktop.

Select an option

Save lzrd/2d686c1a38473cd7ecb7906412547391 to your computer and use it in GitHub Desktop.
Create priority graphs from hubris app.toml files
#!/bin/bash
# This dot files would be better generated in xtask
# where the app.toml files are already parsed
# and the necessary data structures are already
# available.
# To generate all graphs (skipping Cargo.toml files):
# for app in app/*/[a-z]*.toml; do bash priorities $app; done
which dot
APP=${1:?Provide a path to an app.toml, e.g. app/gimletlet/app.toml}
APP_NAME="$(basename $(dirname "${APP}"))_$(basename "$APP" .toml)"
declare -A RANK
declare -A TASK_PRI
declare -A TASK_SLOT
while read line
do
case "${line}" in
*tasks*)
TASK="${line#[tasks.}"
TASK="${TASK%]}"
# echo TASK="${TASK}"
;;
priority*)
PRIORITY="${line#*= }"
RANK[$PRIORITY]+=" ${TASK}"
TASK_PRI[${TASK}]="${PRIORITY}"
;;
task-slots*)
SLOTS="${line#task-slots = \[}"
SLOTS="${SLOTS%\]}"
SLOTS="${SLOTS//,/}"
SLOTS="${SLOTS//\{ /\{}"
SLOTS="${SLOTS//\{[^ ]* /}"
SLOTS="${SLOTS//\}/}"
SLOTS="${SLOTS//\"/}"
SLOTS=( "${SLOTS}" )
# echo 'SLOTS='"${SLOTS[@]}"
for slot in ${SLOTS[@]}
do
TASK_SLOT[${TASK}]+=" ${slot}"
done
PRIORITY=unknown
TASK=unknown
;;
esac
done < <(egrep '(^\[tasks\.[^.]*$|^priority|task-slots)' $APP)
{
echo "digraph PRIORITY {"
PRIORITIES=( $(echo ${!RANK[@]} | tr ' ' '\012' | sort -r -n ) )
for priority in "${PRIORITIES[@]}"
do
NODES=( ${RANK[$priority]} )
echo " {"
echo " edge [ style=invis ];"
echo " rank=same;"
for node in "${NODES[@]}"
do
echo " ${node} [ label=\"${node}\\n${priority}\", shape=box ];"
done
echo " }"
done
# echo " ${TASK} [label=\"$TASK @ $PRIORITY\"]"
for task in "${!TASK_PRI[@]}"
do
for slot in ${TASK_SLOT[$task]}
do
P1=${TASK_PRI[$task]}
P2=${TASK_PRI[$slot]}
if (( P1 <= P2 ))
then
color=red
else
color=green
fi
echo " $task -> $slot [color=\"$color\"];"
done
done
echo "}"
} | tee -i "${APP_NAME}.dot"
dot -Tsvg "${APP_NAME}.dot" > "${APP_NAME}.svg"
echo "See output in ${APP_NAME}.dot and ${APP_NAME}.svg"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment