Mr Dk.'s BlogMr Dk.'s Blog
  • 🦆 About Me
  • ⛏️ Technology Stack
  • 🔗 Links
  • 🗒️ About Blog
  • Algorithm
  • C++
  • Compiler
  • Cryptography
  • DevOps
  • Docker
  • Git
  • Java
  • Linux
  • MS Office
  • MySQL
  • Network
  • Operating System
  • Performance
  • PostgreSQL
  • Productivity
  • Solidity
  • Vue.js
  • Web
  • Wireless
  • 🐧 How Linux Works (notes)
  • 🐧 Linux Kernel Comments (notes)
  • 🐧 Linux Kernel Development (notes)
  • 🐤 μc/OS-II Source Code (notes)
  • ☕ Understanding the JVM (notes)
  • ⛸️ Redis Implementation (notes)
  • 🗜️ Understanding Nginx (notes)
  • ⚙️ Netty in Action (notes)
  • ☁️ Spring Microservices (notes)
  • ⚒️ The Annotated STL Sources (notes)
  • ☕ Java Development Kit 8
GitHub
  • 🦆 About Me
  • ⛏️ Technology Stack
  • 🔗 Links
  • 🗒️ About Blog
  • Algorithm
  • C++
  • Compiler
  • Cryptography
  • DevOps
  • Docker
  • Git
  • Java
  • Linux
  • MS Office
  • MySQL
  • Network
  • Operating System
  • Performance
  • PostgreSQL
  • Productivity
  • Solidity
  • Vue.js
  • Web
  • Wireless
  • 🐧 How Linux Works (notes)
  • 🐧 Linux Kernel Comments (notes)
  • 🐧 Linux Kernel Development (notes)
  • 🐤 μc/OS-II Source Code (notes)
  • ☕ Understanding the JVM (notes)
  • ⛸️ Redis Implementation (notes)
  • 🗜️ Understanding Nginx (notes)
  • ⚙️ Netty in Action (notes)
  • ☁️ Spring Microservices (notes)
  • ⚒️ The Annotated STL Sources (notes)
  • ☕ Java Development Kit 8
