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

Dell and Micron are up more than 125% for 2026; Nvidia is down 19%

November's slide in AI stocks left a lopsided year. Of 15 large AI hardware makers…

6 hours ago

Oracle’s November share buyers are down 7.6%; its new bonds pay up to 8.65%

Investors who bought Oracle shares in the company's $20 billion stock and bond sale on…

8 hours ago

CoreWeave ends November worth $24.6 billion, about half its $46.9 billion debt

CoreWeave, which rents out AI computing power, ended November with a stock-market value of about…

9 hours ago

vivo X500 Review: A Phone That Makes You Want to Take Photos Again

Over the past 4 years of reviewing phones (it’s been a long time, I know),…

10 hours ago

AI hardware stocks lost $1.9 trillion in November; five big AI spenders lost $167 billion

Nvidia and nine other U.S.-listed AI hardware stocks lost about $1.91 trillion of market value…

12 hours ago

Marvell, Broadcom and Micron report in December, shares down up to 42% since guidance

Marvell, Broadcom and Micron, three chipmakers whose sales are closely tied to AI spending, report…

14 hours ago