这就是我最终这样做的方式(免责声明:很多都是hack-ish,所以如果你要长期使用它,你可能需要清理一下)......
假设: - 当前目录包含所有有问题的脚本/二进制文件。- 用于构建图形的文件位于 subdir call_graph 中。
创建脚本 call_graph/make_tgf.sh:
#!/bin/bash
# Run from dir with scripts and subdir call_graph
# Parameters:
# $1 = sources (default is call_graph/sources.txt)
# $2 = targets (default is call_graph/targets.txt)
SOURCES=$1
if [ "$SOURCES" == "" ]; then SOURCES=call_graph/sources.txt; fi
TARGETS=$2
if [ "$TARGETS" == "" ]; then TARGETS=call_graph/targets.txt; fi
if [ ! -d call_graph ]; then echo "Run from parent dir of call_graph" >&2; exit 1; fi
(
# cat call_graph/targets.txt
for file in `cat $SOURCES `
do
for target in `grep -v -E '^ *#' $file | grep -o -F -w -f $TARGETS | grep -v -w $file | sort | uniq`
do echo $file $target
done
done
)
然后,我运行了以下命令(我最终做了仅脚本版本):
cat /dev/null | tee call_graph/sources.txt > call_graph/targets.txt
for file in *
do
if [ -d "$file" ]; then continue; fi
echo $file >> call_graph/targets.txt
if file $file | grep text >/dev/null; then echo $file >> call_graph/sources.txt; fi
done
# For scripts only:
bash call_graph/make_tgf.sh call_graph/sources.txt call_graph/sources.txt > call_graph/scripts.tgf
# For scripts + binaries (binaries will be leaf nodes):
bash call_graph/make_tgf.sh > call_graph/scripts_and_bin.tgf
然后我在yEd中打开生成的 tgf 文件,并让 yEd 进行布局(布局 -> 分层)。我保存为 graphml 以将手动可编辑的文件与自动生成的文件分开。
我发现有些节点在图中没有帮助,例如到处调用的实用程序脚本/二进制文件。所以,我从源/目标文件中删除了这些,并根据需要重新生成,直到我喜欢节点集。
希望这可以帮助某人...