mirror of
https://github.com/eunomia-bpf/bpf-developer-tutorial.git
synced 2026-11-02 05:35:41 +08:00
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:
@@ -419,6 +419,8 @@ Reference: <https://github.com/iovisor/bcc/blob/master/libbpf-tools/memleak.c>
|
||||
|
||||
## Compile and Run
|
||||
|
||||
This implementation uses the latest **blazesym v0.2.0** library for symbol resolution, which provides improved performance and a modern C API through the `capi` package.
|
||||
|
||||
```console
|
||||
$ make
|
||||
$ sudo ./memleak
|
||||
@@ -438,6 +440,35 @@ Tracing outstanding memory allocs... Hit Ctrl-C to end
|
||||
...
|
||||
```
|
||||
|
||||
## Testing memleak
|
||||
|
||||
This repository includes a test program (`test_memleak.c`) that intentionally leaks memory for testing purposes. You can build and run it to verify that memleak correctly detects memory leaks:
|
||||
|
||||
```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
|
||||
```
|
||||
|
||||
As shown above, memleak successfully:
|
||||
- Detected **10240 bytes in 5 allocations** (5 × 2048 bytes) that were leaked
|
||||
- Identified the leaking function **leak_with_loop+0x1f** with the correct offset
|
||||
- Provided the complete call stack showing the leak originated from `main` function
|
||||
- Used the new **blazesym v0.2.0** C API for fast and accurate symbol resolution
|
||||
|
||||
The test demonstrates that memleak with the updated blazesym library can effectively trace memory allocations and pinpoint the exact functions responsible for memory leaks.
|
||||
|
||||
## Summary
|
||||
|
||||
Through this eBPF introductory tutorial, you have learned how to write a Memleak eBPF monitoring program to monitor memory leaks in real time. You have also learned about the application of eBPF in memory monitoring, how to write eBPF programs using the BPF API, create and use eBPF maps, and how to use eBPF tools to monitor and analyze memory leak issues. We have provided a detailed example to help you understand the execution flow and principles of eBPF code.
|
||||
|
||||
Reference in New Issue
Block a user