Just wrote that python script that does the job:
#!/usr/bin/env python
import os, sys
primary_processes = { "unity-panel-service", "unity-applications-daemon", "unity-files-daemon", "unity-gwibber-daemon", "unity-music-daemon", "unity-shopping-daemon", "unity-lens-video", "hud-service", "zeitgeist-fts", "zeitgeist-datahub", "zeitgeist-daemon", "zeitgeist-fts" }
secondary_processes = { "lightdm", "X", "gnome-session", "gnome-settings-daemon", "gnome-keyring-daemon", "compiz", "pulseaudio", "gnome-fallback-mount-helper", "nautilus", "gconf-helper", "gconfd-2", "gtk-window-decorator", "indicator-printers-service", "indicator-sound-service", "indicator-session-service", "indicator-messages-service", "indicator-application-service", "ubuntu-geoip-provider", "gnome-screensaver", "gnome-pty-helper", "update-notifier", "deja-dup-monitor" }
debugOn=False
def getPID(curProc):
try:
return os.popen("pidof "+curProc).read().strip()
except:
return "0"
def getProcMemUsage(curProcID):
"""
Returns curProc's mem usage of curProcID in Kbytes
"""
if(curProcID=="0" or curProcID==""):
return 0
try:
if debugOn:
print curProcID+": "+os.popen("pmap -x "+curProcID+" | tail -1 | awk '{print $3, $2}'").read().strip()
return int(os.popen("pmap -x "+curProcID+" | tail -1 | awk '{print $3}'").read().strip())
except:
return 0
def getProcCpuUsage(curProcID):
"""
Returns curProc's % cpu usage
"""
if(curProcID=="0" or curProcID==""):
return 0
try:
percentage=os.popen("ps aux | grep "+curProcID+" | grep -v grep | awk '{print $3}'").read().strip()
if debugOn:
print curProcID+": "+percentage+"%"
return float(percentage)
except:
return 0
def KbToMb(curKB):
return "{0:.2f}".format(curKB/1024.0)
def main():
sumKB=0
sumCPU=0
if "-d" in sys.argv:
global debugOn
debugOn=True
if "-a" in sys.argv:
for proc in primary_processes :
procpid=getPID(proc)
sumKB += getProcMemUsage(procpid)
sumCPU += getProcCpuUsage(procpid)
for proc in secondary_processes :
procpid=getPID(proc)
sumKB += getProcMemUsage(procpid)
sumCPU += getProcCpuUsage(procpid)
else:
for proc in primary_processes :
procpid=getPID(proc)
sumKB += getProcMemUsage(procpid)
sumCPU += getProcCpuUsage(procpid)
if "-c" in sys.argv:
print str(KbToMb(sumKB))+" MB"
else:
print str(sumKB)+" KB"
print str(sumCPU)+"% CPU"
main()
Usage:
Just run it to tell you what unity uses (memory usage + cpu %)
E.g.
./script.py -c -d
The secondary and primary processes are global variables on the top of the script, so feel free to edit the script and include the processes that you are interested in.
PS: I find the memory usage of a process by using pmap -x, which I find to be a little... excessive (it says that my X server eats up to 70 MB), but I guess the developers of it know more than I do.
htopgive you? – drN Nov 27 '12 at 20:12grep,awk, and stuff? It'll be complicated by the fact that some things that use a lot of CPU are dependencies of Unity but also are dependencies of other things. – ObsessiveSSOℲ Nov 27 '12 at 20:32