GitHub
  • 📝 Notes
    • Algorithm
      • Algorithm - Bloom Filter
      • Algorithm - Disjoint Set
      • Algorithm - Fast Power
      • Algorithm - KMP
      • Algorithm - Monotonic Stack
      • Algorithm - RB-Tree
      • Algorithm - Regular Expression
      • Algorithm - Sliding Window
      • Online Judge - I/O
    • C++
      • C++ - Const
      • C++ File I/O
      • C++ - Object Layout
      • C++ - Operator Overload
      • C++ - Polymorphism
      • C++ STL algorithm
      • C++ STL map
      • C++ STL multimap
      • C++ STL priority_queue
      • C++ STL set
      • C++ STL string
      • C++ STL unordered_map
      • C++ STL vector
      • C++ - Smart Pointer
      • C++ - Template & Genericity
    • Compiler
      • ANTLR - Basic
      • Compiler - LLVM Architecture
      • Compiler - Multi-version GCC
    • Cryptography
      • Cryptography - Certbot
      • Cryptography - Digital Signature & PKCS #7
      • Cryptography - GPG
      • Cryptography - JWT
      • Cryptography - Keystore & Certificates
      • Cryptography - OAuth 2.0
      • Cryptography - Java 实现对称与非对称加密算法
      • Cryptography - TLS
    • DevOps
      • DevOps - Travis CI
    • Docker
      • Docker - Image & Storage Management
      • Docker - Image
      • Docker - Libcontainer
      • Docker - Multi-Arch Image
      • Docker - Multi-Stage Build
      • Docker - Network
      • Docker - Orchestration & Deployment
      • Docker - Overview
      • Docker - Service Building
      • Docker - Volume & Network Usage
      • Docker - Volume
      • Linux - Control Group
      • Linux - Namespace
    • Git
      • Git - Branch & Merge
      • Git - Cached
      • Git - Cherry Pick
      • Git - Commit
      • Git - Patch
      • Git - Proxy
      • Git - Rebase
      • Git - Reset
      • Git - Stash
      • Git - Theme for Git-Bash
    • Java
      • JVM - Synchronized
      • JVM - Volatile
      • Java - Annotation 注解
      • Java - BIO & NIO
      • Java - Class Path
      • Java - Condition and LockSupport
      • Java - Current Timestamp
      • Java - Deep Copy
      • Java - 运行环境配置
      • Java - Equals
      • Java - Exporting JAR
      • Java - Javadoc
      • Java - Lock
      • Java - Maven 项目构建工具
      • Java - References
      • Java - Reflection Mechanism
      • Java - String Split
      • Java - Thread Pool
      • Java - Thread
      • Tomcat - Class Loader
      • Tomcat - Container
    • Linux
      • addr2line
      • cut
      • df
      • du
      • fallocate
      • find
      • fio
      • grep
      • groupadd
      • gzip
      • head / tail
      • hexdump
      • iostat
      • iotop
      • kill
      • ldd
      • lsof
      • ltrace / strace
      • mpstat
      • netstat
      • nm
      • pidstat
      • pmap
      • readlink
      • readlink
      • rpm2cpio / rpm2archive
      • sort
      • tee
      • uniq
      • useradd
      • usermod
      • watch
      • wc
      • which
      • xargs
    • MS Office
      • MS Office - Add-in Dev
      • MS Office - Application
    • MySQL
      • InnoDB - Architecture
      • InnoDB - Backup
      • InnoDB - Checkpoint
      • InnoDB - Critical Features
      • InnoDB - Files
      • InnoDB - Index
      • InnoDB - Insert Buffer
      • InnoDB - Lock
      • InnoDB - Partition Table
      • InnoDB - Table Storage
      • MySQL - Server Configuration
      • MySQL - Storage Engine
    • Network
      • Network - ARP
      • Network - FTP
      • Network - GitHub Accelerating
      • HTTP - Message Format
      • HTTP - POST 提交表单的两种方式
      • Network - Proxy Server
      • Network - SCP
      • Network - SSH
      • Network - TCP Congestion Control
      • Network - TCP Connection Management
      • Network - TCP Flow Control
      • Network - TCP Retransmission
      • Network - Traceroute
      • Network - V2Ray
      • Network - WebSocket
      • Network - Windows 10 Mail APP
      • Network - frp
    • Operating System
      • Linux - Kernel Compilation
      • Linux - Multi-OS
      • Linux - Mutex & Condition
      • Linux - Operations
      • Linux: Package Manager
      • Linux - Process Manipulation
      • Linux - User ID
      • Linux - Execve
      • OS - Compile and Link
      • OS - Dynamic Linking
      • OS - ELF
      • Linux - Image
      • OS - Loading
      • OS - Shared Library Organization
      • OS - Static Linking
      • Syzkaller - Architecture
      • Syzkaller - Description Syntax
      • Syzkaller - Usage
      • Ubuntu - Desktop Recover (Python)
      • WSL: CentOS 8
    • Performance
      • Linux Performance - Perf Event
      • Linux Performance - Perf Record
      • Linux Performance - Perf Report
      • Linux Performance - Flame Graphs
      • Linux Performance - Off CPU Analyze
    • PostgreSQL
      • PostgreSQL - ANALYZE
      • PostgreSQL - Atomics
      • PostgreSQL - CREATE INDEX CONCURRENTLY
      • PostgreSQL - COPY FROM
      • PostgreSQL - COPY TO
      • PostgreSQL - Executor: Append
      • PostgreSQL - Executor: Group
      • PostgreSQL - Executor: Limit
      • PostgreSQL - Executor: Material
      • PostgreSQL - Executor: Nest Loop Join
      • PostgreSQL - Executor: Result
      • PostgreSQL - Executor: Sequential Scan
      • PostgreSQL - Executor: Sort
      • PostgreSQL - Executor: Unique
      • PostgreSQL - FDW Asynchronous Execution
      • PostgreSQL - GUC
      • PostgreSQL - Locking
      • PostgreSQL - LWLock
      • PostgreSQL - Multi Insert
      • PostgreSQL - Plan Hint GUC
      • PostgreSQL - Process Activity
      • PostgreSQL - Query Execution
      • PostgreSQL - Spinlock
      • PostgreSQL - Storage Management
      • PostgreSQL - VFD
      • PostgreSQL - WAL Insert
      • PostgreSQL - WAL Prefetch
    • Productivity
      • LaTeX
      • Venn Diagram
      • VuePress
    • Solidity
      • Solidity - ABI Specification
      • Solidity - Contracts
      • Solidity - Expressions and Control Structures
      • Solidity - Layout and Structure
      • Solidity - Remix IDE
      • Solidity - Slither
      • Solidity - Types
      • Solidity - Units and Globally Available Variables
    • Vue.js
      • Vue.js - Environment Variable
    • Web
      • Web - CORS
      • Web - OpenAPI Specification
    • Wireless
      • Wireless - WEP Cracking by Aircrack-ng
      • Wireless - WPS Cracking by Reaver
      • Wireless - wifiphisher

