
# Profiler分析代码性能概述
#### 使用限制
- Profiler性能分析，当前受限使用。
- Alpine Linux系统不支持Profiler功能。因为Alpine Linux是一个轻量级的Linux系统发行版，缺少运行Profiler的必要依赖。如果需要支持Profiler功能，建议使用标准Linux操作系统。
- 为了应用运行稳定，强烈建议您按照要求升级JDK版本，在低版本的JDK上使用Profiler性能分析功能，存在应用崩溃的风险。
  表1JDK版本说明 
  | JDK类型      | 版本                                                                                                                                                                                                  |
  |:---|:---|
  | OpenJDK    | - OpenJDK 8u352+  - OpenJDK 17.0.5+   |
  | Oracle JDK | - Oracle JDK 17.0.9+                                                                                     |
     
   表2JavaAgent更新说明 
  | Agent版本                                                              | 说明                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
  |:---|:---|
  | 2.4.17-profiler 2.4.17-profiler-jdk17 | Agent版本2.4.17-profiler/2.4.17-profiler-jdk17及以后版本优化内容如下： 1. 兼容otel协议生成调用链。  2. 修复网关服务返回多个traceid问题。  3. 修复httpclient采集不全问题。  4. 修复外部调用正则表达式失效问题。   |
  | 2.4.16-profiler 2.4.16-profiler-jdk17    | Agent版本2.4.16-profiler/2.4.16-profiler-jdk17及以后版本优化内容如下： 1. 数据库SQL采集器支持设置和采集慢SQL次数和数据库名称。  2. URL采集器支持基于URL和异常类型统计异常数。                                                                                                                                                    |
  | 2.4.15-profiler 2.4.15-profiler-jdk17  | 1. Agent版本2.4.15-profiler/2.4.15-profiler-jdk17及以后版本，优化Profiler在CPU采集的过程中可能存在的内存问题。                                                                                                                                                                                                                                                                                        |
  | 2.4.14-profiler 2.4.14-profiler-jdk17 | 1. Agent版本2.4.14-profiler/2.4.14-profiler-jdk17及以后版本，优化Profiler与其他模块间依赖关系，在环境不支持Profiler的情况下，保证其他功能正常使用。                                                                                                                                                                                                                                                             |
  | 2.4.13-profiler 2.4.13-profiler-jdk17 | 1. Agent版本2.4.13-profiler/2.4.13-profiler-jdk17及以后版本，优化调用链上报逻辑。                                                                                                                                                                                                                                                                                                      |
  | 2.4.12-profiler 2.4.12-profiler-jdk17   | 1. Agent版本2.4.12-profiler/2.4.12-profiler-jdk17及以后版本，优化Debugging诊断处理逻辑。                                                                                                                                                                                                                                                                                                |
  | 2.4.11-profiler 2.4.11-profiler-jdk17   | 1. Agent版本2.4.11-profiler/2.4.11-profiler-jdk17及以后版本，支持Profiler的Live Object Memory类型以及全采样设置。                                                                                                                                                                                                                                                                    |
  | 2.4.10-profiler 2.4.10-profiler-jdk17  | 1. Agent版本2.4.10-profiler/2.4.10-profiler-jdk17及以后版本，支持Debugging诊断以及Profiler的Live Object Memory类型。                                                                                                                                                                                                                                                                  |
  | 2.4.9-profiler 2.4.9-profiler-jdk17   | 1. Agent版本2.4.9-profiler/2.4.9-profiler-jdk17及以后版本，时延度量线程采集算法优化。                                                                                                                                                                                                                                                                                                    |
  | 2.4.8-profiler 2.4.8-profiler-jdk17      | 1. Agent版本2.4.8-profiler/2.4.8-profiler-jdk17及以后版本，支持性能优化推荐。                                                                                                                                                                                                                                                                                                        |
  | 2.4.7-profiler 2.4.7-profiler-jdk17     | 1. Agent版本2.4.7-profiler/2.4.7-profiler-jdk17及以后版本，支持用户包数据采集。                                                                                                                                                                                                                                                                                                     |
  | 2.4.6-profiler 2.4.6-profiler-jdk17     | 1. Agent版本2.4.6-profiler/2.4.6-profiler-jdk17及以后版本，支持Profiler的Latency功能。                                                                                                                                                                                                                                                                                           |
  | 2.4.5-profiler 2.4.5-profiler-jdk17      | 1. Agent版本2.4.5-profiler/2.4.5-profiler-jdk17及以后版本，支持Profiler。                                                                                                                                                                                                                                                                                                      |
     
  表3使用限制以及说明 
  | 序号 | 使用限制及说明                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
  |:---|:---|
  | 1  | Profiler功能当前受限使用，且每个环境最多支持开启500个Profiler。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
  | 2  | Profiler引导页，仅在首次开启Profiler功能时展示。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
  | 3  | Profiler仅支持JAVA。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
  | 4  | 如果-XX:MaxJavaStackTraceDepth为零或负，则不会收集任何Java堆栈。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
  | 5  | - CPU Profiler依赖perf_event_open的系统调用，但因为Linux kernel的Syscall安全策略（seccomp）控制，可能会禁止进程调用特定Syscall。  - Docker环境：执行以下命令运行容器。如需配置更精细化的系统调用控制，请参见https://docs.docker.com/engine/security/seccomp/。   ``` docker run --security-opt seccomp=unconfined  XXX ``` - Kubernetes环境：配置特权容器参数privileged: true，特权容器始终保持为Unconfined。   如需配置更精细化的系统调用控制，请参见https://kubernetes.io/zh-cn/docs/tutorials/security/seccomp/。 |
  | 6  | Profiler为目标进程的每个线程分配8kB perf_event缓冲区,Linux内核中限制了进程perf_event相关的MMap的总内存大小, 在非特权用户下运行时，确保/proc/sys/kernel/perf_event_mlock_kb值足够大（超过8\*线程数）: echo 8\*threads+ 4 \> /proc/sys/kernel/perf_event_mlock_kb 。                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
     
  
 
#### 性能影响
CPU\&内存诊断功能经性能测试，在一般的Spring Web应用所有功能效果全部开启的情况下， CPU增加开销5%左右，堆外增加内存开销50 M左右，GC以及请求延迟增加不明显。
#### 常见问题
在Profiler性能分析的火焰图无数据或其他异常情况下，可以查看profiler日志确定问题原因。详细操作参见[Profiler性能分析常见问题](https://support.huaweicloud.com/apm2_faq/apm_faq_0009.html)。
