---
title: 热点函数分析
description: "支持分析C/C++程序代码识别性能瓶颈，给出对应的Top热点函数和调用栈详情。通过火焰图展示函数的调用关系，发现优化路径。"
url: https://www.hikunpeng.com/document/detail/zh/kunpengdevkithistory/devkit_24_t50/cliuserguide/KunpengDevKitCli_0065.html
sourcePath: /source/zh/kunpengdevkithistory/devkit_24_t50/cliuserguide/KunpengDevKitCli_0065.html
indexId: c3073a83e22d835cba213a73c9a98de5f4c12e1f941ba59628a86f4764ae21b685
---
# 热点函数分析

#### 命令功能

支持分析C/C++程序代码识别性能瓶颈，给出对应的Top热点函数和调用栈详情。通过火焰图展示函数的调用关系，发现优化路径。


#### 命令格式

```
devkit tuner hotspot [-h] [-c {n | n,m | n-m}] [-d <sec>] [-D <sec>] [-f n] [-l {0, 1, 2, 3}] [-i <sec>] [-r {user, kernel, all}] [-o] [-s] [-p {PID1 | PID1,PID2 | ALL}] [-g] [--package] [--long-name] [--dwarf] [workload workload...]
```

工具可采集指定应用，命令中[workload workload...]替换为应用路径加应用参数。


#### 参数说明


**表1 参数说明**

| 参数 | 参数选项 | 说明 |
| --- | --- | --- |
| \-h/\-\-help | \- | 获取帮助信息。 |
| \-c/\-\-cpu | \- | 指定采集的CPU核数，如“0”、“0,1,2”、“0\-2”。 |
| \-d/\-\-duration | \- | 设置采集时长，单位为秒，最小值为1秒，默认为一直采集，可使用Ctrl+\取消任务或Ctrl+C停止采集并进入分析。 |
| \-D/\-\-delay | \- | 设置延迟采样时长，默认为0秒，需小于采集时长。 |
| \-i/\-\-interval | \- | 设置采集间隔（以秒为单位）。最小值为1秒，最大值不能超过采集时长，默认为采集时长。如果不指定间隔，不生成子报告。每个子报告中收集数据的时间取决于间隔参数。 |
| \-l/\-\-log\-level | 0/1/2/3 | 设置日志级别，默认为1。 0：日志级别为DEBUG。 1：日志级别为INFO。 2：日志级别为WARNING。 3：日志级别为ERROR。 |
| \-f/\-\-frequency | \- | 设置采样频率，最小值为1次/秒，默认为200次/秒。 |
| \-e/\-\-event | \- | 设置需要采集的事件，可通过devkit tuner hotspot list查看可采集事件。 |
| \-o/\-\-output | \- | 设置报告数据压缩包名称和输出路径，仅输入名称时默认生成在当前所在目录；需和\-\-package配合使用。 |
| \-r/\-\-collection\-range | user/kernel/all | 设置采集模式，默认为all。 all：采集用户态和内核态的性能数据。 user：采集用户态的性能数据。 kernel：采集内核态的性能数据。 |
| \-s/\-\-src\-dir | \- | 指定源码工作目录，用于查找并关联源码，可将任务导入Web端查看。 |
| \-g | \- | 显示调用堆栈信息。如果启用\-g选项，将生成火焰图html文件，默认生成在用户所在目录。 |
| \-p/\-\-pid | PID/PID1，PID2/ALL | 指定采集的进程PID，多个进程PID可用“,”分隔。默认采集全部进程（ALL）。若同时使用\-p和\-c参数则优先采集指定PID的进程。 |
| \-\-long\-name | \- | 设置是否显示详细函数和模块信息。不使用此参数默认简洁显示模块或功能信息。 |
| \-\-dwarf | \- | 设置是否生成C/C++的源代码或汇编代码文件。 |
| \-t/\-\-top | \- | 设置报告中显示数据数量，最小值为1个。 |
| \-\-package | \- | 设置是否生成报告数据压缩包，不指定压缩包名称和路径时默认在当前所在目录生成hotspot\-时间戳.tar。 |


#### 使用示例

```
devkit tuner hotspot -c 0-127 -d 3 -i 1 -o /home/hotspot_cpu -g --package --long-name
```

返回信息如下：

