Skip to content

Commit ccac308

Browse files
committed
update readme for describtion
1 parent 998a39b commit ccac308

File tree

9 files changed

+8399
-2334
lines changed

9 files changed

+8399
-2334
lines changed

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
openresty-1.21.4.1
22
openresty-1.21.4.1.tar.gz
3-
.vscode
4-
tools/FlameGraph
3+
.vscode

README.md

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,13 @@ Use ebpf to generate lua flamegraphs:
77
- support `luajit 32/luajit 64`
88
- working well on new kernel(>=5.13)
99
- faster speed
10-
- run only small binary without any dependencies
10+
- run only a small binary without any dependencies
1111

12-
## probe nginx lua
12+
> Note:
13+
> - for the ebpf verifier instructions limit in kernel, the stack-trace deepth is limited to top 15 in lua. If you need to trace deeper, you need to use systemtap instead.
14+
> - this project is not finished yet, and some errors may occurred.
15+
16+
## probe lua stack in nginx
1317

1418
see: bpftools/profile_nginx_lua/profile.bpf.c
1519

@@ -47,8 +51,8 @@ see the `fix_lua_stack` function:
4751
int i = 0;
4852
frame = nextframe = BPF_PROBE_READ_USER(L, base) - 1;
4953
/* Traverse frames backwards. */
50-
// for the ebpf verifier insns (limit 1000000), we need to limit the max loop times to 12
51-
for (; i < 12 && frame > bot; i++)
54+
// for the ebpf verifier insns (limit 1000000), we need to limit the max loop times to 15
55+
for (; i < 15 && frame > bot; i++)
5256
{
5357
if (frame_gc(frame) == obj2gco(L))
5458
{
@@ -152,6 +156,16 @@ see `bpftools/profile_nginx_lua/profile.c: print_fold_user_stack_with_lua`
152156
153157
If the lua stack output `user_stack_id` matches the original `user_stack_id`, this means the stack is a lua stack. Then, we replace the `[unknown]` function whose uip insides the luajit vm function range with our lua stack. This may not be totally correct, but it works for now. After printing the stack, we can use
154158
159+
## results flamegraph
160+
161+
lua:
162+
163+
![flamegraph](bpftools/profile_nginx_lua/results/user-lua.svg)
164+
165+
lua and c:
166+
167+
![flamegraph](bpftools/profile_nginx_lua/results/user-lua-c.svg)
168+
155169
### reference
156170
157171
for reference, I looked into the debug functions of lua vm:
@@ -179,20 +193,26 @@ and:
179193
- https://github.com/api7/stapxx/blob/master/tapset/luajit_gc64.sxx
180194
- https://github.com/openresty/openresty-systemtap-toolkit/blob/master/ngx-sample-lua-bt
181195
196+
The ebpf program is from: https://github.com/iovisor/bcc/pull/3782
197+
182198
### to run lua profile:
183199
184-
for example:
200+
tested with `luajit-5.1.so`
201+
202+
for example, use apisix profile scripts in CI to start `APISIX`(ci/performance_test.sh):
185203
186204
```bash
187205
# get nginx pid
188206
pgrep -P $(cat logs/nginx.pid) -n -f worker
189207
# sample only user stack and lua stack, use fold output, trace pid 36685 for nginx
190-
sudo ./profile -f -F 499 -U -p 366865 > a.bt
191-
# get flamegraph
192-
cat a.bt | ../../FlameGraph/flamegraph.pl > a.svg
208+
cd bpftools/profile_nginx_lua
209+
make
210+
sudo ./profile -f -F 499 -U -p [pid] --lua-user-stacks-only > a.bt
211+
# get flame graph
212+
cat a.bt | ../../tools/FlameGraph/flamegraph.pl > a.svg
193213
```
194214

195-
## run nginx probe
215+
## run nginx uprobe example
196216

197217
sudo /usr/bin/python /home/yunwei/coding/ebpf/nginx_uprobe.py
198218

@@ -236,15 +256,8 @@ sudo ./ci/performance_test.sh install_stap_tools
236256
- 支持获取在Docker中运行的 `Apache APISIX` 进程
237257
- 支持获取 Apache APISIX Openresty luajit 32/luajit 64 模式
238258
239-
### 项目完成进度
240-
241-
242-
- [X] 获取 docker 中运行的 APISIX 和 Openresty / nginx 进程 PID `2022/05`
243-
- [X] 利用 ebpf/BCC 生成火焰图 `2022/05`
244-
- [X] 利用 libbpf 生成 Openresty/nginx/lua 火焰图 `2022/06/04`
245-
- [X] 在 libbpf 中利用 uprobe 获取 lua status 堆栈信息 `2022/06/08`
246-
- [X] 在 profile 的同时获取 lua status stack trace 信息 `2022/06/23`
247-
- [X] 把得到的函数信息在最后生成火焰图的时候和原先的 c 函数信息综合起来 `2022/06/23`
248-
- [X] 整理工具
249-
- [ ] more with other tools
259+
TODO:
250260
261+
- [ ] test in docker
262+
- [ ] test for more version of luajit32/64
263+
- [ ] add more functionalities
File renamed without changes.

0 commit comments

Comments
 (0)