Thursday 19 April 2018

Different tools to monitor memory utilization in Linux

There are plenty of tools when it comes to monitoring memory usage. The main purpose of using tools like these is to identify any leaks and to know any performance issue that can occur to our program.

Linux natively has tools like 'top', 'pmap' etc. Apart from that Java provides a tool called 'jconsole', I love this tool than any other tool.


1 top

This command is very much similar to what we see in Windows Task Manager. This one shows the real-time memory usage and CPU utilization by each process. We can also monitor for a particular process by passing 'pid' as a command argument. 

$top


Use this command if you would like to monitor all the process


$top -p 29257


Use this one if you would like to monitor for a particular process


$top -p 29257 -b >  /home/venkatesh/memory_footprint.txt


If you would like to record the memory utilization over time, then execute the top command with '-b' option which will output the status ever 'n' seconds

As you can see from the output, it will just tell the percentage of utilization and it will not break the process any further.


2 pmap

pmap will give the snapshot of the process's memory map. It even provides addresses of the each jar that this process has. What I understand is, it is showing only the static memory usage by the processor and does not tells how much it is taking at runtime. 

$pmap -x 29257


We can also get the memory map for multiple processes as well.


3 jconsole

This can be used to monitor only java processes. It gives a clear breakdown of HeapMemory usage, Number of threads, classes, CPU usage, when GC kicked in. All these are real-time information that it shows


$jconsole 29257




4 Oracle Java Mission Control