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命令会连续生成报告。

更多内容请看下回。

相关推荐
千里马学框架5 天前
一起学 Android 14:ShellTransition 屏幕旋转过程深度剖析
android·智能手机·性能优化·framework·性能·屏幕旋转·rotation
liangshanbo12155 天前
React 性能优化实战
性能优化·react
mmsx5 天前
Android GIS系列 内存加锁、SQLite 开事务:矢量数据集双层并发设计
android·性能优化·app
Pioneer000016 天前
我用 Redis + 网关做多模型 API 路由:缓存命中率 95%+ 的工程实践
人工智能·redis·后端·缓存·性能优化·架构
ZFJ_张福杰6 天前
【Flutter】Flutter 中有哪些耗时操作?从 UI 卡顿到 Isolate 性能优化
flutter·性能优化·卡顿·isolate
政企项目老覃6 天前
金融转账“幽灵失败“排查实录:从本地消息表到 Seata TCC 的选型与权衡
数据库·程序人生·性能优化·数据分析·系统架构
爱喝水的鱼丶6 天前
SAP-ABAP:MM 模块供应商主数据开发:字段扩展、分级管控与同步接口开发
开发语言·性能优化·接口·sap·abap·增强·经验交流
贾伟康6 天前
【HarmonyOS 7新能力|050】Core File Kit mmap工程封装:把接入逻辑放进可维护的分层结构
性能优化·harmonyos·arkts·文件系统·mmap
贾伟康6 天前
【HarmonyOS 7新能力|045】LazyLayoutAlgorithm工程封装:把接入逻辑放进可维护的分层结构
性能优化·harmonyos·arkts·arkui·懒加载
打工仔折腾 AI6 天前
数据库上 K8s 之后谁来管?拆解金仓 KES-Operator 的声明式运维方案
人工智能·后端·python·性能优化·ai agent 实战