Last active
August 2, 2022 14:35
-
-
Save dunhamsteve/4d05a4f508927469ddb89cd4610695a2 to your computer and use it in GitHub Desktop.
Process Treemap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# This script generates a treemap of the current memory usage (RSS) | |
awkcode=' | |
$1 == "PID" { next } | |
/.*/ { | |
cmd = substr($0,index($0,$4)); | |
sub(/.*\//,"",cmd); | |
gsub(/\//,"_",cmd); | |
cmds[$1] = cmd; | |
ppid[$1] = $2; | |
size[$1] = $3; | |
} | |
END { | |
for (id in cmds) { | |
mem = size[id]*1024; | |
path = id ":" cmds[id]; | |
while (id = ppid[id]) { | |
path = id ":" cmds[id] "/" path; | |
} | |
print mem, path; | |
} | |
} | |
' | |
ps -axo pid,ppid,rss,comm | awk "$awkcode" | npx webtreemap-cli |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment