cpustat – A Lightweight Process Stats Tool For Small Ubuntu Devices


cpustatShort Bytes: cpustat is a lightweight tool for monitoring per-process cpu utilization (from /proc/$pid/stat) in a fast and efficient way with minimal overhead. It is ideal for small Ubuntu devices and now available in Ubuntu 15.10 Wily Werewolf.

Colin Ian King, an open source developer, has released a lightweight cpu stats monitoring tool called cpustats which he claims to be the most compact and efficient tool till date. Monitoring CPU per process is the everyday job of any devOps engineer or developer who is obsessed with the performance of his code.

There are plenty of tools such as “top” and “atop” that can show per-process CPU utilisation stats, but most of these aren’t useful on really slow low-power devices as they consume several tens of megacycles collecting and displaying the results.

cpustat, on the other hand, periodically dumps out the current CPU utilisation statistics of running processes and it has been optimised to have a minimal CPU overhead and typically uses about 35% of the CPU compared to “top”. cpustat also includes some simple statistical analysis options that can help characterise the way CPUs are being loaded.

Also read: Vifm – A Simple and Powerful Text Based File Manager for GNU/Linux

According to Colin Ian King

I developed cpustat to be compact and efficient, as well as provide enough stats to allow me to easily identify CPU sucking processes.   To optimise the code, I used tools such as perf to identify code hotspots as well as valgrind’scachegrind to identify poorly designed cache inefficient data structures.

He used fscanf() style parsing for /proc and hand-crafted numeric and string scanning parsing that saved several hundred thousand cycles per iteration. He also tweaked the hash table sizes to match the input data more appropriately and by careful re-use of heap allocations, he was able to reduce malloc()/free() calls and save some heap management overhead.

Some very frequent string lookups were replaced with hash lookups and frequently accessed data was duplicated rather than referenced indirectly to keep data local to reduce cache stalls and hence speed up data comparison lookup time.

How to build and use cpustat –

Step-1: git clone git://kernel.ubuntu.com/cking/cpustat.git.

Step-2: Go to cpustat folder and run – make and sudo make install.

Step -3: Now run cpustat. Use the manual for command line options:


Did you like this story? Tell your views in comments below.

Ananda Verma

Ananda Verma

Writes for machines mostly. Sometimes for humans too.
More From Fossbytes

Latest On Fossbytes

Find your dream job