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

CME’s Google Cloud shift skips Dallas for a 2027 Aurora move

CME Group is dropping the Dallas production stop from its livestock trading migration to Google…

6 hours ago

Teradyne’s $300M FormFactor bet dwarfs an earlier Advantest deal

Teradyne has agreed to make a $300 million equity investment in FormFactor, pairing its automated…

7 hours ago

IonQ to buy Elisity for up to $1.3B: what shareholders pay

IonQ agreed on Monday, October 12, to buy cybersecurity company Elisity for up to $1.3…

14 hours ago

ASUS Partners With Raghav Juyal in India, Highlights Free Doorstep Replacement for Accessories

ASUS has named actor and dancer Raghav Juyal as its brand ambassador in India. The…

17 hours ago

ASUS Partners With Raghav Juyal in India, Highlights Free Doorstep Replacement for Accessories

ASUS has named actor and dancer Raghav Juyal as its brand ambassador in India. The…

17 hours ago

OPPO F35 Series Debuts in India With 8,000mAh Batteries and 80W Fast Charging

OPPO has just announced the OPPO F35 Pro and OPPO F35 in India. This launch…

20 hours ago