https://github.com/openresty/openresty-systemtap-toolkit前端
https://sourceware.org/systemtap/langref/linux
https://github.com/brendangregg/FlameGraphnginx
参考ngx-sample-lua-btgit
现代linux 动态追踪技术 主要是基于 ebpfgithub
systemtap 是 动态追踪的前端, 技术原理是 编译一个 相似c的脚本 生成 内核模块, 来监控用户空间的lua程序函数
对openResty的脚本改造两点,工具
1: 去掉nginx相关函数的 probe 探针lua
2:如何获取LuaState 状态机的方法 调整, 能够使用程序内部的 全局变量定义rest
if(\@defined(\@var("globalL", "$lua_path"))) { L = \@var("globalL", "$lua_path") }
对timer 采样也能够调整code
timer.profile 每一个CPU周期 timer.ms 是 定时毫秒
动态追踪核心:
定义probe 探针位置
定义timer 采样
在timer中判断 PID 进程ID, 来肯定本身要观察的程序
timer.s 观察总时长后结束
systemtap 的堆栈格式是
一次堆栈每层 文件:行号 总共出现次数
fix-bt 以后 获得 lua 函数名字
flamegraph 的工具 stack stap 多行压缩到一行
最后生成 火焰图 分析