Skip to content

Instantly share code, notes, and snippets.

@dunhamsteve
Last active August 2, 2022 14:35
Show Gist options
  • Save dunhamsteve/4d05a4f508927469ddb89cd4610695a2 to your computer and use it in GitHub Desktop.
Save dunhamsteve/4d05a4f508927469ddb89cd4610695a2 to your computer and use it in GitHub Desktop.
Process Treemap
#!/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