Skip to content

πŸ“‰ This tool prints a bar-graph (like this: "β–β–‚β–…β–β–†β–ˆ β–‚β–ƒ ▁") of the usage of each virtual CPU in a single line using unicodes block characters.

License

rstemmer/cpubgline

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

9 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

cpubgline

Status: 🟒 Active - License: GPL v3

cpubgline shows the load of the CPU cores as Unicode^ bar graph in a single line

This tool prints a bar graph of the usage of each virtual CPU in a single line using Unicode block characters.

This line may look like β–β–‚β–…β–β–†β–ˆ β–‚β–ƒ ▁ on a hexacore CPU with hyper threading.

Installation

You should check the install.sh script before executing. The default installation path is /usr/local/bin

# Download
git clone https://github.com/rstemmer/cpubgline.git
cd cpubgline

# Build
./build.sh

# Install
sudo ./install.sh

Usage

The first time you call cpubgline it initializes itself. Then, each time you call it, it displays the usage of each CPU core during the last and the current call.

Examples

watch -n 1 cpubgline

See the tmux.conf file for an example use-case. There the CPU usage gets printed into the status line.

How it works

The tool first loads the previous CPU statistics, it got from the last run, stored in a temporary file. The file is stored at /tmp/cpubglinehist_$PARENTPID. So when using cpubgline in your command prompt or a status line, it has a unique history and does not mix up the histories with other instances of the shell or window manager.

After reading the old statistics, it reads the current from /proc/stats. The difference is used to calculate the usage:

for(int i=0; i<numofcores; i++)
{
    double active, inactive;
    active   = currstats[i].active   - prevstats[i].active  ;
    inactive = currstats[i].inactive - prevstats[i].inactive;
    usage[i] = active / (active + inactive);
}

The active value is the sum of the counter user, nice, sys, irq, softirq and steal. The inactive value is the sum of idle and iowait. Hint: To get the load instead of the usage, move the summand iowait to the cpustat->acitve sum.

Then the current statistics gets written into the history file.

Finally the bar graph gets generated by using the 8 block character of the Unicode and the space character for each virtual CPU.

About

πŸ“‰ This tool prints a bar-graph (like this: "β–β–‚β–…β–β–†β–ˆ β–‚β–ƒ ▁") of the usage of each virtual CPU in a single line using unicodes block characters.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published