Add wall clock analysis (#184)

* Add combined on-CPU and off-CPU profiler script

- Implemented a new profiling tool that captures both on-CPU and off-CPU activity for a specified process.
- The script runs 'oncputime' and 'offcputime' tools simultaneously and combines their results into a unified flamegraph.
- Added functionality to discover threads and profile them individually if the application is multi-threaded.
- Included error handling for tool execution and output processing.
- Created methods for generating flamegraph data and SVG visualizations.
- Added command-line argument parsing for user-defined profiling parameters.
- Implemented detailed analysis reports for both individual threads and overall profiling results.

* feat: integrate blazesym v0.2.0 for improved symbol resolution and add test program for memory leak detection

* docs: update README to enhance wall clock profiling tutorial with detailed explanations and examples

* feat: add wallclock-profiler tests to CI workflow for tool validation

* fix: rename combined_profiler.py to wallclock_profiler.py in test scripts and usage examples
This commit is contained in:
云微
2025-09-30 22:11:52 -07:00
committed by GitHub
parent da67bfcf24
commit 70451702f0
31 changed files with 8584 additions and 53 deletions

View File

@@ -459,6 +459,8 @@ int attach_uprobes(struct memleak_bpf *skel)
## 编译运行
本实现使用最新的 **blazesym v0.2.0** 库进行符号解析,该库通过 `capi` 包提供了改进的性能和现代化的 C API。
```console
$ make
$ sudo ./memleak
@@ -478,6 +480,35 @@ Tracing outstanding memory allocs... Hit Ctrl-C to end
...
```
## 测试 memleak
本仓库包含一个测试程序(`test_memleak.c`),该程序会故意泄漏内存以供测试使用。您可以编译并运行它来验证 memleak 是否能正确检测内存泄漏:
```console
$ make test_memleak
$ ./test_memleak &
$ sudo ./memleak -p $(pidof test_memleak)
using default object: libc.so.6
using page size: 4096
tracing kernel: false
Tracing outstanding memory allocs... Hit Ctrl-C to end
[19:31:49] Top 1 stacks with outstanding allocations:
10240 bytes in 5 allocations from stack
0 [<00005a7ea0a34212>] leak_with_loop+0x1f
1 [<00005a7ea0a3428e>] main+0x6e
2 [<00007b4ea482a1ca>] <null sym>
3 [<00007b4ea482a28b>] __libc_start_main+0x8b
4 [<00005a7ea0a34105>] _start+0x25
```
如上所示,memleak 成功地:
- 检测到 **10240 字节的 5 次分配**(5 × 2048 字节)发生了泄漏
- 识别出泄漏函数 **leak_with_loop+0x1f** 及其正确的偏移量
- 提供了完整的调用栈,显示泄漏源自 `main` 函数
- 使用新的 **blazesym v0.2.0** C API 进行快速准确的符号解析
该测试演示了更新 blazesym 库后的 memleak 可以有效地跟踪内存分配,并精确定位导致内存泄漏的函数。
## 总结
通过本篇 eBPF 入门实践教程,您已经学习了如何编写 Memleak eBPF 监控程序,以实时监控程序的内存泄漏。您已经了解了 eBPF 在内存监控方面的应用,学会了使用 BPF API 编写 eBPF 程序,创建和使用 eBPF maps,并且明白了如何用 eBPF 工具监测和分析内存泄漏问题。我们展示了一个详细的例子,帮助您理解 eBPF 代码的运行流程和原理。