[转帖]SystemTap Beginners Guide -profiling

systemtap,beginners,guide,profiling · 浏览次数 : 0

小编点评

Sure, here's the summary you requested: **Profileing Function Calls** This section provides a script called `functioncallcount.stp` that can be used to count the number of times a specific kernel function is called within a 30-second sample. The script takes the targeted kernel function as an argument and supports wildcards to target multiple functions. **Key points:** * The script uses `stap` for profiling, which allows it to track function calls and measure their frequency. * It can be used to monitor the number of times a particular function is called, regardless of its arguments. * The output contains the name of the function called and its count, with the results sorted in descending order of call frequency. * This script provides a convenient way to analyze kernel activity and identify functions that are frequently called.

正文

⁠5.3. Profiling

The following sections showcase scripts that profile kernel activity by monitoring function calls.

⁠5.3.1. Counting Function Calls Made

This section describes how to identify how many times the system called a specific kernel function in a 30-second sample. Depending on the use of wildcards, you can also use this script to target multiple kernel functions.
functioncallcount.stp
#! /usr/bin/env stap
# The following line command will probe all the functions
# in kernel's memory management code:
#
# stap  functioncallcount.stp "*@mm/*.c"

probe kernel.function(@1).call {  # probe functions listed on commandline
  called[ppfunc()] <<< 1  # add a count efficiently
}

global called

probe end {
  foreach (fn in called-)  # Sort by call count (in decreasing order)
  #       (fn+ in called)  # Sort by function name
    printf("%s %d\n", fn, @count(called[fn]))
  exit()
}
functioncallcount.stp takes the targeted kernel function as an argument. The argument supports wildcards, which enables you to target multiple kernel functions up to a certain extent.
The output of functioncallcount.stp contains the name of the function called and how many times it was called during the sample time (in alphabetical order). Example 5.13, “functioncallcount.stp Sample Output” contains an excerpt from the output of stap functioncallcount.stp "*@mm/*.c":

Example 5.13. functioncallcount.stp Sample Output

[...]
__vma_link 97
__vma_link_file 66
__vma_link_list 97
__vma_link_rb 97
__xchg 103
add_page_to_active_list 102
add_page_to_inactive_list 19
add_to_page_cache 19
add_to_page_cache_lru 7
all_vm_events 6
alloc_pages_node 4630
alloc_slabmgmt 67
anon_vma_alloc 62
anon_vma_free 62
anon_vma_lock 66
anon_vma_prepare 98
anon_vma_unlink 97
anon_vma_unlock 66
arch_get_unmapped_area_topdown 94
arch_get_unmapped_exec_area 3
arch_unmap_area_topdown 97
atomic_add 2
atomic_add_negative 97
atomic_dec_and_test 5153
atomic_inc 470
atomic_inc_and_test 1
[...]

与[转帖]SystemTap Beginners Guide -profiling相似的内容:

[转帖] SystemTap Beginners Guide -network

SystemTap Beginners Guide Next ⁠Chapter 5. Useful SystemTap Scripts 5.1. Network5.1.1. Network Profiling5.1.2. Tracing Functions Called in Network Soc

[转帖]SystemTap Beginners Guide -disk

SystemTap Beginners Guide Next ⁠5.2. Disk The following sections showcase scripts that monitor disk and I/O activity. ⁠5.2.1. Summarizing Disk Read/Wr

[转帖]Systemtap的另类用法

November 10th, 2010Yu Feng 原创文章,转载请注明: 转载自系统技术非业余研究 本文链接地址: Systemtap的另类用法 通常我们在做内核编程的时候,会用到内核的数据结构,比如说textsearch提供了几种算法用于支付串查找。在用于正式的项目前,我们会希望考察下他的用法

[转帖]Systemtap 用法

https://www.jianshu.com/p/fb4dde8baff4 霸爷博客,干货满满。有两篇文章现在还记得,《Linux下如何知道文件被哪个进程写》和《巧用Systemtap注入延迟模拟IO设备抖动》,周末突然想起来,发现能看懂了:) 什么是 systemtap Systemtap is

[转帖]Systemtap系列之语法专辑

1. 常用技巧 systemtap可以实现交叉编译: 编译可执行模块如下: stap -r kernel_version script -m module_name 运行命令如下: staprun module_name.ko stap命令会读取脚本的指令,并翻译成C代码,编译成内核模块加载到内核。

[转帖]systemtap 之 基础命令

https://phpor.net/blog/post/3661 示例1: 通过 -e 选项直接执行probe,如: 1 stap -ve 'probe kernel.function("do_fork") { printf("%-25s %-10d 0x%-x\n", execname(), pi

[转帖]巧用Systemtap注入延迟模拟IO设备抖动

http://blog.yufeng.info/archives/2935 原创文章,转载请注明: 转载自系统技术非业余研究 本文链接地址: 巧用Systemtap注入延迟模拟IO设备抖动 当我们的IO密集型的应用怀疑设备的IO抖动,比如说一段时间的wait时间过长导致性能或其他疑难问题的时候,这个

[转帖]s-systemtap工具使用图谱(持续更新)

整体的学习思维导图如下,后续持续更新完善文章目录​​安装​​​​简介​​​​执行流程​​​​执行方式​​​​stap脚本语法​​​​探针语法​​​​API函数​​​​探针举例​​​​变量使用​​​​基本应用​​​​1. 定位函数位置​​​​2. 查看文件能够添加探针的位置​​​​3. 打印函数参数(

[转帖]s-systemtap工具使用图谱(持续更新)

整体的学习思维导图如下,后续持续更新完善文章目录​​安装​​​​简介​​​​执行流程​​​​执行方式​​​​stap脚本语法​​​​探针语法​​​​API函数​​​​探针举例​​​​变量使用​​​​基本应用​​​​1. 定位函数位置​​​​2. 查看文件能够添加探针的位置​​​​3. 打印函数参数(

[转帖]小技巧!如何用 systemtap 排查问题

https://www.modb.pro/db/79444 霸爷博客,干货满满。有两篇文章现在还记得,《Linux下如何知道文件被哪个进程写》[1]和《巧用Systemtap注入延迟模拟IO设备抖动》[2],周末突然想起来,发现能看懂了:) 本文虽然说是小技巧,可是难度一点也不低 ^_^ 什么是 s