将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 */
...
相关文章
|
机器学习/深度学习 监控 Ubuntu
perf性能分析工具使用分享
perf性能分析工具使用分享
1717 0
perf性能分析工具使用分享
|
Linux 虚拟化 监控
PERF EVENT 硬件篇
简介 本文将通过以 X86 为例子介绍硬件 PMU 如何为 linux kernel perf_event 子系统提供硬件性能采集功能 理解硬件 MSR (Model Specify Register) 可以理解为CPU硬件的专用寄存器,下述的所有寄存器都是这个类型 汇编指令 rdmsr/wrm.
3803 0
|
C++
如何使用MACS进行peak calling
MACS2是peak calling最常用的工具。 callpeak用法 这是MACS2的主要功能,因为MACS2的目的就是找peak,其他功能都是可有可无,唯独callpeak不可取代。
3799 0
|
17天前
|
前端开发 Linux 调度
ftrace、perf、bcc、bpftrace、ply的使用
ftrace、perf、bcc、bpftrace、ply的使用
|
15天前
|
Linux
perf_event_open学习 —— 缓冲区管理
perf_event_open学习 —— 缓冲区管理
|
12月前
|
数据可视化 Linux 调度
译 | Linux perf_events Off-CPU Time Flame Graph
译 | Linux perf_events Off-CPU Time Flame Graph
89 0
|
传感器 算法 Linux
Perf Subsystem —— 基于PMI实现的NMI Watchdog
## 背景 任务能否被及时响应,对内核来说,至关重用。Linux kernel实现了softlockup和hardlockup,用于检测系统是否出现了长时间无响应。 &gt; A ‘softlockup’ is defined as a bug that causes the kernel to loop in kernel mode for more than 20 seconds, with
2022 1
|
Linux
PERF EVENT 硬件篇续 -- core/offcore/uncore
简介 在上篇中,我们简单介绍 PERF EVENT 如何在硬件层面给予测量性能的能力,在这篇中我们继续针对硬件性能事件的类型做进一步介绍以理清我们日常在沟通中会遇到的一些概念。 在上篇介绍中我们介绍了三种事件捕捉实现 通用事件 PMCx & PERFEVETSELx 专用事件 FIXED_CTRx.
6353 0