linux - 如何监控内核执行的系统调用数量?

标签 linux statistics kernel monitoring system-calls

我需要监控 Linux 执行的系统调用数量。 我知道 vmstat 能够为 BSD 和 AIX 系统显示此信息,但对于 Linux 它不能(根据手册页)。

/proc 中有计数器吗?或者有什么其他的监控方式吗?

最佳答案

我写了一个简单的 SystemTap 脚本(基于 syscalls_by_pid.stp )。 它产生这样的输出:

ProcessName          #SysCalls

munin-graph          38609 
munin-cron           8160  
fping                4502  
check_http_demo      2584  
check_nrpe           2045  
sh                   1836  
nagios               886   
sendmail             747   
smokeping            649   
check_http           571   
check_nt             376   
pcscd                216   
ping                 108   
check_ping           100   
crond                87    
stapio               69    
init                 56    
syslog-ng            27    
sshd                 17    
ntpd                 9     
hp-asrd              8     
hald-addon-stor      7     
automount            6     
httpd                4     
stap                 3     
flow-capture         2     
gam_server           2     

Total                61686

脚本本身:

#! /usr/bin/env stap

#
# Print the system call count by process name in descending order.
#

global syscalls

probe begin {
  print ("Collecting data... Type Ctrl-C to exit and display results\n")
}

probe syscall.* {
  syscalls[execname()]++
}

probe end {
  printf ("%-20s %-s\n\n", "ProcessName", "#SysCalls")
  summary = 0
  foreach (procname in syscalls-) {
    printf("%-20s %-10d\n", procname, syscalls[procname])
    summary = summary + syscalls[procname]
  }
  printf ("\n%-20s %-d\n", "Total", summary)
}

关于linux - 如何监控内核执行的系统调用数量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8757318/

相关文章:

algorithm - 简单的趋势分析算法

c - Linux Kernel Module程序从IP获取域名

kernel - Virtualbox 6.1.10、Ubuntu 20.04 错误返回状态构建在内核 5.8.0 上,包 virtualbox-dkms 错误

c - 根据进程组限制对文件的访问

c++ - 与icecc交叉编译时如何设置ICECC_VERSION

c - 带分隔符的Strtok行为

linux - 在/dev/shm 的子目录中创建共享内存时,shm_open() 失败并返回 EINVAL

Python - 测试我的数据是否遵循泊松/指数分布

linux - 如何在 Mac 上创建稀疏文件

java - 如何使用 MultivariateNormalDistribution 类创建多个相关随机数?