blob: 61aa3f5789b6e6da561b78370869a795073580e0 [file] [log] [blame]
Neels Hofmeyr69391692023-02-09 14:39:11 +01001#!/bin/sh
2#
3# Print a summary of how often each named object appears in a talloc report.
4#
5# usage:
6# talloc_count.sh my_talloc_report.txt
7# or:
8# osmo_interact_vty.py -p 4242 -c 'show talloc-context application full' | talloc_count.sh
9#
10# produces output like:
11# 1 struct foo
12# 1 struct log_info
13# 1 struct log_info_cat
14# 21 msgb
15# 1391 SCCP-SCOC(N)[N]
16# 1402 struct osmo_fsm_inst
17# [...]
18
19f="$1"
20
21tmpdir="$(mktemp -d)"
22trap "rm -rf \"$tmpdir\"" EXIT
23
24# without input file, read stdin
25if [ "x$f" = "x" ]; then
26 f="$tmpdir/input"
27 cat > $f
28fi
29
30mangled="$tmpdir/mangled"
31grep contains "$f" \
32 | sed 's/[ \t]*contains.*//' \
33 | sed 's/^[ \t]*//' \
34 | sed 's/[ \t][ \t]*/ /g' \
35 | grep -v '^$' \
36 | grep -v '^[0-9]\+$' \
37 | sed 's/0x[0-9a-fA-F]\+/N/g' \
Neels Hofmeyre1c4f242023-03-13 16:10:03 +010038 | sed 's/\<[0-9a-fA-F]\+\>/N/g' \
Neels Hofmeyr69391692023-02-09 14:39:11 +010039 | sed 's/[0-9]\+/N/g' \
40 | sort \
41 > "$mangled"
42
43count() {
44 name="$1"
45 nr="$(grep -Fx "$name" "$mangled" | wc -l)"
46 printf "%6d $name\\n" $nr
47}
48
49{
50 cat "$mangled" | uniq | while read type; do
51 count "$type"
52 done
53} | sort -h