~q3cpma/dotfiles

ref: 3526232deabe1e0191e2350fbc2138af7846c331 dotfiles/.config/lemonbar/cpu_usage.awk -rw-r--r-- 382 bytes
3526232dq3cpma Whoops 6 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
function stat_read()
{
	getline <"/proc/stat"
	close("/proc/stat")
	work_prev = work
	total_prev = total
	work = $2 + $3 + $6 + $7 + $8 + $9 + $10 + $11
	total = work + $4 + $5
}

BEGIN\
{
	stat_read()
	while (1)
	{
		sleep(delay)
		split($0, old)
		stat_read()
		usage = (work - work_prev) / (total - total_prev)
		printf "p%s%02u%%\n", (usage > high ? red : ""), usage * 100
	}
}