systemTab動態分析linux下lua性能

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 多行壓縮到一行

最後生成 火焰圖 分析

相關文章
相關標籤/搜索