linux系统分析工具pidstat

2024-01-06 16:38

本文主要是介绍linux系统分析工具pidstat,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

pidstat主要用于监控全部或者指定进程占用系统资源的情况如CPU,内存,设备IO,任务切换,线程等.pidstat首次运行事显示自系统启动开始的各项统计信息,之后运行pidstat将显示自上次运行该命令以后的统计信息.用户可以通过指定统计的此时和时间来获得所需要的统计信息.该命令是sysstat中的工具,想要使用该命令需要先安装sysstat工具.pidstat命令只有在内核版本为2.6.20版本以后执行才有效.

用法:

输入pidstat --help后显示帮助:

[root@centos democlass]# pidstat --help
Usage: pidstat [ options ] [ <interval> [ <count> ] ]
Options are:
[ -C <command> ] [ -d ] [ -h ] [ -I ] [ -l ] [ -r ] [ -t ] [ -u ] [ -V ] [ -w ]
[ -p { <pid> [,...] | SELF | ALL } ] [ -T { TASK | CHILD | ALL } ]

描述:

 The  pidstat  command  is  used  for monitoring individual tasks currently being managed by the Linux kernel.  It writes to standard output activities for every task selected with option -p or for every task managed by the Linux kernel if option -p ALL has been used. Not selecting any tasks is equivalent to specifying -p ALL but  only  active  tasks  (tasks with non-zero statistics values) will appear in the report.

The pidstat command can also be used for monitoring the child processes of selected tasks.  Read about option -T below.

The  interval parameter specifies the amount of time in seconds between each report.  A value of 0 (or no parameters at all) indicates that tasks statistics are to be reported for the time since system startup (boot).  The count parameter can be specified in conjunction with the interval parameter if this one is not set to zero. The value  of  count  determines the number of reports generated at interval seconds apart. If the interval parameter is specified without the count parameter, the pidstat command generates reports continuously.

You can select information about specific task activities using flags.  Not specifying any flags selects only CPU activity.

选项:-C comm		#只显示那些包含字符串(可是正则表达式)comm的命令的名字-d			#显示I/O统计信息(须内核2.6.20及以后)PID			        #进程号kB_rd/s			#每秒此进程从磁盘读取的千字节数kB_wr/s			#此进程已经或者将要写入磁盘的每秒千字节数kB_ccwr/s			#由任务取消的写入磁盘的千字节数Command			#命令的名字-h			#显示所有的活动的任务-I			#在SMP环境,指出任务的CPU使用(等同于选项-u)应该被除于cpu的总数-l			#显示进程的命令名和它的参数-p { pid [,...] | SELF | ALL }		#指定线程显示其报告-r			#显示分页错误的内存利用率When reporting statistics for individual tasks, the following values are displayed:PID			        #进程号minflt/s			#每秒次缺页错误次数(minor page faults),次缺页错误次数意即虚拟内存地址映射成物理内存地址产生的page fault次数majflt/s			#每秒主缺页错误次数(major page faults),当虚拟内存地址映射成物理内存地址时,相应的page在swap中,这样的page fault为major page fault,一般在内存使用紧张时产生VSZ			        #该进程使用的虚拟内存(以kB为单位)RSS			        #该进程使用的物理内存(以kB为单位)%MEM			#当前任务使用的有效内存的百分比Command			#任务的命令名             When reporting global statistics for tasks and all their children, the following values are displayed:PID			        #PID号minflt-nr			#在指定的时间间隔内收集的进程和其子进程的次缺页错误次数majflt-nr			#在指定的时间间隔内收集的进程和其子进程的主缺页错误次数Command			#命令名-s			#堆栈的使用-t			#显示与所选任务相关的线程的统计数据-T { TASK | CHILD | ALL }	#指定必须监测的内容:TASK是默认的,单个任务的报告;CHILD:指定的进程和他们的子进程的全局报告,ALL:相当于TASK和CHILD-u			#报告CPU使用When reporting statistics for individual tasks, the following values are displayed: PID%usr			#用户层任务正在使用的CPU百分比(with or without nice priority ,NOT include time spent running a virtual processor)%system			#系统层正在执行的任务的CPU使用百分比%guest			#运行虚拟机的CPU占用百分比%CPU			#所有的使用的CPU的时间百分比CPU			        #处理器数量Command			#命令When reporting global statistics for tasks and all their children, the following values are displayed:PID			        #PID号usr-ms			#在指定时间内收集的在用户层执行的进程和它的子进程占用的CPU时间(毫秒){with or without nice priority,NOT include time spent running a virtual processor)system-ms			#在指定时间内收集的在系统层执行的进程和它的子进程占用的CPU时间(毫秒)guest-ms			#花在虚拟机上的时间Command			#命令-V			#版本号-w			#报告任务切换情况PID			        #PID号cswch/s			#每秒自动上下文切换nvcswch/s			#每秒非自愿的上下文切换Command			#命令

示例:

