配置trace_filter.conf文件
用户可以通过配置trace_filter.conf文件,对Java函数的追踪过程进行插桩与过滤,若未进行配置,工具将使用默认配置对Java函数进行追踪。
前提条件
以动态源码优化工具安装路径“/home/DevKit-Optimizer-CLI-x.x.x-Linux-Kunpeng”为例。
操作步骤
- 进入动态源码优化工具解压后的目录,打开trace_filter.conf文件。
vim conf/trace_filter.conf
- 按“i”进入编辑模式,修改配置文件。
# Trace filter configuration. ############################ Trace parameters ############################ # All key=value parameters must appear before the first [xxx] filter section. ############################ Java trace parameters ############################ # Number of entries in the shared-memory ring buffer. # Each compact entry occupies 64 bytes and stores one method-enter or method-exit event. # Memory usage: slot_count * 64 bytes + about 59 MB metadata (Method/module and thread names). # Default: 2097152 slots (about 187 MB), Maximum: 67108864 slots (about 4.06 GB) # Increase this value further for high-frequency methods or long collection intervals. slot_count=2097152 # Java call-graph context expansion depth. Valid range: 0-5. # The total number of additional methods is limited by 'context_max_methods'. # 0 disables expansion and instruments only UTraceAttr, devopt record and [java_include] matches. # Values greater than 0 may add caller/callee methods around matched methods. context_depth=0 # Upper limit for additional methods produced by call-graph context expansion shared by all directly matched methods # Valid range: 0-4096. 0 disables context expansion. Default: 128. context_max_methods=128 ############################ Native trace parameters ############################ # Sampling period for native entry and return probes. Default: 4000. native_sample_period=4000 ############################ Kernel trace parameters ############################ # Per-CPU ftrace ring-buffer size used by trace_pipe_raw, in KiB. # Default: 1024. Valid range: 1-16384. Total allocation scales with online CPUs. kernel_ftrace_buffer_size_kb=1024 # Whether function_graph records selected functions running in interrupt context. kernel_ftrace_irqs=true ############################ Java trace filters ############################ # Java rule syntax. Please refer to the following input format: # com.example.service.* # Match classes directly in com.example.service, but not subpackages. # com.example.service.** # Match classes in com.example.service and all nested subpackages. # com.example.Foo # Match every eligible method declared by this exact class. # com.example.Foo::bar # Match method bar in class com.example.Foo, any descriptor. # com.example.Foo::ba* # Match methods whose names start with ba in class com.example.Foo. # com.example.Foo::bar(Ljava/lang/String;)V # Match method bar with the exact JVM method descriptor. # Additional classes or methods to instrument besides UTraceAttr symbols. [java_include] # Java classes or methods excluded from instrumentation with the highest priority. [java_exclude] # Agent and trace runtime com.libkperf.tracex.** # high-frequency JDK infrastructure java.lang.** java.util.** java.io.** java.nio.** java.net.** java.lang.instrument.** # Internal JDK implementation packages are unstable and frequently contain VM/native bridge code. jdk.** sun.** com.sun.** # Bytecode transformation frameworks may run while classes are being loaded or retransformed org.objectweb.asm.** net.bytebuddy.** javassist.** ############################ Native trace filters ############################ # Native C, C++ and Go trace filters. # Include formats: # function_name # Resolve an exact symbol from the target process mappings; exactly one ELF module must match. # Wildcard characters are not supported for automatic module resolution. # /absolute/path/to/module.so::function_name # Select an exact module explicitly, e.g. /opt/app/lib/libmath.so::math_phase_one. # Exclude Format: function_name or /absolute/path/to/module.so::function_name [native_include] [native_exclude] ############################ Kernel trace filters ############################ # Rules are kernel function-name patterns, for example do_futex or __arm64_sys_*. [kernel_include] [kernel_exclude] # Exclude tracing internals, process termination paths, and scheduler switch internals by default *ftrace* ring_buffer_* do_exit panic __switch_to* finish_task_switch* # Default exclusions for high-frequency low-level functions __schedule schedule _raw_spin_* preempt_* ktime_get* sched_clock* printk*
表1 配置项说明 配置项
说明
slot_count
共享内存缓冲区的槽位数量,用于配置工具在共享内存缓冲区可记录的Java追踪事件数量,默认值为2,097,152个槽位(约187MB),取值范围为0 ~ 67,108,864(约4.06GB)。当需要追踪高频调用的函数或进行较长时间的数据采集时,建议增加该配置值。
context_depth
Java函数调用链上下文扩展深度,默认值为0,取值范围为0 ~ 5。
- 0:表示工具不进行上下文扩展,仅对热点函数以及包含列表中的函数进行插桩操作。
- 大于0的整数:表示工具进行上下文扩展的深度,即对函数调用链中其他函数进行插桩的层数。
context_max_methods
上下文扩展函数的最大数量,默认值为128,取值范围为0 ~ 4,096。当该配置项为0时表示工具关闭上下文扩展。
java_include
包含列表,用于填写需要工具进行插桩操作的Java类或方法,默认为空。该配置项为空时工具默认对热点函数进行插桩操作。填写格式可参考以下示例。
- com.example.service.*:表示匹配com.example.service包下的类,不包括子包的类。
- com.example.service.**:表示匹配com.example.service包及所有子包下的类。
- com.example.Foo:表示匹配com.example.Foo类中声明的所有方法。
- com.example.Foo::bar:表示匹配com.example.Foo类中的bar方法,可匹配任何描述符。
- com.example.Foo::ba*:表示匹配com.example.Foo类中以ba开头的方法。
- com.example.Foo::bar(Ljava/lang/String;)V:表示匹配具有指定JVM方法描述符的bar方法。
java_exclude
排除列表,用于填写无需工具进行插桩操作的Java类或方法,默认值如文件所示。填写格式与包含列表中的示例相同。
须知:移除某些默认值可能会导致数据采集失败,建议保留默认值。
native_sample_period
采样周期,用于指定采样原生代码的固定间隔,默认值如文件所示。
native_include
包含列表,用于填写需要工具进行追踪操作的用户态函数,默认为空。填写格式可参考以下示例。
- function_name:表示追踪所有模块中匹配该函数名的函数。
- /absolute/path/to/module.so::function_name:表示仅追踪指定共享库文件中的特定函数。
native_exclude
排除列表,用于填写无需工具进行追踪操作的用户态函数,默认值如文件所示。填写格式与包含列表中的示例相同。
说明:如果不同模块有同名函数,可能会同时被排除追踪,需谨慎使用。
kernel_ftrace_buffer_size_kb
每个CPU核心的ftrace环形缓冲区大小,默认值为1024。
kernel_ftrace_irqs
是否采集硬中断(IRQ)上下文中的内核函数调用,默认值为true。
kernel_include
包含列表,用于填写需要工具进行追踪操作的内核函数,默认为空。填写格式可参考以下示例。
symbol_pattern:表示追踪所有模块中匹配该函数名的函数。
kernel_exclude
排除列表,用于填写无需工具进行追踪操作的内核函数,默认值如文件所示。填写格式与包含列表中的示例相同。
说明:如果不同模块有同名函数,可能会同时被排除追踪,需谨慎使用。
- 按“Esc”键退出编辑模式,输入:wq!,按“Enter”键保存并退出文件。
- 完成配置并采集数据后,可使用report命令查看Java函数的调用链信息。