[Tarantool-patches] [PATCH luajit 2/2] sysprof: add stack sandwich support

Sergey Kaplun skaplun at tarantool.org
Sat Jul 16 10:32:53 MSK 2022


Hi, Maxim!

Thanks for the patch!

LGTM, except a few nits below.

On 04.07.22, Maxim Kokryashkin wrote:
> This commit introduces stack sandwich support to the
> sysprof's parser.
> 
> Sandwich is handled the following way:

Typo: s/Sandwich/The sandwich/

>   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

Typo: s/next chunk/the next chunk/

>   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)

<snipped>

>    end
> +  table.remove(lua.callchain, ins_cnt)
>  end
>  
> +

Nit: looks like this newline is excess.

>  -- 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

Why do we use `string.match()` instead `==`?

> +      -- 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

I suggest to check full function name, so use '^lua_p?call$' as pattern
instead.

> +      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
> 

-- 
Best regards,
Sergey Kaplun


More information about the Tarantool-patches mailing list