[Tarantool-patches] [PATCH luajit v4 2/4] memprof: refactor location parsing

Mikhail Shishatskiy m.shishatskiy at tarantool.org
Wed Sep 29 23:07:56 MSK 2021


As it is hard to keep function `id_location` easily usable in the
function `parse_location` with a growing number of fields in the
<loc> table, the code is refactored to make it more understandable.

The API of <utils/symtab.lua> module changed with adding a function
`id(loc)` returning the same id-string, as `id_location` did. This
function is useful to "stringify" the location and use it as a key
in the key/value storage.

Part of tarantool/tarantool#5814
---

Issue: https://github.com/tarantool/tarantool/issues/5814
Branch: https://github.com/tarantool/luajit/tree/shishqa/gh-5814-group-allocations-on-trace-by-trace-number
CI: https://github.com/tarantool/tarantool/tree/shishqa/gh-5814-group-allocations-on-trace-by-trace-number

 tools/memprof/parse.lua | 26 +++++++++++++-------------
 tools/utils/symtab.lua  |  4 ++++
 2 files changed, 17 insertions(+), 13 deletions(-)

diff --git a/tools/memprof/parse.lua b/tools/memprof/parse.lua
index 12e2758f..34ff8aef 100644
--- a/tools/memprof/parse.lua
+++ b/tools/memprof/parse.lua
@@ -8,6 +8,8 @@ local bit = require "bit"
 local band = bit.band
 local lshift = bit.lshift
 
+local symtab = require "utils.symtab"
+
 local string_format = string.format
 
 local LJM_MAGIC = "ljm"
@@ -59,22 +61,20 @@ local function link_to_previous(heap_chunk, e, nsize)
   end
 end
 
-local function id_location(addr, line)
-  return string_format("f%#xl%d", addr, line), {
-    addr = addr,
-    line = line,
-  }
-end
-
 local function parse_location(reader, asource)
-  if asource == ASOURCE_INT then
-    return id_location(0, 0)
-  elseif asource == ASOURCE_CFUNC then
-    return id_location(reader:read_uleb128(), 0)
+  local loc = {
+    addr = 0,
+    line = 0,
+  }
+  if asource == ASOURCE_CFUNC then
+    loc.addr = reader:read_uleb128()
   elseif asource == ASOURCE_LFUNC then
-    return id_location(reader:read_uleb128(), reader:read_uleb128())
+    loc.addr = reader:read_uleb128()
+    loc.line = reader:read_uleb128()
+  elseif asource ~= ASOURCE_INT then
+    error("Unknown asource "..asource)
   end
-  error("Unknown asource "..asource)
+  return symtab.id(loc), loc
 end
 
 local function parse_alloc(reader, asource, events, heap)
diff --git a/tools/utils/symtab.lua b/tools/utils/symtab.lua
index 3ed1dd13..e01daa62 100644
--- a/tools/utils/symtab.lua
+++ b/tools/utils/symtab.lua
@@ -73,6 +73,10 @@ function M.parse(reader)
   return symtab
 end
 
+function M.id(loc)
+  return string_format("f%#xl%d", loc.addr, loc.line)
+end
+
 function M.demangle(symtab, loc)
   local addr = loc.addr
 
-- 
2.33.0



More information about the Tarantool-patches mailing list