LatencyTop - Track down the cause of latencies or lag on your Linux system
Sometimes, you would have noticed slowness or lag with certain applications on your system. Usually the reason is that the process/application concerned is waiting for some useful information it needs in order to continue with the execution and hence is blocked by the kernel, e.g. Web browser waiting while the webpage is being fetched, this is latency/lag. Although sometimes it could be a limited resource issue, e.g. overloaded system - total memory footprint required by all the processes is way more than the RAM could support. In such cases, data-fetching from hard disk to RAM and swapping etc. causes delay. As a developer, both kernel or userspace, you need to know the cause of such latencies. If your code is the cause of the delay then you can track down the issue and improve the code. Latencytop lets you do so.
Latencytop works on the principle of finding out the processes that are blocked by the kernel while they are waiting for some useful information. This waiting time is known as latency or lag that we see in our system. Latencytop lets you track such processes/applications along with the maximum time they have been waiting aka latency and backtrace method to let you know about the exact reasons of delay.
In the announcement of the Latencytop, 0.1 version, Arjan van de Van said,
Slow servers, Skipping audio, Jerky video --everyone knows the symptoms of latency. But to know what's really going on in the system, what's causing the latency, and how to fix it... those are difficult questions without good answers right now,
Download and Install Latencytop
If it isn't already installed on your linux system then run the following command on a terminal
[shredder12]$ sudo apt-get install latencytop # for Ubuntu/Debian based systems
[root]# yum install latencytop # for Fedora/RedHat based systems
Others can download the source tar from here.
This is one of the most useful applications with respect to a developer, but it can even be used by a user to figure out the cause of slow system.
Now, run latencytop. Please note that you will need root privileges in order to use it.
[shredder12]$ sudo latencytop
You will be presented with a window, letting you visualize latencies. The left side shows you a list of processes, sorted in the order of their latency - highest at the top. The right side shows you the latencies and their causes. The list refreshes every 30 seconds. You can refresh it in between too.
There are not any options available in the tool. For the front-end, searching for a particular process can be done by typing the initials e.g. for gnome-terminal, start by typing 'g'.