neels has uploaded this change for review. (
https://gerrit.osmocom.org/c/libosmocore/+/31266 )
Change subject: add contrib/talloc_count.sh
......................................................................
add contrib/talloc_count.sh
When a user reports a memory leak with a talloc report, this script is
useful to quickly get a handle of what is being leaked. The alternative
is eyeballing the talloc report for a very long time.
Change-Id: I5b3242dd6e0649925ac6abfd1e96625c682b8934
---
A contrib/talloc_count.sh
1 file changed, 43 insertions(+), 0 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/66/31266/1
diff --git a/contrib/talloc_count.sh b/contrib/talloc_count.sh
new file mode 100755
index 0000000..ca0cc24
--- /dev/null
+++ b/contrib/talloc_count.sh
@@ -0,0 +1,43 @@
+#!/bin/sh
+#
+# Print a summary of how often each named object appears in a talloc report.
+#
+# usage:
+# talloc_count.sh my_talloc_report.txt
+# or:
+# osmo_interact_vty.py -p 4242 -c 'show talloc-context application full' |
talloc_count.sh
+#
+# produces output like:
+# 1 = struct foo
+# 1 = struct log_info
+# 1 = struct log_info_cat
+# 21 = msgb
+# 1391 = SCCP-SCOC(N)[N]
+# 1402 = struct osmo_fsm_inst
+# [...]
+
+f="$1"
+
+tmpdir="$(mktemp -d)"
+trap "rm -rf \"$tmpdir\"" EXIT
+
+# without input file, read stdin
+if [ "x$f" = "x" ]; then
+ f="$tmpdir/input"
+ cat > $f
+fi
+
+mangled="$tmpdir/mangled"
+grep contains "$f" | sed 's/[ \t]*contains.*//' | sed 's/^[
\t]*//' | sed 's/[ \t][ \t]*/ /g' | grep -v '^$' | grep -v
'^[0-9]\+$' | sed 's/0x[0-9a-fA-F]\+/N/g' | sed 's/[0-9]\+/N/g' |
sort > "$mangled"
+
+count() {
+ name="$1"
+ nr="$(grep -Fx "$name" "$mangled" | wc -l)"
+ printf "%6d = $name\\n" $nr
+}
+
+{
+ cat "$mangled" | uniq | while read type; do
+ count "$type"
+ done
+} | sort -h
--
To view, visit
https://gerrit.osmocom.org/c/libosmocore/+/31266
To unsubscribe, or for help writing mail filters, visit
https://gerrit.osmocom.org/settings
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: I5b3242dd6e0649925ac6abfd1e96625c682b8934
Gerrit-Change-Number: 31266
Gerrit-PatchSet: 1
Gerrit-Owner: neels <nhofmeyr(a)sysmocom.de>
Gerrit-MessageType: newchange