pidstat

Created by : Mr Dk.

2023 / 08 / 14 00:23

Hangzhou, Zhejiang, China


Background

pidstat 用于打印 Linux 任务(进程/线程)的统计信息。

Usage

$ pidstat --help
Usage: pidstat [ options ] [ <interval> [ <count> ] ] [ -e <program> <args> ]
Options are:
[ -d ] [ -H ] [ -h ] [ -I ] [ -l ] [ -R ] [ -r ] [ -s ] [ -t ] [ -U [ <username> ] ]
[ -u ] [ -V ] [ -v ] [ -w ] [ -C <command> ] [ -G <process_name> ] [ --human ]
[ -p { <pid> [,...] | SELF | ALL } ] [ -T { TASK | CHILD | ALL } ]

Filter

使用 -c 参数按命令名称过滤:

$ pidstat -C postgres
Linux 5.10.134-007.ali5000.al8.x86_64 (k39a07236.sqa.eu95)      08/14/2023      _x86_64_        (104 CPU)

12:02:25 AM   UID       PID    %usr %system  %guest   %wait    %CPU   CPU  Command
12:02:25 AM  1000    513728    0.00    0.00    0.00    0.00    0.00    58  postgres
12:02:25 AM  1000   1000582    0.00    0.00    0.00    0.00    0.00    44  postgres
12:02:25 AM  1000   1000587    0.00    0.00    0.00    0.00    0.00    89  postgres
12:02:25 AM  1000   1000590    0.00    0.00    0.00    0.00    0.00    79  postgres
12:02:25 AM  1000   1000591    0.00    0.00    0.00    0.00    0.00    25  postgres
12:02:25 AM  1000   1000593    0.00    0.00    0.00    0.00    0.00    36  postgres
12:02:25 AM  1000   1000625    0.00    0.00    0.00    0.00    0.00    27  postgres
12:02:25 AM  1000   1000627    0.00    0.00    0.00    0.00    0.00   103  postgres
...

使用 -p 参数按 pid 过滤:

$ pidstat -p 513728
Linux 5.10.134-007.ali5000.al8.x86_64 (k39a07236.sqa.eu95)      08/14/2023      _x86_64_        (104 CPU)

12:03:34 AM   UID       PID    %usr %system  %guest   %wait    %CPU   CPU  Command
12:03:34 AM  1000    513728    0.00    0.00    0.00    0.00    0.00    58  postgres

CPU Utilization

