修改进程在指定cpu上运行:taskset -pc 3 21184
进程启动时指定CPU: taskset -c 1 ./redis-server ../redis.conf
1.统计丢包
netstat -s
root@U2:~# netstat -s -u
IcmpMsg:
InType0: 6
InType3: 2840330
InType5: 715
InType8: 11
InType11: 48
OutType0: 11
OutType3: 2832457
OutType8: 40
Udp:
1786529 packets received
312733376 packets to unknown port received
0 packet receive errors
754885510 packets sent
0 receive buffer errors
0 send buffer errors
IgnoredMulti: 16282
UdpLite:
IpExt:
OutMcastPkts: 2
InBcastPkts: 16282
InOctets: 17165483864
OutOctets: 38380998475
OutMcastOctets: 80
InBcastOctets: 1533417
InNoECTPkts: 328407033
root@U2:~#
2.总体cpu 情况
mpstat -P ALL 5 6
root@U2:~# mpstat -P ALL 5 6
Linux 5.4.0-1034-raspi (U2) 06/05/21 _aarch64_ (4 CPU)
08:08:05 CPU %usr %nice %sys %iowait %irq %soft %steal %guest %gnice %idle
08:08:10 all 1.20 0.00 23.85 0.00 0.00 0.00 0.00 0.00 0.00 74.95
08:08:10 0 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00
08:08:10 1 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00
08:08:10 2 0.00 0.00 0.20 0.00 0.00 0.00 0.00 0.00 0.00 99.80
08:08:10 3 4.80 0.00 95.20 0.00 0.00 0.00 0.00 0.00 0.00 0.00
08:08:10 CPU %usr %nice %sys %iowait %irq %soft %steal %guest %gnice %idle
08:08:15 all 1.55 0.00 23.55 0.00 0.00 0.00 0.00 0.00 0.00 74.90
08:08:15 0 0.00 0.00 0.20 0.00 0.00 0.00 0.00 0.00 0.00 99.80
08:08:15 1 0.00 0.00 0.20 0.00 0.00 0.00 0.00 0.00 0.00 99.80
08:08:15 2 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00
08:08:15 3 6.20 0.00 93.80 0.00 0.00 0.00 0.00 0.00 0.00 0.00
08:08:15 CPU %usr %nice %sys %iowait %irq %soft %steal %guest %gnice %idle
08:08:20 all 1.50 0.00 23.57 0.00 0.00 0.00 0.00 0.00 0.00 74.92
08:08:20 0 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00
08:08:20 1 0.00 0.00 0.20 0.00 0.00 0.00 0.00 0.00 0.00 99.80
08:08:20 2 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00
08:08:20 3 6.00 0.00 94.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
3.统计进程cpu
root@U2:~# pidstat -u 5 6
Linux 5.4.0-1034-raspi (U2) 06/05/21 _aarch64_ (4 CPU)
08:08:56 UID PID %usr %system %guest %wait %CPU CPU Command
08:09:01 0 1206512 4.98 95.02 0.00 0.00 100.00 3 udp_client
08:09:01 0 1206546 0.00 0.20 0.00 0.00 0.20 0 kworker/u8:2-events_power_efficient
08:09:01 0 1206626 0.20 0.00 0.00 0.00 0.20 3 kworker/3:2-events
08:09:01 0 1207254 0.00 0.40 0.00 0.00 0.40 2 pidstat
08:09:01 UID PID %usr %system %guest %wait %CPU CPU Command
08:09:06 0 1206512 6.40 93.40 0.00 0.20 99.80 3 udp_client
08:09:06 0 1207254 0.20 0.40 0.00 0.00 0.60 2 pidstat
08:09:06 UID PID %usr %system %guest %wait %CPU CPU Command
08:09:11 0 1253 0.00 0.20 0.00 0.00 0.20 2 openvpn
08:09:11 0 1206512 4.80 95.20 0.00 0.00 100.00 3 udp_client
08:09:11 0 1206626 0.20 0.00 0.00 0.00 0.20 3 kworker/3:2-events
08:09:11 0 1207254 0.00 0.40 0.00 0.00 0.40 2 pidstat
统进程中断情况
root@U2:~# pidstat -wt 1
Linux 5.4.0-1034-raspi (U2) 06/05/21 _aarch64_ (4 CPU)
08:38:04 UID TGID TID cswch/s nvcswch/s Command
08:38:06 0 9 - 1.90 0.00 ksoftirqd/0
08:38:06 0 - 9 1.90 0.00 |__ksoftirqd/0
08:38:06 0 10 - 11.43 0.00 rcu_preempt
08:38:06 0 - 10 11.43 0.00 |__rcu_preempt
08:38:06 0 18 - 2.86 0.00 ksoftirqd/1
cswch (voluntary context switches)自愿上下文切换,是指进程无法获取所需资源,导致的上下文切换。比如说, I/O、内存等系统资源不足时,就会发生自愿上下文切换。
nvcswch (non voluntary context switches)自愿上下文切换,则是指进程由于时间片已到等原因,被系统强制调度,进而发生的上下文切换。比如说,大量进程都在争抢 CPU 时,就容易发生非自愿上下文切换。
这里的切换是指切换进程,不是syscall
4.统计系统buff cache 中断 上下文切换情况
root@U2:~# vmstat 5
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
r b swpd free buff cache si so bi bo in cs us sy id wa st
3 0 0 1552384 252952 5785540 0 0 0 59 3 2 3 3 94 1 0
1 0 0 1552432 252952 5785540 0 0 0 1 412 252 1 24 75 0 0
1 0 0 1552400 252952 5785540 0 0 0 0 403 245 1 24 75 0 0
1 0 0 1552400 252952 5785540 0 0 0 0 503 357 1 24 75 0 0
1 0 0 1552392 252952 5785540 0 0 0 0 413 254 1 24 75 0 0
1 0 0 1552400 252952 5785540 0 0 0 0 496 333 1 24 75 0 0
1 0 0 1552392 252952 5785540 0 0 0 0 500 348 1 24 75 0 0
1 0 0 1552384 252952 5785540 0 0 0 0 397 240 1 24 75 0 0
5. perf top查看系统整体调用栈占用情况
perf top -g -p pid 分析进程调用栈耗时情况