[Tarantool-patches] [PATCH luajit 2/2] sysprof: add stack sandwich support
Maxim Kokryashkin
max.kokryashkin at gmail.com
Mon Jul 4 00:38:15 MSK 2022
This commit introduces stack sandwich support to the
sysprof's parser.
Sandwich is handled the following way:
1. If there is a `lua_cpcall` in the C stack trace, nothing
is done on the C stack and the corresponding frame on the
Lua stack is removed.
2. If there is a `lua_call`/`lua_pcall`, then next chunk of
frames is from the Lua stack. That chunk ends with either
a CFUNC, or a stack trace end.
Resolves tarantool/tarantool#7244
---
tools/sysprof/collapse.lua | 31 +++++++++++++++++++------------
1 file changed, 19 insertions(+), 12 deletions(-)
diff --git a/tools/sysprof/collapse.lua b/tools/sysprof/collapse.lua
index b0c4afc8..b815baf3 100755
--- a/tools/sysprof/collapse.lua
+++ b/tools/sysprof/collapse.lua
@@ -39,9 +39,11 @@ local function insert(name, node, is_leaf)
end
local function insert_lua_callchain(chain, lua, symbols)
+ local ins_cnt = 0
for _,fr in pairs(lua.callchain) do
local name_lua
+ ins_cnt = ins_cnt + 1
if fr.type == parse.FRAME.FFUNC then
name_lua = vmdef.ffnames[fr.ffid]
else
@@ -58,38 +60,43 @@ local function insert_lua_callchain(chain, lua, symbols)
gen = fr.gen
})
end
+
+ if fr.type == parse.FRAME.CFUNC then
+ -- C function encountered, the next chunk
+ -- of frames is located on the C stack.
+ break
+ end
end
table.insert(chain, 1, { name = name_lua })
end
+ table.remove(lua.callchain, ins_cnt)
end
+
-- merge lua and host callchains into one callchain representing
-- transfer of control
local function merge(event, symbols, sep_vmst)
local cc = {}
- local lua_inserted = false
for _,h_fr in pairs(event.host.callchain) do
local name_host = symtab.demangle(symbols, {
addr = h_fr.addr,
gen = h_fr.gen
})
+ table.insert(cc, 1, { name = name_host })
- -- We assume that usually the transfer of control
- -- looks like:
- -- HOST -> LUA -> HOST
- -- so for now, lua callchain starts from lua_pcall() call
- if name_host == 'lua_pcall' then
- insert_lua_callchain(cc, event.lua, symbols)
- lua_inserted = true
+ if string.match(name_host, '^lua_cpcall') ~= nil then
+ -- Any C function is present on both the C and the Lua
+ -- stacks. It is more convenient to get its info from the host stack,
+ -- since it has information about child frames.
+ table.remove(event.lua.callchain, 1)
end
- table.insert(cc, 1, { name = name_host })
- end
+ if string.match(name_host, '^lua_p?call') ~= nil then
+ insert_lua_callchain(cc, event.lua, symbols)
+ end
- if lua_inserted == false then
- insert_lua_callchain(cc, event.lua, symbols)
end
if sep_vmst == true then
--
2.36.1
More information about the Tarantool-patches
mailing list