gpt4 book ai didi

linux - 如何在 linux shell 脚本中获取 cpu sirq?

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:36:51 27 4
gpt4 key购买 nike

以下是top -b的输出

Mem: 95752K used, 29164K free, 0K shrd, 0K buff, 35176K cached
CPU: 5% usr 9% sys 0% nic 0% idle 0% io 0% irq 84% sirq

我需要持续监控 sirq,我该如何在 shell 脚本 (sh) 中做到这一点?

问候, Jade 薇

最佳答案

参见 Linux 内核的1.8 节 proc.txt document .同样具有启发性的是 busybox top source .
来自 proc.txt 文档的1.8 节

1.8 Miscellaneous kernel statistics in /proc/stat

Various pieces of information about kernel activity are available in the /proc/stat file. All of the numbers reported in this file are aggregates since the system first booted. For a quick look, simply cat the file.

The "softirq" line gives counts of softirqs serviced since boot time, for each of the possible system softirqs. The first column is the total of all softirqs serviced; each subsequent column is the total for that particular softirq.

所以下面的命令获取自启动以来的总数,

cat /proc/stat | grep softirq | awk '{print $2}'

您必须在脚本中做一些数学运算才能得到 delta

每个 CPU 行都有一个 softirq 值。这是第八项,再次手动增量时间

cat /proc/stat  | grep cpu[^0-9] | awk '{ print $8}'

您可以根据需要单独选择每个 CPU。我相信人们可以想出更好的脚本,但我认为他们展示了原则。

关于linux - 如何在 linux shell 脚本中获取 cpu sirq?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16440635/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com