Linux性能优化工具系列详解(3)

接前一篇文章:Linux性能优化工具系列详解(2)

本系列内容参考:

极客时间 ------ 倪朋飞 《Linux 性能优化实战》

特此致谢!

系列工具

前两回讲解了性能优化系列工具的第1个 ------ uptime。本回讲解第2个命令 ------ mpstat。

2. mpstat

(1)概述

mpstat是Linux系统中sysstat工具包 的核心组件,用于‌实时监控多核CPU各核心的详细利用率及中断统计‌,支持按核心拆分数据以定位负载均衡瓶颈。‌‌

mpstat命令主要用于多CPU环境下,它显示各个可用CPU的状态。这些信息存放在/proc/stat文件中。在多CPUs系统里,其不但能查看所有CPU的平均状况信息,而且能够查看特定CPU的信息。

(2)详情

注:

既然mpstat隶属于sysstat工具包,那么要使用mpstat命令,需要首先下载sysstat工具包。在笔者的Ubuntu虚拟机中,通过apt命令下载syastat工具包,实际命令及结果如下:

bash 复制代码
$ sudo apt install sysstat
[sudo] password for ph: 
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Suggested packages:
  isag
The following NEW packages will be installed:
  sysstat
0 upgraded, 1 newly installed, 0 to remove and 224 not upgraded.
Need to get 487 kB of archives.
After this operation, 1,507 kB of additional disk space will be used.
Get:1 http://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy-updates/main amd64 sysstat amd64 12.5.2-2ubuntu0.2 [487 kB]
Fetched 487 kB in 0s (1,345 kB/s)
Preconfiguring packages ...
Selecting previously unselected package sysstat.
(Reading database ... 268580 files and directories currently installed.)
Preparing to unpack .../sysstat_12.5.2-2ubuntu0.2_amd64.deb ...
Unpacking sysstat (12.5.2-2ubuntu0.2) ...
Setting up sysstat (12.5.2-2ubuntu0.2) ...

Creating config file /etc/default/sysstat with new version
update-alternatives: using /usr/bin/sar.sysstat to provide /usr/bin/sar (sar) in auto mode
Created symlink /etc/systemd/system/sysstat.service.wants/sysstat-collect.timer → /lib/systemd/system/sysstat-collect.timer.
Created symlink /etc/systemd/system/sysstat.service.wants/sysstat-summary.timer → /lib/systemd/system/sysstat-summary.timer.
Created symlink /etc/systemd/system/multi-user.target.wants/sysstat.service → /lib/systemd/system/sysstat.service.
Processing triggers for man-db (2.10.2-1) ...
ph@ph-virtual-machine:~$ 

只有下载完sysstat工具包之后,man mpstat命令才有内容。

NAME

mpstat - Report processors related statistics.

名称

mpstat ------ 报告处理器相关统计数据。

SYNOPSIS

mpstat -A --dec={ 0 \| 1 \| 2 } -n -u -T -V -I { keyword\[,... | ALL } ] -N { node_list \| ALL } -o JSON -P { cpu_list \| ALL } interval \[ count ]

简介

mpstat -A --dec={ 0 \| 1 \| 2 } -n -u -T -V -I { keyword\[,... | ALL } ] -N { node_list \| ALL } -o JSON -P { cpu_list \| ALL } interval \[ count ]

语法

mpstat 选项 参数

DESCRIPTION

The mpstat command writes to standard output activities for each available processor, processor 0 being the first one. Global average activities among all processors are also reported. The mpstat command can be used on both SMP and UP machines, but in the latter, only global average activities will be printed. If no activity has been selected, then the default report is the CPU utilization report.

The interval parameter specifies the amount of time in seconds between each report. A value of 0 (or no parameters at all) indicates that processors 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 mpstat command generates reports continuously.

描述

mpstat命令将每个可用处理器的活动信息输出到标准输出,其中处理器0为第一个处理器。同时还会报告所有处理器的全局平均活动情况。该命令适用于SMP和UP机器,但在UP机器上仅会打印全局平均活动信息。若未选择特定活动,则默认输出CPU利用率报告。

interval参数指定每个报告之间的时间量(秒)。值0(或根本没有参数)表示要报告自系统启动(引导)以来的处理器统计信息。如果计数参数未设置为零,则可以将其与间隔参数一起指定。计数值决定了以秒为间隔生成的报告数量。如果指定了间隔参数而没有指定计数参数,则mpstat命令会连续生成报告。

更多内容请看下回。

相关推荐
CCblandy1 天前
Agent 工具调用怎么编排?本机实测:并行只到 2.63 倍,慢的先发省 30ms,CPU 活加 worker 无效
人工智能·后端·python·性能优化
用AI来创业吧1 天前
网站建设公司哪家好:报价差 3 倍,差在哪四项成本上(选型笔记)
笔记·性能优化·软件工程·安全威胁分析
yunwei371 天前
eBPF 入门实践教程:BPF Token,安全的委托式权限与程序加载
linux·后端·性能优化
CSharp精选营1 天前
SaveChanges 一万行?换批量操作快 10 倍
性能优化·efcore·批量操作·csharp·executeupdate
爱喝水的鱼丶1 天前
SAP-ABAP:S/4 HANA ABAP 新特性入门:与 ECC ABAP 的核心差异、架构优势与学习路径规划
运维·数据库·性能优化·sap·abap·hana·开发交流
余槐i2 天前
PostgreSQL 函数索引报错 must be immutable:3种绕法与代价
数据库·后端·sql·postgresql·性能优化
余槐i2 天前
Skills 增至 30 个,Claude Code 反而变慢:token 与加载实测
性能优化·开发工具·ai agent·claude code·agent skills
xiaoqiMikko2 天前
fastjson 1.2.84 的补丁关掉了一个缓存:addAccept 包前缀白名单下,反序列化慢了 13~28 倍
java·后端·性能优化
万联WANFLOW2 天前
LLM 调用很快,AI Agent 为什么还是慢?关键路径分析与优化方法
性能优化·llm·aigc
yunwei372 天前
eBPF 教程:BPF 迭代器用于内核数据导出
linux·后端·性能优化