Categories: All

cpustat – A Lightweight Process Stats Tool For Small Ubuntu Devices


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.


spatsariya

Recent Posts

Garena Free Fire Max Codes (June, 2025)

Garena Free Fire Max is one of the most popular games on the planet, and…

22 hours ago

ByteDance Nears $50B Profit Despite TikTok’s U.S. Uncertainty

The future of TikTok is a topic of heated debate among lawmakers, while users fight…

2 days ago

Meta Prepares Major AI Push With New Image, Video, and Text Models in 2026

When a company starts assigning fruits as codenames for AI models, it is an indicator…

2 days ago

Bernstein Says Nvidia Stock Is a Buy After Valuation Reset

Purchasing Nvidia at this time may be similar to requesting a dessert after a massive…

2 days ago

YouTube Suffers Global Outage, Services Quickly Restored

For a tiny fraction of time on Friday, the entire world simultaneously hit the refresh…

2 days ago

Coatue Trims Nvidia, Boosts Alphabet Stock in Strategic AI Shift

The highly influential manager of Coatue Management, Philippe Laffont also made a bold asset reallocation…

2 days ago