Table of Contents

CPU on Linux Performance (top, mpstat, sar )



Check CPU Number

The number of physical CPU (The number of Socket)

# cat /proc/cpuinfo | grep "physical id" |sort
physical id     : 0
physical id     : 0
physical id     : 3
physical id     : 3

# cat /proc/cpuinfo | grep "physical id" |sort | uniq
physical id     : 0
physical id     : 3

# cat /proc/cpuinfo | grep "physical id" |sort | uniq |wc -l
2


The number of Processors.

# cat /proc/cpuinfo | grep processor
processor       : 0
processor       : 1
processor       : 2
processor       : 3

# cat /proc/cpuinfo | grep processor |wc -l
4


The number of Cores per Socket

# cat /proc/cpuinfo |grep "cpu cores"
cpu cores       : 2
cpu cores       : 2
cpu cores       : 2
cpu cores       : 2

#cat /proc/cpuinfo | grep "cpu cores" |uniq
cpu cores       : 2

# cat /proc/cpuinfo |grep "cpu cores" | perl -e 'while(<>){$n+=/(\d+)/?$1:0;}print"$n\n";'
8


The number of total core (CPU x core)

cat /proc/cpuinfo |grep "cpu cores" | perl -e 'while(<>){$n+=/(\d+)/?$1:0;}print"$n\n";'




Check Performance

top

top - 08:29:00 up 216 days, 22:29,  1 user,  load average: 0.55, 1.10, 1.17
Tasks: 135 total,   1 running, 134 sleeping,   0 stopped,   0 zombie
Cpu0  :  0.6%us,  0.3%sy,  0.0%ni, 93.6%id,  5.5%wa,  0.0%hi,  0.0%si,  0.0%st
Cpu1  :  0.6%us,  0.3%sy,  0.0%ni, 95.5%id,  3.5%wa,  0.0%hi,  0.0%si,  0.0%st
Cpu2  :  1.5%us,  0.6%sy,  0.0%ni, 76.6%id, 21.2%wa,  0.0%hi,  0.1%si,  0.0%st
Cpu3  :  0.8%us,  0.4%sy,  0.0%ni, 94.9%id,  3.8%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:   2059340k total,  1730316k used,   329024k free,   151200k buffers
Swap:  2048152k total,      148k used,  2048004k free,   950676k cached


  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
    1 root      15   0 10344  676  568 S  0.0  0.0   0:10.74 init
    1 root      15   0 10344  676  568 S  0.0  0.0   0:10.74 init
    2 root      RT  -5     0    0    0 S  0.0  0.0   0:43.41 migration/0
    3 root      34  19     0    0    0 S  0.0  0.0   0:00.07 ksoftirqd/0
    4 root      RT  -5     0    0    0 S  0.0  0.0   0:00.00 watchdog/0
    5 root      RT  -5     0    0    0 S  0.0  0.0   0:40.33 migration/1
    6 root      34  19     0    0    0 S  0.0  0.0   0:00.06 ksoftirqd/1
    7 root      RT  -5     0    0    0 S  0.0  0.0   0:00.00 watchdog/1
    8 root      RT  -5     0    0    0 S  0.0  0.0   0:42.92 migration/2
    9 root      34  19     0    0    0 S  0.0  0.0   0:01.52 ksoftirqd/2
#abbr


mpstat

user1@ubuntu20:~$ mpstat -P ALL 1
Linux 5.4.0-65-generic (ubuntu20)       03/03/2021      _x86_64_        (2 CPU)

09:36:44 AM  CPU    %usr   %nice    %sys %iowait    %irq   %soft  %steal  %guest  %gnice   %idle
09:36:45 AM  all    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00  100.00
09:36:45 AM    0    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00  100.00
09:36:45 AM    1    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00  100.00

09:36:45 AM  CPU    %usr   %nice    %sys %iowait    %irq   %soft  %steal  %guest  %gnice   %idle
09:36:46 AM  all    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00  100.00
09:36:46 AM    0    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00  100.00
09:36:46 AM    1    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00  100.00

