1. 系统层面
查看cpu占用命令top -c
:
> top
top - 20:41:20 up 3 days, 23 min, 0 users, load average: 0.52, 0.58, 0.59
Tasks: 27 total, 1 running, 16 sleeping, 0 stopped, 10 zombie
%Cpu(s): 5.0 us, 10.3 sy, 0.0 ni, 84.2 id, 0.0 wa, 0.6 hi, 0.0 si, 0.0 st
MiB Mem : 16278.2 total, 3836.5 free, 16278.2 used, 224.0 buff/cache
MiB Swap: 12718.9 total, 10941.9 free, 1776.9 used. 3929.9 avail Mem
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
1 root 20 0 8952 324 280 S 0.0 0.0 0:00.06 init
14 root 20 0 15564 2916 2688 S 0.0 0.0 0:00.26 bash
15923 dnsmasq 20 0 18400 892 772 S 0.0 0.0 0:00.00 dnsmasq
15939 dnsmasq 20 0 18400 892 772 S 0.0 0.0 0:00.01 dnsmasq
15944 dnsmasq 20 0 18400 896 772 S 0.0 0.0 0:00.00 dnsmasq
16662 root 20 0 476032 234972 1816 S 0.0 1.4 0:10.38 skynet
16682 root 20 0 0 0 0 Z 0.0 0.0 0:00.00 sh
查看内存使用命令free -h
:
> free -h
total used free shared buff/cache available
Mem: 15Gi 15Gi 3.6Gi 17Mi 223Mi 3.7Gi
Swap: 12Gi 1.7Gi 10Gi
查看硬盘占用命令df -h
:
> df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 927M 0 927M 0% /dev
tmpfs 945M 16K 945M 1% /dev/shm
tmpfs 945M 536K 944M 1% /run
tmpfs 945M 0 945M 0% /sys/fs/cgroup
/dev/vda1 40G 16G 23G 41% /
tmpfs 945M 4.0K 945M 1% /tmp
查看网络IO情况命令:
按磁盘来看iostat
> iostat
Linux 5.10.134-17.al8.x86_64 11/15/2024 _x86_64_ (2 CPU)
avg-cpu: %user %nice %system %iowait %steal %idle
1.32 0.02 0.69 0.10 0.00 97.87
Device tps kB_read/s kB_wrtn/s kB_read kB_wrtn
vda 3.95 86.35 19.54 171946190 38904053
按进程来看iotop
> yum install -y iotop
> iotop
Total DISK READ : 0.00 B/s | Total DISK WRITE : 0.00 B/s
Actual DISK READ: 0.00 B/s | Actual DISK WRITE: 0.00 B/s
TID PRIO USER DISK READ DISK WRITE SWAPIN IO> COMMAND
1 be/4 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % systemd --switched-root --system --deserialize 17
2 be/4 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % [kthreadd]
3 be/0 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % [rcu_gp]
4 be/0 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % [rcu_par_gp]
6 be/0 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % [kworker/0:0H-kblockd]
8 be/0 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % [mm_percpu_wq]
9 be/4 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % [rcu_tasks_rude_]
10 be/4 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % [rcu_tasks_trace]
11 be/4 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % [ksoftirqd/0]
查看网络端口占用命令netstat -anp
:
netstat -anp
2. C++进程内部
C++进程内部查看可以使用gdb
来,具体可以参考 linux gdb调试笔记 - 简书