5 ['--out']='report' # report | edges | graph
18 if [ -v opts
["$key"] ]
26 echo "Option $key requires an argument" >&2
30 echo "Unknown option: $key" >&2
41 target_fun_regex
="${opts['--fun']}"
42 output_type
="${opts['--out']}"
45 printf '[DEBUG] target_module : "%s"\n' "$target_module" >&2
46 printf '[DEBUG] target_fun_regex : "%s"\n' "$target_fun_regex" >&2
47 printf '[DEBUG] dirs : "%s"\n' "$dirs" >&2
48 printf '[DEBUG] output_type : "%s"\n' "$output_type" >&2
50 find $dirs -type f
-name '*.erl' -exec grep -Hn "\<$target_module\>:" '{}' \
; \
53 -F "${target_module}:" \
54 -v target_module
="$target_module" \
55 -v output_type
="$output_type" \
56 -v target_fun_regex
="$target_fun_regex" '
58 caller_module_file = $1
59 sub(":.*$", "", caller_module_file)
62 sub("\\(.*$", "", called_function)
64 if (called_function ~ /^[a-z][a-zA-Z_0-9]+$/) {
65 if (called_function ~ target_fun_regex) {
66 Calls[called_function]++
67 Calls_from[caller_module_file, called_function]++
68 Caller_modules[caller_module_file]++
72 "[WARN] skipped an invalid erlang function name. File: \"%s\", function: \"%s\", original line: \"%s\"\n", \
73 caller_module_file, called_function, $0 \
79 if (output_type == "report") {
81 } else if (output_type == "edges") {
83 } else if (output_type == "graph") {
85 vertices() # Vertices must be printed before edges, else records arent recognized.
89 printf "[ERROR] Unknown output type: \"%s\"\n", output_type > "/dev/stderr"
94 printf "node [shape=record];\n"
95 printf "%s [label=\"", target_module;
97 for (called_fun in Calls) {
98 printf "%s<%s> %s", sep, called_fun, called_fun
105 for (cf in Calls_from) {
106 split(cf, call, SUBSEP)
108 called_mod = target_module
110 printf("\"%s\" -> %s:%s\n", caller_mod, called_mod, called_fun)
116 print "group-by-caller"
117 for (caller_module_file in Caller_modules) {
118 printf "%s%s\n", indent, caller_module_file;
119 sort = "sort -n -k 2 -r | column -t | sed \"s/^/" indent indent "/\""
120 for (cf in Calls_from) {
121 split(cf, call, SUBSEP);
122 if (call[1] == caller_module_file)
123 printf "%s %d\n", call[2], Calls_from[cf] | sort;
129 sort = "sort -n -k 2 -r | column -t | sed \"s/^/" indent "/\""
130 for (called_function in Calls)
131 printf "%s %d\n", called_function, Calls[called_function] | sort
This page took 0.088872 seconds and 4 git commands to generate.