diff --git a/README.md b/README.md index e8516bc..64af086 100644 --- a/README.md +++ b/README.md @@ -11,3 +11,21 @@ Google or Amazon or Apple. The post detailing this is at To dynamically create a list of virtualbox VM's (and allow you to run them) as an OpenBox pipe menu + +## topmem.sh and topcpu.sh + +While these aren't exactly *speedy* or *optimized*, they do what I want; +they show me the top five memory using (or CPU using, respectively) +*commands*. That is, it lumps all `vivaldi-bin` or `firefox-bin` +processes together before doing the calculation and sort. That way I can +see what commands are eating up everything. + +A small note - processes from bash, python, and java (at present) are +not *excluded*, but the command they're *running* is what is counted. So +for example, these three commands: + +`/usr/bin/python /usr/share/kupfer/kupfer.py --no-splash` +`/usr/bin/python /usr/bin/autokey-gtk` +`/usr/bin/python /usr/bin/dstat -c -C 0,1,total -d -s -n -y -r` + +are *not* lumped together, but are treated as separate commands. diff --git a/topcpu.sh b/topcpu.sh new file mode 100644 index 0000000..7839ba4 --- /dev/null +++ b/topcpu.sh @@ -0,0 +1,43 @@ +#!/bin/bash + +ps aux | awk '{ for (i=11; i<=NF; i++) printf("%s ",$i)} {print ""}' |\ +while read i +do + STRING=$(echo "$i" | awk -F ' ' '{print $1}' ) + STRING=${STRING##*( )} + case "$STRING" in + [*) + string2=$(echo "$STRING" | cut -c 2- | rev | cut -c 2- | rev) + ;; + -*) + string2=$(echo "$STRING" | cut -c 2- ) + ;; + *) + string2=$(basename "$STRING") + ;; + esac + + case "$string2" in + bash*|python*|java*) + string3=$(echo "$i" | awk -F ' ' '{print $2}' ) + if [ -n "$string3" ];then + tmpcmd=$(basename $string2) + else + tmpcmd=$(echo $string2) + fi + ;; + *) + tmpcmd=$(echo $string2) + ;; + esac + echo "$tmpcmd" + +done | sort | uniq |\ +while read q +do + if [ -n "$q" ];then + cmdmem=$(ps -C "$q" --no-headers -o pmem | xargs | sed -e 's/ /+/g' | bc) + cmdcpu=$(ps -C "$q" --no-headers -o pcpu | xargs | sed -e 's/ /+/g' | bc) + echo "CPU $cmdcpu MEM $cmdmem CMD $q" + fi +done | sort -r -s -n -k 2 | head -5 diff --git a/topmem.sh b/topmem.sh new file mode 100644 index 0000000..c3a2515 --- /dev/null +++ b/topmem.sh @@ -0,0 +1,43 @@ +#!/bin/bash + +ps aux | awk '{ for (i=11; i<=NF; i++) printf("%s ",$i)} {print ""}' |\ +while read i +do + STRING=$(echo "$i" | awk -F ' ' '{print $1}' ) + STRING=${STRING##*( )} + case "$STRING" in + [*) + string2=$(echo "$STRING" | cut -c 2- | rev | cut -c 2- | rev) + ;; + -*) + string2=$(echo "$STRING" | cut -c 2- ) + ;; + *) + string2=$(basename "$STRING") + ;; + esac + + case "$string2" in + bash*|python*) + string3=$(echo "$i" | awk -F ' ' '{print $2}' ) + if [ -n "$string3" ];then + tmpcmd=$(basename $string2) + else + tmpcmd=$(echo $string2) + fi + ;; + *) + tmpcmd=$(echo $string2) + ;; + esac + echo "$tmpcmd" + +done | sort | uniq |\ +while read q +do + if [ -n "$q" ];then + cmdmem=$(ps -C "$q" --no-headers -o pmem | xargs | sed -e 's/ /+/g' | bc) + cmdcpu=$(ps -C "$q" --no-headers -o pcpu | xargs | sed -e 's/ /+/g' | bc) + echo "CPU $cmdcpu MEM $cmdmem CMD $q" + fi +done | sort -r -s -n -k 4 | head -5