Linux 工具介绍:pidstat

# Linux工具介绍: pidstat

相较于传统、老旧的top,ps命令,pidstat能解决那些问题?

  1. 查看指定进程的stats
  2. 查看指定进程的磁盘操作(读、写)stats
  3. 查看指定进程所有线程(threads)的stats
  4. 查看每一个活动进程的CPU stats报告
  5. 获取: 进程触发了多少次 Context Switches (cs)
  6. 获取: 指定进程的内存使用、page faults
  7. 确认指定进程有无内存泄露

由上可知,pidstat提供了很多新能力,象查看进程的IO读写、内存使用等等,在分析诊断问题的时候都是关键的判断因素。

安装 

不是最基础的Unix工具集成员,需要单独安装,属于 sysstat 包

~ yum install sysstat ~

用法: 查看指定进程的I/O stats

~ # pidstat -d -p interval count ~

~ # pidstat -d -p 6417 2 10 ~

6417 是我系统中OpenShift的进程ID, 2表示间隔2秒,10 表示采样10次,下面的输出显示,虽然这个进程是我系统中最消耗CPU的,但是并没有什么I/O操作。

_ ccwr: canceled writes _

~~ [root@dell ~]# pidstat -d -p 6417 2 10

~~ Linux 3.10.0-957.el7.x86_64 (dell.oc.skyatlas.net) 03/10/2019x86_64(4 CPU)

~~ 

~~ 09:17:32 AM UID PID kB_rds kB_wrs kB_ccwr/s Command

~~ 09:17:34 AM 0 6417 0.00 0.00 0.00 openshift

~~ 09:17:36 AM 0 6417 0.00 0.00 0.00 openshift

~~ 09:17:38 AM 0 6417 0.00 0.00 0.00 openshift

~~ 09:17:40 AM 0 6417 0.00 0.00 0.00 openshift

~~ 09:17:42 AM 0 6417 0.00 0.00 0.00 openshift

~~ 09:17:44 AM 0 6417 0.00 0.00 0.00 openshift

~~ 09:17:46 AM 0 6417 0.00 0.00 0.00 openshift

~~ 09:17:48 AM 0 6417 0.00 0.00 0.00 openshift

~~ 09:17:50 AM 0 6417 0.00 0.00 0.00 openshift

~~ 09:17:52 AM 0 6417 0.00 0.00 0.00 openshift

~~ Average: 0 6417 0.00 0.00 0.00 openshift

用法: 找出page faults Top 5 进程

~ # pidstat -T Child -r 2 5 ~

输出:

  • minflt-nr: 采样的间隔内,minor faults总数
  • majflt-nr: 采样的时间间隔内,major faults总数

用法: 查看CPU使用

~ # pidstat -T CHILD -u 2 2 ~

输出:

  • usr-ms:usr level(application)cpu时间(ms)
  • system-ms:system level(kernel)cpu时间(ms)
  • guest-ms: 虚拟机时间(ms)

更多使用,查看pidstat man手册

Leave Comment