将perf跟funcgraph-retval结合起来使用

简介: 将perf跟funcgraph-retval结合起来使用

作者

pengdonglin137@163.com

概述

下面是之前写的使用funcgraph-retval的文章:

上面的文章里,都是直接通过命令行配置ftrace来使用的,过程稍微有些繁琐,linux提供了perf工具,通过perf工具可以简化上面的一些操作。

正文

这里用到的是perf的ftrace子命令,帮助信息如下:

# perf ftrace -h
 Usage: perf ftrace [<options>] [<command>]
    or: perf ftrace [<options>] -- [<command>] [<options>]
    or: perf ftrace {trace|latency} [<options>] [<command>]
    or: perf ftrace {trace|latency} [<options>] -- [<command>] [<options>]
    -D, --delay <n>       Number of milliseconds to wait before starting tracing after program start
    -F, --funcs <[FILTER]>
                          Show available functions to filter
    -G, --graph-funcs <func>
                          Trace given functions using function_graph tracer
    -g, --nograph-funcs <func>
                          Set nograph filter on given functions
    -m, --buffer-size <size>
                          Size of per cpu buffer, needs to use a B, K, M or G suffix.
    -N, --notrace-funcs <func>
                          Do not trace given functions
    -T, --trace-funcs <func>
                          Trace given functions using function tracer
    -t, --tracer <tracer>
                          Tracer to use: function_graph(default) or function
        --func-opts <options>
                          Function tracer options, available options: call-graph,irq-info
        --graph-opts <options>
                          Graph tracer options, available options: nosleep-time,noirqs,verbose,thresh=<n>,depth=<n>
        --inherit         Trace children processes

ftrace子命令默认使用的是function_graph这个跟踪器,并且提供了下面一些辅助选项:

-G 指定要跟踪的函数,只能设置一个
-g 设置不跟踪的函数,只能设置一个
--graph-opts 控制输出哪些信息,比如verbose参数可以输出最详细的信息

下面以cat /proc/stat为例:

# echo 1 > /sys/kernel/tracing/options/funcgraph-retval
# perf ftrace -G ksys_read cat /proc/stat

可以得到下面的日志:

...
 43)               |    vfs_read() {
 43)               |      rw_verify_area() {
 43)               |        security_file_permission() {
 43)               |          selinux_file_permission() {
 43)               |            inode_security() {
 43)   0.159 us    |              __cond_resched(); /* = 0x0 */
 43)   0.475 us    |            } /* inode_security = 0xffff88811534def8 */
 43)   0.160 us    |            avc_policy_seqno(); /* = 0x1 */
 43)   1.103 us    |          } /* selinux_file_permission = 0x0 */
 43)   0.161 us    |          bpf_lsm_file_permission(); /* = 0x0 */
 43)   1.865 us    |        } /* security_file_permission = 0x0 */
 43)   2.151 us    |      } /* rw_verify_area = 0x0 */
 43)   0.174 us    |      __get_task_ioprio(); /* = 0x4004 */
 43)               |      proc_reg_read_iter() {
 43)               |        seq_read_iter() {
 43)               |          mutex_lock() {
 43)   0.172 us    |            __cond_resched(); /* = 0x0 */
 43)   0.482 us    |          } /* mutex_lock = 0x0 */
 43)   0.160 us    |          single_start(); /* = 0x0 */
 43)   0.162 us    |          single_stop(); /* = 0xffffffff81490e70 */
 43)   0.251 us    |          mutex_unlock(); /* = 0xffff888836c3d180 */
 43)   2.244 us    |        } /* seq_read_iter = 0x0 */
 43)   2.689 us    |      } /* proc_reg_read_iter = 0x0 */
 43)   5.745 us    |    } /* vfs_read = 0x0 */
...
目录
打赏
0
2
2
1
113
分享
相关文章
PERF EVENT 硬件篇
简介 本文将通过以 X86 为例子介绍硬件 PMU 如何为 linux kernel perf_event 子系统提供硬件性能采集功能 理解硬件 MSR (Model Specify Register) 可以理解为CPU硬件的专用寄存器,下述的所有寄存器都是这个类型 汇编指令 rdmsr/wrm.
3953 0
Perf Arm SPE介绍与使用
本次分享的主题是 Perf Arm-SPE 的介绍及使用,本次分享主要介绍如何在倚天 710 平台上利用 Arm-SPE 特性定位伪共享问题、分析内存访问、分析指令延时以及监控访存延时等功能。 1. 背景介绍 2. Arm SPE的原理 3. Arm SPE在倚天服务器上的应用 4. Arm SPE 更多特性与功能的探索
ftrace、perf、bcc、bpftrace、ply的使用
ftrace、perf、bcc、bpftrace、ply的使用
|
5月前
|
perf_event_open学习 —— 缓冲区管理
perf_event_open学习 —— 缓冲区管理
Linux性能分析工具-perf并生成火焰图
Linux性能分析工具-perf并生成火焰图
【 C/C++ 性能分析工具 CPU 采样分析器 perf 】掀开Linux perf性能分析的神秘面纱
【 C/C++ 性能分析工具 CPU 采样分析器 perf 】掀开Linux perf性能分析的神秘面纱
496 0
译 | Linux perf_events Off-CPU Time Flame Graph
译 | Linux perf_events Off-CPU Time Flame Graph
129 0

热门文章

最新文章

AI助理

你好,我是AI助理

可以解答问题、推荐解决方案等