首页 > 其他分享 >bcc-tools工具之profile

bcc-tools工具之profile

时间:2024-04-07 11:22:05浏览次数:16  
标签:profile kernel -- bcc only stack tools stacks

profile是用于追踪程序执行调用流程的工具,类似于perf中的-g指令

相比perf -g而言,profile功能化更加细分,可以根据需要选择追踪层面,例如-U(用户要调用流程) -K (内核态调用流程)

下面具体介绍该工具的使用

采用profile --help,我们可以看到如下介绍:

usage: profile [-h] [-p PID] [-U | -K] [-F FREQUENCY | -c COUNT] [-d] [-a]
               [-f] [--stack-storage-size STACK_STORAGE_SIZE] [-C CPU]
               [duration]

Profile CPU stack traces at a timed interval

positional arguments:
  duration              duration of trace, in seconds   # profile的持续时间

optional arguments:
  -h, --help            show this help message and exit
  -p PID, --pid PID     profile this PID only           # 只追踪该pid的调用流程
  -U, --user-stacks-only                   # 查看用户态函数调用流程
                        show stacks from user space only (no kernel space
                        stacks)
  -K, --kernel-stacks-only                  # 只查看内核态调用流程
                        show stacks from kernel space only (no user space
                        stacks)
  -F FREQUENCY, --frequency FREQUENCY                   # profile追踪采样频率  例如: -F 99  表示按照99hz的频率进行采样,默认是采用的49hz
                        sample frequency, Hertz
  -c COUNT, --count COUNT                   # 选择采样次数 -c 5表示在周期内采样5次,-c和-F两者不能同时使用
                        sample period, number of events 
  -d, --delimited       insert delimiter between kernel/user stacks  # 在内核和用户态之间插入分界符 “---”
  -a, --annotations     add _[k] annotations to kernel frames        # 在显示的内核函数后面标记 '[k]'标识
  -f, --folded          output folded format, one line per stack (for flame #采用横向线上模式 xxx;xxx_1;xxxxx_2
                        graphs)
  --stack-storage-size STACK_STORAGE_SIZE                 # 设置调用栈的使用空间和默认支持空间大小
                        the number of unique stack traces that can be stored
                        and displayed (default 16384)
  -C CPU, --cpu CPU     cpu number to run profile on           # 允许几个cpu运行profile程序     

examples:
    ./profile             # profile stack traces at 49 Hertz until Ctrl-C
    ./profile -F 99       # profile stack traces at 99 Hertz
    ./profile -c 1000000  # profile stack traces every 1 in a million events
    ./profile 5           # profile at 49 Hertz for 5 seconds only
    ./profile -f 5        # output in folded format for flame graphs
    ./profile -p 185      # only profile threads for PID 185
    ./profile -U          # only show user space stacks (no kernel)
    ./profile -K          # only show kernel space stacks (no user)

下面对相关重要指令进行测试分析:

  1. profile -f

在没有添加-f参数时,可看出是一行线上一个函数调用信息

加入-f参数后,采用每行递增线上函数调用信息。

  1. profile -d :用于将内核态和用户态函数通过"--"分割开来,如下图红色框框所示

  1. profile -F :用于设置该工具采样频率

  1. profile -K -a :用于仅显示内核调用函数,并且在函数后面增加"_[K]"标识 (156标识进程id号)

  1. profile -c :在采样周期内对每一个线程xx个event进行采样

标签:profile,kernel,--,bcc,only,stack,tools,stacks
From: https://www.cnblogs.com/linhaostudy/p/18118701

相关文章

  • My Profile
    ......
  • Win+Anaconda环境下安装pycocotools
    pipinstall-U'git+https://github.com/cocodataset/cocoapi.git#subdirectory=PythonAPI'参照项目的配置环境,使用pipinstall下载pycocotools出现了报错:解决方法:在终端中输入以下代码,成功下载:pipinstallpycocotools-windows-ihttps://pypi.tuna.tsinghua.edu......
  • (谷歌浏览器)如何在vscode中搭建vue.js devtools的环境
    搭建过程中明明所有操作步骤都做了,却还是出现下面这种情况: 以下是正确的搭建操作步骤:根据一下图片在vscode中创建文件夹;将以下代码写入; <scripttype="text/javascript"src="../js/vue.js"></script>接下来就是我们需要点击https://vuejs.zcopy.site/,进入到网站后,......
  • 5.103 BCC工具之filegone.py解读
    一,工具简介filegone 追踪文件消失的原因,无论是被删除还是被重命名。二,代码示例#!/usr/bin/pythonfrom__future__importprint_functionfrombccimportBPFimportargparsefromtimeimportstrftime#argumentsexamples="""examples:./filegone......
  • 5.102 BCC工具之filelife.py解读
    一,工具简介filelife 追踪短生命周期的文件:那些在追踪过程中被创建然后又被删除的文件。二,代码示例#!/usr/bin/envpythonfrom__future__importprint_functionfrombccimportBPFimportargparsefromtimeimportstrftime#argumentsexamples="""examples:......
  • setuptools 对于现代python包支持的简单试用
    以前我们编写python包通过setuptools是编写配置setup.cfg以及一个setup.py文件,现代的玩法是基于pyproject.toml以下是一个简单学习项目准备使用venvclipython-mvenvvenvsourcevenv/bin/activate创建项目文件pyproject.toml,里边包含了build......
  • 5.95 BCC工具之dcsnoop.py解读
    一,工具简介dcsnoop工具用于追踪目录项缓存(dcache)的查找,并可用于dcstat(8)之外的进一步调查。由于dcache查找可能很频繁,因此输出可能很冗长。默认情况下,仅显示查找失败的情况。二,代码示例#!/usr/bin/envpythonfrom__future__importprint_functionfrombccimport......
  • 5.96 BCC工具之dcstat.py解读
    一,工具简介1.1 dcache介绍dcache,即目录项缓存(DirectoryEntryCache),是Linux内核中的一个重要缓存机制。它主要用于缓存文件系统中的目录项信息,包括文件和目录的名称、位置、权限等元数据。这些元数据在文件系统中被频繁访问,因此将它们缓存在内存中可以显著提高文件访问的性......
  • 安装VMwaretools
    首先:开机弹出镜像关机在开机(先别进桌面)右键虚拟机——》重装vmwaretools进去桌面把tgz文件移动到opt目录下,移动不了》权限不够,右键打开终端输入su输入root密码然后输入sudonautilus然后会出现一个可操作的文件夹,在这里移动就行回到终端看看自己操作前面有没有root......
  • Java 程序性能分析利器:IDEA Profiler,相见恨晚
    一个javawebapi,耗时2s,但是db300ms就返回了,时间到底耗费在哪里呢。当我最终定位下来,是因为db返回了5M数据跨局域网传输大概需要1s,导致的。一行行跟踪源码,很耽误时间。后来遇到了IDEAProfiler(IDEAIDE自带的性能分析工具),简直太好用了。https://www.jetbrains.com/pag......