Skip to the content.

trace 传统工具

procs

命令 解释 特殊说明
free Report the amount of free and used memory in the system  
kill Send a signal to a process based on PID  
pgrep List processes based on name or other attributes  
pkill Send a signal to a process based on name or other attributes  
pmap Report memory map of a process /proc/pid/maps 和 smaps 重新解析而已
ps Report information of processes  
pwdx Report current directory of a process  
slabtop Display kernel slab cache information in real time  
sysctl Read or Write kernel parameters at run-time  
top Dynamic real-time view of running processes  
uptime Display how long the system has been running  
vmstat Report virtual memory statistics  
w Report logged in users and what they are doing  
watch Execute a program periodically, showing output fullscreen  
cifsiostat    
tapestat    

在 fedora 中安装,移除掉翻译后,是这些文件:

🤒  sudo rpm -ql sysstat
/etc/sysconfig/sysstat
/etc/sysconfig/sysstat.ioconf
/usr/bin/cifsiostat
/usr/bin/iostat
/usr/bin/mpstat
/usr/bin/pidstat
/usr/bin/sadf
/usr/bin/sar
/usr/bin/tapestat
/usr/lib/systemd/system-sleep/sysstat.sleep
/usr/lib/systemd/system/sysstat-collect.service
/usr/lib/systemd/system/sysstat-collect.timer
/usr/lib/systemd/system/sysstat-rotate.service
/usr/lib/systemd/system/sysstat-rotate.timer
/usr/lib/systemd/system/sysstat-summary.service
/usr/lib/systemd/system/sysstat-summary.timer
/usr/lib/systemd/system/sysstat.service
/usr/lib64/sa
/usr/lib64/sa/sa1
/usr/lib64/sa/sa2
/usr/lib64/sa/sadc
/usr/share/doc/sysstat
/usr/share/doc/sysstat/CHANGES
/usr/share/doc/sysstat/CREDITS
/usr/share/doc/sysstat/FAQ.md
/usr/share/doc/sysstat/README.md
/usr/share/man/man1/iostat.1.gz
/usr/share/man/man1/mpstat.1.gz
/usr/share/man/man1/pidstat.1.gz
/usr/share/man/man1/sadf.1.gz
/usr/share/man/man1/sar.1.gz
/usr/share/man/man1/cifsiostat.1.gz
/usr/share/man/man1/tapestat.1.gz
/usr/share/man/man5/sysstat.5.gz
/usr/share/man/man8/sa1.8.gz
/usr/share/man/man8/sa2.8.gz
/usr/share/man/man8/sadc.8.gz
/var/log/sa

vmstat

vmstat 1

procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
 2  0      0 19883668 271528 4860896    0    0   153    53  283  344  1  1 98  0  0
 0  0      0 19882456 271528 4860972    0    0     0     4 6806 10110  0  0 99  0  0
 1  0      0 19884664 271528 4861036    0    0     0     4 9503 12598  2  0 97  0  0
 1  0      0 19900404 271528 4861164    0    0     0   728 12225 16093  4  0 96  0  0

top

和 htop 相同,通过按 H 可以详细的展示每一个 thread 的内容,这个更好用,可以展示 thread 的名称。

展示 Last Used CPU

  1. 在 top 中临时开启(交互式)

启动 top 后,按 f 进入字段管理界面:

• 找到 P (Last Used Cpu) 或 Last Used CPU (SMP) • 按 Space 选中(前面会出现 *) • 按 q 返回主界面

此时 P 列就会显示每个进程最后一次在哪个 CPU 核心上运行。

  1. 保存为默认配置 在 top 中按 Shift + W(即大写 W),可以将当前字段设置保存到 ~/.toprc,下次启动 top 自动生效。

ps

What does aux mean in ps aux?

ps 输出排序

sysstat

iostat reports CPU statistics and input/output statistics for block devices and partitions. mpstat reports individual or combined processor related statistics. pidstat reports statistics for Linux tasks (processes) : I/O, CPU, memory, etc.

sar

最核心就记住这个就可以了: sar -n DEV 1