09:36:46 AM  CPU    %usr   %nice    %sys %iowait    %irq   %soft  %steal  %guest  %gnice   %idle
09:36:47 AM  all    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00  100.00
09:36:47 AM    0    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00  100.00
09:36:47 AM    1    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00  100.00

09:36:47 AM  CPU    %usr   %nice    %sys %iowait    %irq   %soft  %steal  %guest  %gnice   %idle
09:36:48 AM  all    0.50    0.00    0.00    0.00    0.00    0.00    0.50    0.00    0.00   99.01
09:36:48 AM    0    0.99    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00   99.01
09:36:48 AM    1    0.00    0.00    0.00    0.00    0.00    0.00    0.99    0.00    0.00   99.01
^C
Average:     CPU    %usr   %nice    %sys %iowait    %irq   %soft  %steal  %guest  %gnice   %idle
Average:     all    0.12    0.00    0.00    0.00    0.00    0.00    0.12    0.00    0.00   99.75
Average:       0    0.25    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00   99.75
Average:       1    0.00    0.00    0.00    0.00    0.00    0.00    0.25    0.00    0.00   99.75


sar

user1@ubuntu20:~$ sar 1
Linux 5.4.0-65-generic (ubuntu20)       03/03/2021      _x86_64_        (2 CPU)

09:34:15 AM     CPU     %user     %nice   %system   %iowait    %steal     %idle
09:34:16 AM     all      0.00      0.00      0.00      0.00      0.00    100.00
09:34:17 AM     all      0.00      0.00      0.00      0.00      0.00    100.00
09:34:18 AM     all      0.00      0.00      0.00      0.00      0.00    100.00
09:34:19 AM     all      3.03      0.00      1.52      0.00      0.00     95.45
09:34:20 AM     all      0.00      0.00      0.00      0.00      0.00    100.00
09:34:21 AM     all      0.00      0.00      0.00      0.00      0.00    100.00
09:34:22 AM     all      0.00      0.00      0.00      0.00      0.00    100.00
09:34:23 AM     all      0.00      0.00      0.00      0.00      0.00    100.00
09:34:24 AM     all      0.00      0.00      0.00      0.00      0.00    100.00
09:34:25 AM     all      0.00      0.00      0.00      0.00      0.00    100.00
^C

Average:        all      0.30      0.00      0.15      0.00      0.00     99.55
user1@ubuntu20:~$
user1@ubuntu20:~$ sar -P ALL 1
Linux 5.4.0-65-generic (ubuntu20)       03/03/2021      _x86_64_        (2 CPU)

09:35:40 AM     CPU     %user     %nice   %system   %iowait    %steal     %idle
09:35:41 AM     all      0.00      0.00      0.00      0.00      0.00    100.00
09:35:41 AM       0      0.00      0.00      0.00      0.00      0.00    100.00
09:35:41 AM       1      0.00      0.00      0.00      0.00      0.00    100.00

09:35:41 AM     CPU     %user     %nice   %system   %iowait    %steal     %idle
09:35:42 AM     all      0.00      0.00      0.00      0.00      0.00    100.00
09:35:42 AM       0      0.00      0.00      0.00      0.00      0.00    100.00
09:35:42 AM       1      0.00      0.00      0.00      0.00      0.00    100.00

09:35:42 AM     CPU     %user     %nice   %system   %iowait    %steal     %idle
09:35:43 AM     all      0.00      0.00      0.00      0.00      0.00    100.00
09:35:43 AM       0      0.00      0.00      0.00      0.00      0.00    100.00
09:35:43 AM       1      0.00      0.00      0.00      0.00      0.00    100.00

09:35:43 AM     CPU     %user     %nice   %system   %iowait    %steal     %idle
09:35:44 AM     all      0.00      0.00      0.50      0.00      0.00     99.50
09:35:44 AM       0      0.00      0.00      0.00      0.00      0.00    100.00
09:35:44 AM       1      0.00      0.00      0.99      0.00      0.00     99.01
^C

Average:        CPU     %user     %nice   %system   %iowait    %steal     %idle
Average:        all      0.00      0.00      0.13      0.00      0.00     99.87
Average:          0      0.00      0.00      0.00      0.00      0.00    100.00
Average:          1      0.00      0.00      0.25      0.00      0.00     99.75




Related Pages