From: Maxim Kokryashkin via Tarantool-patches <tarantool-patches@dev.tarantool.org>
To: tarantool-patches@dev.tarantool.org, imun@tarantool.org,
skaplun@tarantool.org
Subject: [Tarantool-patches] [PATCH luajit 2/2] sysprof: add stack sandwich support
Date: Mon, 4 Jul 2022 00:38:15 +0300 [thread overview]
Message-ID: <83b89e5c769469d19f0bc9144667685801f3cb51.1656883823.git.m.kokryashkin@tarantool.org> (raw)
In-Reply-To: <cover.1656883823.git.m.kokryashkin@tarantool.org>
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
next prev parent reply other threads:[~2022-07-03 21:39 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-03 21:38 [Tarantool-patches] [PATCH luajit 0/2] sysprof: fix inconsistencies Maxim Kokryashkin via Tarantool-patches
2022-07-03 21:38 ` [Tarantool-patches] [PATCH luajit 1/2] symtab: fix static symtab dump Maxim Kokryashkin via Tarantool-patches
2022-07-16 7:21 ` Sergey Kaplun via Tarantool-patches
2022-07-03 21:38 ` Maxim Kokryashkin via Tarantool-patches [this message]
2022-07-16 7:32 ` [Tarantool-patches] [PATCH luajit 2/2] sysprof: add stack sandwich support Sergey Kaplun via Tarantool-patches
2022-07-18 17:23 ` [Tarantool-patches] [PATCH luajit 0/2] sysprof: fix inconsistencies Igor Munkin via Tarantool-patches
2022-08-10 14:34 ` Igor Munkin via Tarantool-patches
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=83b89e5c769469d19f0bc9144667685801f3cb51.1656883823.git.m.kokryashkin@tarantool.org \
--to=tarantool-patches@dev.tarantool.org \
--cc=imun@tarantool.org \
--cc=max.kokryashkin@gmail.com \
--cc=skaplun@tarantool.org \
--subject='Re: [Tarantool-patches] [PATCH luajit 2/2] sysprof: add stack sandwich support' \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox