[Tarantool-patches] [PATCH luajit v2 3/3] memprof: substitute long proto names with aliases
Sergey Kaplun
skaplun at tarantool.org
Tue Jan 25 13:12:05 MSK 2022
Hi, Mikhail!
Thanks for the patch!
May be it is more user-friendly to use the first line of alias instead
strict "function_alias_\d"? Something like:
| \d string "print(nil)..."#N:
\d here is the number of alias.
#N -- linenumber.
Also this simplifies reading for oneline functions without \n.
Thoughts?
But I'm OK with the current version.
LGTM, otherwise, except a few nits below.
On 02.12.21, Mikhail Shishatskiy wrote:
> Sometimes a loaded chunk name can be multiline (actually, it
> is the Lua code itself). In order not to burden memprof parser
> output with big multiline names, aliases were introduced.
>
> The chunk name is replaced by `function_alias_N` (where N is a unique id)
> to be displayed in the allocation events report. All the aliases are
> printed in the end of parser's output under the header "ALIASES".
Typo: s/in/at/
Typo: s/parser's/the parsers/
>
> Because of changes mentioned above, the API of <utils/symtab.lua>
> changed: now symtab has additional `alias` assotiative table for
Typo: s/assotiative/associative/
> storing aliases: one can get alias string by sym_chunk key and sym_chunk
> by alias index. The humanizer module now can display aliases with the
> new function <aliases>.
>
> Follows up tarantool/tarantool#5815
Nit: "Part of" looks more properly.
> ---
>
> Issue: https://github.com/tarantool/tarantool/issues/5815
> Branch: https://github.com/tarantool/luajit/tree/shishqa/gh-5815-enrich-symtab-when-prototype-is-allocated-v2
> Tarantool branch: https://github.com/tarantool/tarantool/tree/shishqa/gh-5815-enrich-symtab-when-prototype-is-allocated
>
> tools/memprof.lua | 1 +
> tools/memprof/humanize.lua | 14 ++++++++++++++
> tools/utils/symtab.lua | 17 +++++++++++++----
> 3 files changed, 28 insertions(+), 4 deletions(-)
>
> diff --git a/tools/memprof.lua b/tools/memprof.lua
> index 18b44fdd..cf66dd9e 100644
> --- a/tools/memprof.lua
> +++ b/tools/memprof.lua
> @@ -106,6 +106,7 @@ local function dump(inputfile)
<snipped>
> diff --git a/tools/memprof/humanize.lua b/tools/memprof/humanize.lua
> index 7771005d..d77c7132 100644
> --- a/tools/memprof/humanize.lua
> +++ b/tools/memprof/humanize.lua
> @@ -81,4 +81,18 @@ function M.leak_info(dheap)
> print("")
> end
>
> +function M.aliases(symbols)
> + if #symbols.alias == 0 then return end
> + print("ALIASES:")
> + for _, source in ipairs(symbols.alias) do
> + print(symbols.alias[source]..":")
> + local lineno = 1
> + for line in source:gmatch("(.-)\n") do
The last line may be without \n symbol and will be skipped.
For example the following chunk
| $ src/luajit -e '
| misc.memprof.start("/tmp/test_memprof.bin")
| loadstring"\n\nfor i = 1, 1e3 do _ = {i = string.rep(i, 12)} end"()
| misc.memprof.stop()
| '
will report:
| function_alias_1:
| 1 |
| 2 |
| ~
> + print(tostring(lineno).."\t| "..line)
> + lineno = lineno + 1
> + end
> + print("~\n")
Do we need this '~' symbol?
> + end
> +end
> +
> return M
> diff --git a/tools/utils/symtab.lua b/tools/utils/symtab.lua
> index 00bab03a..133a0fc7 100644
> --- a/tools/utils/symtab.lua
> +++ b/tools/utils/symtab.lua
> @@ -46,6 +46,13 @@ function M.parse_sym_lfunc(reader, symtab)
> symtab.lfunc[sym_addr] = {}
> end
>
> + if sym_chunk:find('\n') and symtab.alias[sym_chunk] == nil then
Nit: `and not symtab.alias[sym_chunk]` looks more in Lua way for me.
Fill free to ignore.
> + table.insert(symtab.alias, sym_chunk)
> + symtab.alias[sym_chunk] = string_format(
> + "function_alias_%d", #symtab.alias
> + )
> + end
> +
> table.insert(symtab.lfunc[sym_addr], {
> source = sym_chunk,
> linedefined = sym_line,
> @@ -77,6 +84,7 @@ function M.parse(reader)
<snipped>
> --
> 2.33.1
>
--
Best regards,
Sergey Kaplun
More information about the Tarantool-patches
mailing list