Skip to content

Commit dfa0f97

Browse files
mkokryashkinigormunkin
authored andcommitted
sysprof: implement stack sandwich support
This commit introduces stack sandwich support to the sysprof's parser. The 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 the 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
1 parent 054ec48 commit dfa0f97

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

tools/sysprof/collapse.lua

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,11 @@ local function insert(name, node, is_leaf)
3939
end
4040

4141
local function insert_lua_callchain(chain, lua, symbols)
42+
local ins_cnt = 0
4243
for _,fr in pairs(lua.callchain) do
4344
local name_lua
4445

46+
ins_cnt = ins_cnt + 1
4547
if fr.type == parse.FRAME.FFUNC then
4648
name_lua = vmdef.ffnames[fr.ffid]
4749
else
@@ -58,38 +60,42 @@ local function insert_lua_callchain(chain, lua, symbols)
5860
gen = fr.gen
5961
})
6062
end
63+
64+
if fr.type == parse.FRAME.CFUNC then
65+
-- C function encountered, the next chunk
66+
-- of frames is located on the C stack.
67+
break
68+
end
6169
end
6270

6371
table.insert(chain, 1, { name = name_lua })
6472
end
73+
table.remove(lua.callchain, ins_cnt)
6574
end
6675

6776
-- merge lua and host callchains into one callchain representing
6877
-- transfer of control
6978
local function merge(event, symbols, sep_vmst)
7079
local cc = {}
71-
local lua_inserted = false
7280

7381
for _,h_fr in pairs(event.host.callchain) do
7482
local name_host = symtab.demangle(symbols, {
7583
addr = h_fr.addr,
7684
gen = h_fr.gen
7785
})
86+
table.insert(cc, 1, { name = name_host })
7887

79-
-- We assume that usually the transfer of control
80-
-- looks like:
81-
-- HOST -> LUA -> HOST
82-
-- so for now, lua callchain starts from lua_pcall() call
83-
if name_host == 'lua_pcall' then
84-
insert_lua_callchain(cc, event.lua, symbols)
85-
lua_inserted = true
88+
if string.match(name_host, '^lua_cpcall') ~= nil then
89+
-- Any C function is present on both the C and the Lua
90+
-- stacks. It is more convenient to get its info from the
91+
-- host stack, since it has information about child frames.
92+
table.remove(event.lua.callchain, 1)
8693
end
8794

88-
table.insert(cc, 1, { name = name_host })
89-
end
95+
if string.match(name_host, '^lua_p?call') ~= nil then
96+
insert_lua_callchain(cc, event.lua, symbols)
97+
end
9098

91-
if lua_inserted == false then
92-
insert_lua_callchain(cc, event.lua, symbols)
9399
end
94100

95101
if sep_vmst == true then

0 commit comments

Comments
 (0)