Commit | Line | Data |
---|---|---|
2b05907b SK |
1 | #! /bin/bash |
2 | ||
3 | target_module="$1" | |
15f22284 SK |
4 | target_fun_regex="$2" |
5 | shift 2 | |
2b05907b SK |
6 | dirs=$@ |
7 | ||
8 | find $dirs -type f -name '*.erl' -exec grep -Hn "\<$target_module\>:" '{}' \; \ | |
9 | | sed 's/%.*$//g' \ | |
15f22284 SK |
10 | | awk \ |
11 | -F "${target_module}:" \ | |
12 | -v target_module="$target_module" \ | |
13 | -v target_fun_regex="$target_fun_regex" ' | |
2b05907b SK |
14 | $1 && $2 { |
15 | caller_module_file = $1 | |
16 | sub(":.*$", "", caller_module_file) | |
17 | ||
18 | called_function = $2 | |
19 | sub("\\(.*$", "", called_function) | |
20 | ||
21 | if (called_function ~ /^[a-z][a-zA-Z_0-9]+$/) { | |
fc84ff9c | 22 | if (called_function ~ target_fun_regex) { |
4cc39e2a | 23 | Calls[called_function]++ |
fc84ff9c SK |
24 | Calls_from[caller_module_file, called_function]++ |
25 | Caller_modules[caller_module_file]++ | |
26 | } | |
2b05907b SK |
27 | } else { |
28 | printf \ | |
29 | "[WARN] skipped an invalid erlang function name. File: \"%s\", function: \"%s\", original line: \"%s\"\n", \ | |
30 | caller_module_file, called_function, $0 \ | |
31 | > "/dev/stderr" | |
32 | } | |
33 | } | |
34 | ||
35 | END { | |
36 | indent = " " | |
4cc39e2a SK |
37 | |
38 | print "group-by-caller" | |
2b05907b | 39 | for (caller_module_file in Caller_modules) { |
4cc39e2a | 40 | printf "%s%s\n", indent, caller_module_file; |
2b05907b SK |
41 | for (cf in Calls_from) { |
42 | split(cf, call, SUBSEP); | |
fc84ff9c | 43 | if (call[1] == caller_module_file) |
c10264d1 | 44 | printf "%s%s %d\n", indent indent, call[2], Calls_from[cf] | "sort"; |
2b05907b SK |
45 | } |
46 | close("sort") | |
47 | } | |
48 | ||
4cc39e2a | 49 | print "all" |
2b05907b | 50 | for (called_function in Calls) |
c10264d1 | 51 | printf "%s%s %d\n", indent, called_function, Calls[called_function] | "sort" |
2b05907b SK |
52 | close("sort") |
53 | }' |