Added topcpu and topmem along with readme info

master
Steven Saus 5 years ago
parent cdc480da8f
commit 9f952144bd
  1. 18
      README.md
  2. 43
      topcpu.sh
  3. 43
      topmem.sh

@ -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.

@ -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

@ -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
Loading…
Cancel
Save