---
title: 使用KUPL PROF进行全量的函数时序统计
description: "KUPL对外提供profile和trace两个工具，来提供运行时的时序统计，通过动态链接到prof对应的动态链接库来使能profile和trace功能。"
url: https://www.hikunpeng.com/document/detail/zh/kunpenghpcs/hpckit/devg/KunpengHPCKit_developer_014.html
sourcePath: /source/zh/kunpenghpcs/hpckit/devg/KunpengHPCKit_developer_014.html
indexId: d965e00b2dfbe478d4a8714bb8bdb6c37274f539cc8f06fe7faf2a4ba536692667
---
# 使用KUPL PROF进行全量的函数时序统计

KUPL对外提供profile和trace两个工具，来提供运行时的时序统计，通过动态链接到prof对应的动态链接库来使能profile和trace功能。

1. 节点上安装HPCkit(https://www.hikunpeng.com/developer/hpc/hpckit-download)，HPCKit安装指导请参见《Kunpeng HPCKit 26.1.RC1 安装指南》(https://www.hikunpeng.com/document/detail/zh/kunpenghpcs/hpckit/instg/KunpengHPCKit_install_024.html)
2. 通过setvars.sh --kupl_mode=prof链接到prof动态链接库。
3. 运行程序时额外配置环境变量KUPL_PROF_LEVEL=statistic来开启特定的函数累计计时，KUPL_PROF_LEVEL=trace来开启全量的函数时序统计。
4. 程序运行结束时，如果配置了KUPL_PROF_LEVEL=statistic或 KUPL_PROF_LEVEL=trace则会在程序运行打印结尾生成函数累计计时profile报告（报告表头字段详情见表1 函数累计计时profile报告的表头字段说明），如果配置了KUPL_PROF_LEVEL=trace还可以在程序运行目录下生成ptrace文件，其中包含各个进程中各个线程运行情况的统计文件（以.json文件保存），该文件可以通过chrome://tracing网页（请使用chrome 94以上版本的Chrome浏览器运行）来观看可视化版本报告（即把想要观看的文件导入进网页）。
**表1 函数累计计时profile报告的表头字段说明**

| 信息名称 | 描述 |
| --- | --- |
| thread\_id | 执行线程id |
| msg\_id | 函数信息号 |
| msg | 函数信息名称 |
| sum(ms) | 函数总耗时（毫秒） |
| count | 函数执行次数 |
| avg(ns) | 函数平均耗时（纳秒） |
| max(ns) | 函数单次最大耗时（纳秒） |
| min(ns) | 函数单次最小耗时（纳秒） |


**表2 函数累计计时profile报告的msg字段支持种类含义说明**

| msg信息名称 | 函数行为 |
| --- | --- |
| task\_execute | 提交给KUPL的任务执行耗时 |
| task\_finish | 提交给KUPL的任务执行完毕后释放资源耗时 |
| sched\_add\_taskbase | 向KUPL底层Sched中提交任务耗时 |
| sched\_get\_taskbase | 从KUPL底层Sched中获取任务耗时 |


  通过网页观看可视化版本报告建议使用Chrome浏览器。
