Tarantool development patches archive
 help / color / mirror / Atom feed
From: Mikhail Shishatskiy 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 v2 3/3] memprof: substitute long proto names with aliases
Date: Thu,  2 Dec 2021 14:03:29 +0300	[thread overview]
Message-ID: <20211202110329.664738-4-m.shishatskiy@tarantool.org> (raw)
In-Reply-To: <20211202110329.664738-1-m.shishatskiy@tarantool.org>

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

Because of changes mentioned above, the API of <utils/symtab.lua>
changed: now symtab has additional `alias` assotiative table for
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
---

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)
   end
   local dheap = process.form_heap_delta(events, symbols)
   view.leak_info(dheap)
+  view.aliases(symbols)
   os.exit(0)
 end
 
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
+      print(tostring(lineno).."\t| "..line)
+      lineno = lineno + 1
+    end
+    print("~\n")
+  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
+    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)
   local symtab = {
     lfunc = {},
     trace = {},
+    alias = {},
   }
   local magic = reader:read_octets(3)
   local version = reader:read_octets(1)
@@ -147,15 +155,16 @@ function M.demangle(symtab, loc)
   end
 
   local addr = loc.addr
+  local epoch = loc.epoch
 
   if addr == 0 then
     return "INTERNAL"
   end
 
-  if symtab.lfunc[addr] and symtab.lfunc[addr][loc.epoch] then
-    return string_format(
-      "%s:%d", symtab.lfunc[addr][loc.epoch].source, loc.line
-    )
+  if symtab.lfunc[addr] and symtab.lfunc[addr][epoch] then
+    local source = symtab.lfunc[addr][epoch].source
+    local alias = symtab.alias[source]
+    return string_format("%s:%d", alias or source, loc.line)
   end
 
   return string_format("CFUNC %#x", addr)
-- 
2.33.1


  parent reply	other threads:[~2021-12-02 11:05 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-02 11:03 [Tarantool-patches] [PATCH luajit v2 0/3] memprof: enrich symtab when meeting new prototype Mikhail Shishatskiy via Tarantool-patches
2021-12-02 11:03 ` [Tarantool-patches] [PATCH luajit v2 1/3] memprof: add symbol epochs Mikhail Shishatskiy via Tarantool-patches
2022-03-15  7:56   ` Sergey Kaplun via Tarantool-patches
2021-12-02 11:03 ` [Tarantool-patches] [PATCH luajit v2 2/3] memprof: enrich symtab when meeting new prototype Mikhail Shishatskiy via Tarantool-patches
2022-01-19 16:56   ` Mikhail Shishatskiy via Tarantool-patches
2022-01-25  8:14     ` Sergey Kaplun via Tarantool-patches
2021-12-02 11:03 ` Mikhail Shishatskiy via Tarantool-patches [this message]
2022-01-25 10:12   ` [Tarantool-patches] [PATCH luajit v2 3/3] memprof: substitute long proto names with aliases Sergey Kaplun via Tarantool-patches
2022-04-12 14:30 ` [Tarantool-patches] [PATCH luajit v2 0/3] memprof: enrich symtab when meeting new prototype 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=20211202110329.664738-4-m.shishatskiy@tarantool.org \
    --to=tarantool-patches@dev.tarantool.org \
    --cc=imun@tarantool.org \
    --cc=m.shishatskiy@tarantool.org \
    --cc=skaplun@tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH luajit v2 3/3] memprof: substitute long proto names with aliases' \
    /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