Graphing a process's memory usage

怎甘沉沦 提交于 2019-12-02 14:03:25
LovesTha

I couldn't find any real tools to do it.

But I have found a neat small set of scripts that'll do it.

Using this little bash loop to do the logging:

while true; do
ps -C <ProgramName> -o pid=,%mem=,vsz= >> /tmp/mem.log
gnuplot /tmp/show_mem.plt
sleep 1
done &

This will create a nice little log file of memory usage called /tmp/mem.log. Then it generates an image of the data with gnuplot using the following script (put this in /tmp/show_mem.plt):

set term png small size 800,600
set output "mem-graph.png"

set ylabel "VSZ"
set y2label "%MEM"

set ytics nomirror
set y2tics nomirror in

set yrange [0:*]
set y2range [0:*]

plot "/tmp/mem.log" using 3 with lines axes x1y1 title "VSZ", \
     "/tmp/mem.log" using 2 with lines axes x1y2 title "%MEM"

Then opening the image with the default GNOME image viewer it keeps reloading the image when it changes. So if all the above loop is backgrounded it will appear that you have an amazing memory usage graphing tool running within an image viewer :)

The process I'm tracking right now looks like this:

It looks like I do have some memory issues :(

Much of this was ripped from http://brunogirin.blogspot.com.au/2010/09/memory-usage-graphs-with-ps-and-gnuplot.html, credit where it is due.

I really like using "htop" instead of "top". It's very colorful and has a lot of options like setup, search, invert, tree, sort by, nice, kill. Give it a try:

$ sudo apt-get install htop

The accepted answer worked for me, but i was a bit tired to do all this stuff any time i want to measure memory, so i've created a small tool for this:

https://github.com/parikls/mem_usage_ui

Top will do the trick

top -b | grep {name of process}
top -b -p {PID}
top -b -u {userid}

Try running the command "top" in the command line. This will display a list of processes similar to the windows task manager.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!