Skip to content

Commit

Permalink
profilers: purge generation mechanism
Browse files Browse the repository at this point in the history
Since both of the profiler parsers are now processing
the events in a stream-like fashion, the generation
mechanism is excessive and can be purged. This results
in a significant memory consumption drop, especially
for the AVL-tree part.

Follows up tarantool/tarantool#8700
  • Loading branch information
mkokryashkin committed Aug 28, 2023
1 parent acbce44 commit c5778a4
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 36 deletions.
7 changes: 2 additions & 5 deletions test/tarantool-tests/gh-5813-resolving-of-c-symbols.test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,9 @@ local TMP_BINFILE = profilename("memprofdata.tmp.bin")
local function tree_contains(node, name)
if node == nil then
return false
elseif node.value.name == name then
return true
else
for i = 1, #node.value do
if node.value[i].name == name then
return true
end
end
return tree_contains(node.left, name) or tree_contains(node.right, name)
end
end
Expand Down
2 changes: 1 addition & 1 deletion tools/memprof/parse.lua
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ local function parse_location(reader, asource, symbols)
else
error("Unknown asource "..asource)
end
local loc = symtab.loc(symbols, args)
local loc = symtab.loc(args)
return symtab.id(loc), symtab.demangle(symbols, loc)
end

Expand Down
9 changes: 3 additions & 6 deletions tools/sysprof/parse.lua
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ end
local function parse_lfunc(reader, symbols)
local addr = reader:read_uleb128()
local line = reader:read_uleb128()
local loc = symtab.loc(symbols, { addr = addr, line = line })
local loc = symtab.loc{ addr = addr, line = line }
loc.type = FRAME.LFUNC
return symtab.demangle(symbols, loc)
end
Expand All @@ -71,7 +71,7 @@ end

local function parse_cfunc(reader, symbols)
local addr = reader:read_uleb128()
local loc = symtab.loc(symbols, { addr = addr })
local loc = symtab.loc{ addr = addr }
loc.type = FRAME.CFUNC
return symtab.demangle(symbols, loc)
end
Expand Down Expand Up @@ -99,7 +99,7 @@ local function parse_host_callchain(reader, event, symbols)
local addr = reader:read_uleb128()

while addr ~= 0 do
local loc = symtab.loc(symbols, { addr = addr })
local loc = symtab.loc{ addr = addr }
table.insert(event.host.callchain, 1, symtab.demangle(symbols, loc))
addr = reader:read_uleb128()
end
Expand All @@ -113,14 +113,11 @@ local function parse_trace_callchain(reader, event, symbols)
loc.addr = reader:read_uleb128()
loc.line = reader:read_uleb128()

local gen = symtab.loc(symbols, loc).gen
local name_lua = symtab.demangle(symbols, {
addr = loc.addr,
traceno = loc.traceno,
gen = gen
})
event.lua.trace = loc
event.lua.trace.gen = gen
event.lua.trace.name = name_lua
end

Expand Down
4 changes: 2 additions & 2 deletions tools/utils/avl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,15 @@ end
function M.insert(node, key, value)
assert(key, "Key can't be nil")
if node == nil then
return create_node(key, { value })
return create_node(key, value)
end

if key < node.key then
node.left = M.insert(node.left, key, value)
elseif key > node.key then
node.right = M.insert(node.right, key, value)
else
table.insert(node.value, value)
node.value = value
end

update_height(node)
Expand Down
33 changes: 11 additions & 22 deletions tools/utils/symtab.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,13 @@ local SYMTAB_TRACE = 2

local M = {}

function M.loc(symtab, args)
function M.loc(args)
local loc = {
addr = args.addr or 0,
line = args.line or 0,
traceno = args.traceno or 0,
}

if loc.traceno ~= 0 and symtab.trace[loc.traceno] then
loc.gen = #symtab.trace[loc.traceno]
elseif symtab.lfunc[loc.addr] then
loc.gen = #symtab.lfunc[loc.addr]
else
local _, csym = avl.floor(symtab.cfunc, loc.addr)
loc.gen = csym and #csym or 1
end

return loc
end

Expand All @@ -56,10 +47,10 @@ function M.parse_sym_lfunc(reader, symtab)
)
end

table.insert(symtab.lfunc[sym_addr], {
symtab.lfunc[sym_addr] = {
source = sym_chunk,
linedefined = sym_line,
})
}
end

function M.parse_sym_trace(reader, symtab)
Expand All @@ -69,9 +60,9 @@ function M.parse_sym_trace(reader, symtab)

symtab.trace[traceno] = symtab.trace[traceno] or {}

table.insert(symtab.trace[traceno], {
start = M.loc(symtab, { addr = sym_addr, line = sym_line })
})
symtab.trace[traceno] = {
start = M.loc{ addr = sym_addr, line = sym_line }
}
end

-- Parse a single entry in a symtab: .so library
Expand Down Expand Up @@ -136,7 +127,7 @@ end

function M.id(loc)
return string_format(
"f%#xl%dt%dg%d", loc.addr, loc.line, loc.traceno, loc.gen
"f%#xl%dt%dg", loc.addr, loc.line, loc.traceno
)
end

Expand All @@ -146,8 +137,7 @@ local function demangle_trace(symtab, loc)
assert(traceno ~= 0, "Location is a trace")

local trace_str = string_format("TRACE [%d]", traceno)
local gens = symtab.trace[traceno]
local trace = gens and gens[loc.gen]
local trace = symtab.trace[traceno]

if trace then
assert(trace.start.traceno == 0, "Trace start is not a trace")
Expand All @@ -162,21 +152,20 @@ function M.demangle(symtab, loc)
end

local addr = loc.addr
local gen = loc.gen

if addr == 0 then
return "INTERNAL"
end

if symtab.lfunc[addr] and symtab.lfunc[addr][gen] then
local source = symtab.lfunc[addr][gen].source
if symtab.lfunc[addr] then
local source = symtab.lfunc[addr].source
return string_format("%s:%d", symtab.alias[source] or source, loc.line)
end

local key, value = avl.floor(symtab.cfunc, addr)

if key then
return string_format("%s:%#x", value[gen].name, key)
return string_format("%s:%#x", value.name, key)
end

return string_format("CFUNC %#x", addr)
Expand Down

0 comments on commit c5778a4

Please sign in to comment.