```
Hotspot Summary Report-1                                Time:2024/07/19 10:12:32
================================================================================

────────────────────────────────────────────────────────────────────
Function                                               cycles      Module                                                cycles(%)
──────────────────────────────────────────────────────────────────── 
  __do_softirq                                     108,999,839     [kernel]                                                  57.88
  arch_cpu_idle                                     55,335,310     [kernel]                                                  29.38
  avc_lookup                                         8,693,198     [kernel]                                                   4.62
  0xfd950                                            3,706,419     /home/devkit/libsqlite3/libsqlite3.so.0.8.6                1.97
  dput                                               3,706,419     [kernel]                                                   1.97
  __set_current_blocked                              3,041,886     [kernel]                                                   1.62
  smp_call_function_single                           2,763,855     [kernel]                                                   1.47
  __clock_gettime                                    1,135,231     /usr/lib64/libc.so.6                                       0.60
  0x7eab4                                              879,665     /usr/lib64/libc.so.6                                       0.47
  generic_exec_single                                   67,298     [kernel]                                                   0.04
────────────────────────────────────────────────────────────────────
Hotspot Summary Report-2                                Time:2024/07/19 10:12:33
================================================================================
──────────────────────────────────────────────────────────────────── 
Function                                                                cycles      Module                                cycles(%)
─────────────────────────────────────────────────────────────────────  std::pair<std::_Rb_tree_iterator<std::pair<unsigned long cons       81,259,412    /root/DevKit-CLI-24.0.xx-Linux-
                                                                                    Kunpeng/tuner/lib/libsym.so              14.11
  t, elf::sym> >, bool> std::_Rb_tree<unsigned long, std::pair<
  unsigned long const, elf::sym>, std::_Select1st<std::pair<uns
  igned long const, elf::sym> >, std::less<unsigned long>, std:
  :allocator<std::pair<unsigned long const, elf::sym> > >::_M_i
  nsert_unique<std::pair<unsigned long const, elf::sym> const&>
  (std::pair<unsigned long const, elf::sym> const&)
  malloc                                                             76,662,049    /usr/lib64/libc.so.6                      13.32
  KUNPENG_SYM::SymbolResolve::RecordElf(char const*)                 38,279,588    /root/DevKit-CLI-24.0.xx-Linux- 
                                                                                   Kunpeng/tuner/lib/libsym.so                6.65
  std::_Sp_counted_base<(__gnu_cxx::_Lock_policy)2>::_M_release      25,561,443    /root/DevKit-CLI-24.0.xx-Linux-
                                                                                   Kunpeng/tuner/libtuner.so                  4.44
  ()
  rt6_probe                                                            735,855    [kernel]                                    0.13
  flush_smp_call_function_from_idle                                    530,160    [kernel]                                    0.09
  G1YoungRemSetSamplingClosure::do_heap_region(HeapRegion*)            406,124    /home/bisheng-jdk17/lib/server/libjvm.so    0.07
─────────────────────────────────────────────────────────────────────Hotspot Summary Report-3                                Time:2024/07/19 10:12:34
================================================================================

──────────────────────────────────────────────────────────────────── 
Function                                                                     cycles    Module                                                           cycles(%)
─────────────────────────────────────────────────────────────────────────────────────  
  0x8e09c14                                                               132,887,377    /home/bisheng-jdk17/lib/libzip.so                                    21.48
  std::pair<std::_Rb_tree_iterator<std::pair<unsigned long cons            57,971,051    /root/DevKit-CLI-24.0.xx-Linux-Kunpeng/tuner/lib/libsym.so           9.37
  t, elf::sym> >, bool> std::_Rb_tree<unsigned long, std::pair<
  unsigned long const, elf::sym>, std::_Select1st<std::pair<uns
  igned long const, elf::sym> >, std::less<unsigned long>, std:
  :allocator<std::pair<unsigned long const, elf::sym> > >::_M_i
  nsert_unique<std::pair<unsigned long const, elf::sym> const&>
  (std::pair<unsigned long const, elf::sym> const&)
  0x8e09a4c                                                                33,494,056    /home/bisheng-jdk17/lib/libzip.so                                     5.41
  0x8e09a84                                                                31,358,880    /home/bisheng-jdk17/lib/libzip.so                                     5.07
  arch_cpu_idle                                                            21,190,896    [kernel]                                                              3.43

  0xffff800008f78d80                                                          781,761    [kernel]                                                              0.13
  ldsem_down_read_trylock                                                     738,684    [kernel]                                                              0.12
─────────────────────────────────────────────────────────────────────────────────────
Hotspot Summary Report-ALL                              Time:2024/07/19 10:12:32
================================================================================

─────────────────────────────────────────────────────────────────────────────────────
Function                                                                   cycles      Module                                                            cycles(%)
─────────────────────────────────────────────────────────────────────────────────────  
  std::pair<std::_Rb_tree_iterator<std::pair<unsigned long cons           139,230,463    /root/DevKit-CLI-24.0.xx-Linux-Kunpeng/tuner/lib/libsym.so          10.07
  t, elf::sym> >, bool> std::_Rb_tree<unsigned long, std::pair<
  unsigned long const, elf::sym>, std::_Select1st<std::pair<uns
  igned long const, elf::sym> >, std::less<unsigned long>, std:
  :allocator<std::pair<unsigned long const, elf::sym> > >::_M_i
  nsert_unique<std::pair<unsigned long const, elf::sym> const&>
  (std::pair<unsigned long const, elf::sym> const&)
  G1YoungRemSetSamplingClosure::do_heap_region(HeapRegion*)                   406,124    /home/bisheng-jdk17/lib/server/libjvm.so                              0.03
─────────────────────────────────────────────────────────────────────────────────────
3348 milliseconds time elapsed

Callstack is saved to /home/callstack-20240719-101232.log
Flamegraph is saved to /home/Flamegraph-20240719-101232.html
The report /home/hotspot_cpu1.tar is generated successfully.
To view summary report. you can run: devkit report -i /home/hotspot_cpu1.tar
To view detail report. you can import the report to the WebUI or IDE to view details.
```

生成的火焰图html文件默认生成在用户所在目录，火焰图html文件可使用浏览器查看。

图1 火焰图html