在这里 https://www.brendangregg.com/linuxperf.html 找到了这个图总结,真不错啊 https://www.brendangregg.com/Perf/linux_static_tools.png

sar 的配套工具,找到系统中长时间的记录:

  1. sadf - Display data collected by sar in multiple formats.
  2. sadc - System activity data collector.

例如是 8 号这天的日志:

sar -P 1,2 -f  /var/log/sa/sa08 | rg "10:.*:.*"

注意,sar 配置了一个服务就可以了:

systemctl status sysstat-collect
○ sysstat-collect.service - system activity accounting tool
     Loaded: loaded (/usr/lib/systemd/system/sysstat-collect.service; static)
    Drop-In: /usr/lib/systemd/system/service.d
             └─10-timeout-abort.conf
     Active: inactive (dead) since Tue 2026-04-07 13:30:02 CST; 6min ago
 Invocation: fb53c5b0c2f24719af7d3629842ef372
TriggeredBy: ● sysstat-collect.timer
       Docs: man:sa1(8)
    Process: 2580619 ExecStart=/usr/lib64/sa/sa1 1 1 (code=exited, status=0/SUCCE>
   Main PID: 2580619 (code=exited, status=0/SUCCESS)
   Mem peak: 1.2M
        CPU: 9ms

iostat

iostat 从 /sys/block/nvme0n1/stat 中获取的: Documentation/admin-guide/iostats.rst

执行一次 iostat 的结果似乎不对,使用 iostat -xz 1

🤒  cat /sys/block/nvme0n1/stat
  250304    54867 17676331    44341   420980   730997 14007220  1718258        0   733693  1910688        0        0        0        0    88034   148089

/sys/block/loop4/stat

docs/kernel/sysfs-blk.md

通过 iostat -xz 1 可以看到 D2C 的 io 的延迟

这个数据是从 /proc/diskstats 中导出的吗? 或者说,D2C 这个字段也是在 /proc/diskstats 中的?

看看 util 的含义

              %util  Percentage of elapsed time during which I/O requests were issued  to  the  device
                     (bandwidth  utilization for the device). Device saturation occurs when this value
                     is close to 100% for devices serving requests serially.  But for devices  serving
                     requests  in  parallel, such as RAID arrays and modern SSDs, this number does not
                     reflect their performance limits.

pidstat

mpstat

20时14分19秒  CPU    %usr   %nice    %sys %iowait    %irq   %soft  %steal  %guest  %gnice   %idle
20时14分20秒  all    0.00    0.00    0.13    0.00    0.00    0.00    0.00    0.00    0.00   99.87
20时14分21秒  all    0.37    0.00    0.34    0.06    0.00    0.03    0.00    0.00    0.00   99.19
20时14分22秒  all    0.25    0.00    0.16    0.00    0.00    0.00    0.00    0.00    0.00   99.59
20时14分23秒  all    0.19    0.00    0.09    0.03    0.00    0.00    0.00    0.00    0.00   99.69
20时14分24秒  all    0.38    0.00    0.19    0.00    0.00    0.00    0.00    0.03    0.00   99.41
20时14分25秒  all    0.06    0.00    0.13    0.03    0.00    0.00    0.00    0.00    0.00   99.78
20时14分26秒  all    0.19    0.00    0.16    0.00    0.00    0.00    0.00    0.00    0.00   99.66
20时14分27秒  all    0.37    0.00    0.19    0.03    0.00    0.00    0.00    0.00    0.00   99.41
20时14分28秒  all    0.19    0.00    0.19    0.03    0.00    0.00    0.00    0.09    0.00   99.50
20时14分29秒  all    1.41    0.00    0.50    0.19    0.00    0.00    0.00    0.31    0.00   97.53

util-linux

ipcs

irqtop

htop

操作

界面

pstack

https://github.com/mpercy/pstack

lshw

time

lsof

https://github.com/lsof-org/lsof

strace -t -e trace=file lsof bin

只是访问 /proc/pdi/fd 和 /proc/pdi/fdinfo 而已

iotop

https://github.com/Tomas-M/iotop

本站所有文章转发 CSDN 将按侵权追究法律责任,其它情况随意。