使用 -u 参数将会打印 CPU 使用情况:

  • %usr:用户空间 CPU 使用量
  • %system:内核空间 CPU 使用量
  • %guest:虚拟机 CPU 使用量
  • %wait:等待被执行的 CPU 使用量
  • %CPU:CPU 总使用量
  • CPU:执行该任务的 CPU 编号
$ pidstat -p 513728 -u
Linux 5.10.134-007.ali5000.al8.x86_64 (k39a07236.sqa.eu95)      08/14/2023      _x86_64_        (104 CPU)

12:13:28 AM   UID       PID    %usr %system  %guest   %wait    %CPU   CPU  Command
12:13:28 AM  1000    513728    0.00    0.00    0.00    0.00    0.00    58  postgres

Context Switching

使用 -w 参数将会打印上下文切换信息:

  • cswch/s:每秒自愿发生的上下文切换次数(比如因等待资源而阻塞)
  • nvcswch/s:每秒非自愿发生的上下文切换次数(比如时间片用完)
$ pidstat -p 513728 -w
Linux 5.10.134-007.ali5000.al8.x86_64 (k39a07236.sqa.eu95)      08/14/2023      _x86_64_        (104 CPU)

12:13:41 AM   UID       PID   cswch/s nvcswch/s  Command
12:13:41 AM  1000    513728      0.00      0.00  postgres

Memory Utilization

使用 -r 参数将会打印缺页和内存使用信息:

  • minflt/s:每秒钟不需要从内存装载的缺页次数
  • majflt/s:每秒钟需要从内存装载的缺页次数
  • VSZ:虚拟内存 kB 数
  • RSS:非 swap 的物理内存 kB 数
  • %MEM:目前使用的物理内存占所有物理内存的比例
$ pidstat -p 513728 -r
Linux 5.10.134-007.ali5000.al8.x86_64 (k39a07236.sqa.eu95)      08/14/2023      _x86_64_        (104 CPU)

12:15:29 AM   UID       PID  minflt/s  majflt/s     VSZ     RSS   %MEM  Command
12:15:29 AM  1000    513728      0.00      0.00 2980112      80   0.00  postgres

I/O Statistics

使用 -d 参数将会打印 I/O 统计信息:

  • kB_rd/s:每秒从磁盘上读取的 kB 数
  • kB_wr/s:每秒写入磁盘的 kB 数
  • iodelay:等待 I/O 完成的时钟周期数
$ pidstat -d
Linux 5.10.134-007.ali5000.al8.x86_64 (k39a07236.sqa.eu95)      08/14/2023      _x86_64_        (104 CPU)

12:21:36 AM   UID       PID   kB_rd/s   kB_wr/s kB_ccwr/s iodelay  Command
12:21:36 AM     0         1     -1.00     -1.00     -1.00   11739  systemd
12:21:36 AM     0       778     -1.00     -1.00     -1.00    2611  kswapd0
12:21:36 AM     0       779     -1.00     -1.00     -1.00     140  kswapd1
...

Threads

使用 -t 参数可以打印一个进程内所有线程的信息:

$pidstat -p 399853 -t
Linux 5.10.134-007.ali5000.al8.x86_64 (3970e7e00014)    08/13/2023      _x86_64_        (104 CPU)

04:26:16 PM   UID      TGID       TID    %usr %system  %guest   %wait    %CPU   CPU  Command
04:26:16 PM  1000    399853         -    0.00    0.00    0.00    0.00    0.00    20  postgres
04:26:16 PM  1000         -    399853    0.00    0.00    0.00    0.00    0.00    20  |__postgres
04:26:16 PM  1000         -    399854    0.00    0.00    0.00    0.00    0.00     9  |__postgres
04:26:16 PM  1000         -    399855    0.00    0.00    0.00    0.00    0.00    17  |__pxadps399853

References

pidstat(1) — Linux manual page

Monitor and Find Statistics for Linux Processes Using pidstat Tool

Edit this page on GitHub
Prev
nm
Next
pmap