$ pidstat 2 5                        #Display five reports of CPU statistics for every active task in the system at two second intervals.(每隔两秒输出一份报告统计)$ pidstat -r -p 1643 2 5             #Display five reports of page faults and memory statistics for PID 1643 at two second intervals.(每隔两秒显示1643进程的内存信息统计)$ pidstat -C "fox|bird" -r -p ALL    #Display global page faults and memory statistics for all the processes whose command name includes the string "fox" or "bird".$ pidstat -T CHILD -r 2 5            #Display five reports of page faults statistics at two second intervals for the child processes of  all  tasks in the system. Only child processes with non-zero statistics values are displayed.


本文参考(大部分):

http://xuclv.blog.51cto.com/5503169/1166398

同时参考:;林昊的<<java应用>>

这篇关于linux系统分析工具pidstat的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/576951

相关文章

linux-基础知识3

打包和压缩 zip 安装zip软件包 yum -y install zip unzip 压缩打包命令: zip -q -r -d -u 压缩包文件名 目录和文件名列表 -q:不显示命令执行过程-r:递归处理,打包各级子目录和文件-u:把文件增加/替换到压缩包中-d:从压缩包中删除指定的文件 解压:unzip 压缩包名 打包文件 把压缩包从服务器下载到本地 把压缩包上传到服务器(zip

高效录音转文字:2024年四大工具精选!

在快节奏的工作生活中,能够快速将录音转换成文字是一项非常实用的能力。特别是在需要记录会议纪要、讲座内容或者是采访素材的时候,一款优秀的在线录音转文字工具能派上大用场。以下推荐几个好用的录音转文字工具! 365在线转文字 直达链接:https://www.pdf365.cn/ 365在线转文字是一款提供在线录音转文字服务的工具,它以其高效、便捷的特点受到用户的青睐。用户无需下载安装任何软件,只

Linux 网络编程 --- 应用层

一、自定义协议和序列化反序列化 代码: 序列化反序列化实现网络版本计算器 二、HTTP协议 1、谈两个简单的预备知识 https://www.baidu.com/ --- 域名 --- 域名解析 --- IP地址 http的端口号为80端口,https的端口号为443 url为统一资源定位符。CSDNhttps://mp.csdn.net/mp_blog/creation/editor

【Python编程】Linux创建虚拟环境并配置与notebook相连接

1.创建 使用 venv 创建虚拟环境。例如,在当前目录下创建一个名为 myenv 的虚拟环境: python3 -m venv myenv 2.激活 激活虚拟环境使其成为当前终端会话的活动环境。运行: source myenv/bin/activate 3.与notebook连接 在虚拟环境中,使用 pip 安装 Jupyter 和 ipykernel: pip instal

Linux_kernel驱动开发11

一、改回nfs方式挂载根文件系统         在产品将要上线之前,需要制作不同类型格式的根文件系统         在产品研发阶段,我们还是需要使用nfs的方式挂载根文件系统         优点:可以直接在上位机中修改文件系统内容,延长EMMC的寿命         【1】重启上位机nfs服务         sudo service nfs-kernel-server resta

【Linux 从基础到进阶】Ansible自动化运维工具使用

Ansible自动化运维工具使用 Ansible 是一款开源的自动化运维工具,采用无代理架构(agentless),基于 SSH 连接进行管理,具有简单易用、灵活强大、可扩展性高等特点。它广泛用于服务器管理、应用部署、配置管理等任务。本文将介绍 Ansible 的安装、基本使用方法及一些实际运维场景中的应用,旨在帮助运维人员快速上手并熟练运用 Ansible。 1. Ansible的核心概念

Linux服务器Java启动脚本

Linux服务器Java启动脚本 1、初版2、优化版本3、常用脚本仓库 本文章介绍了如何在Linux服务器上执行Java并启动jar包, 通常我们会使用nohup直接启动,但是还是需要手动停止然后再次启动, 那如何更优雅的在服务器上启动jar包呢,让我们一起探讨一下吧。 1、初版 第一个版本是常用的做法,直接使用nohup后台启动jar包, 并将日志输出到当前文件夹n

[Linux]:进程(下)

✨✨ 欢迎大家来到贝蒂大讲堂✨✨ 🎈🎈养成好习惯,先赞后看哦~🎈🎈 所属专栏:Linux学习 贝蒂的主页:Betty’s blog 1. 进程终止 1.1 进程退出的场景 进程退出只有以下三种情况: 代码运行完毕,结果正确。代码运行完毕,结果不正确。代码异常终止(进程崩溃)。 1.2 进程退出码 在编程中,我们通常认为main函数是代码的入口,但实际上它只是用户级

【Linux】应用层http协议

一、HTTP协议 1.1 简要介绍一下HTTP        我们在网络的应用层中可以自己定义协议,但是,已经有大佬定义了一些现成的,非常好用的应用层协议,供我们直接使用,HTTP(超文本传输协议)就是其中之一。        在互联网世界中,HTTP(超文本传输协议)是一个至关重要的协议,他定义了客户端(如浏览器)与服务器之间如何进行通信,以交换或者传输超文本(比如HTML文档)。