Skip to content

Instantly share code, notes, and snippets.

@justdoit0823
Last active July 22, 2020 07:42
Show Gist options
  • Save justdoit0823/863bc33a7964d9b3153d4b65676c16cb to your computer and use it in GitHub Desktop.
Save justdoit0823/863bc33a7964d9b3153d4b65676c16cb to your computer and use it in GitHub Desktop.
Linux process segment memory usage stat script.
# total threads memory
grep -A 2 'stack:' /proc/$PID/smaps|grep Rss|awk '{m += $2} END {print m}'
# top ten threads
grep -A 2 'stack:' /proc/$PID/smaps|grep -v -- '--'|awk '{if(index($0, "stack")) {split($NF, a, "stack:"); split(a[2], b, "]"); s[i++] = b[1]} if(index($0, "Rss")) {v[b[1]] = $2}} END {for(t in s) print s[t], v[s[t]]}'|sort -k 2 -nr|head
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment