Skip to content

Commit 090117d

Browse files
mkokryashkinigormunkin
authored andcommitted
profilers: purge generation mechanism
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. Consider this script: | jit.off() | misc.sysprof.start{mode = 'C', interval=10} | for i = 1, 1e7 do tostring(i) end | misc.sysprof.stop() After executing it with LuaJIT, you can parse it like this: | $ time -v luajit-parse-sysprof sysprof.bin So, before the patch: | Maximum resident set size (kbytes): 224928 And after the patch: | Maximum resident set size (kbytes): 32780 That is the 85% reduction in memory consumption. Follows up tarantool/tarantool#8700 Reviewed-by: Sergey Kaplun <[email protected]> Reviewed-by: Sergey Bronnikov <[email protected]> Signed-off-by: Igor Munkin <[email protected]>
1 parent 05502ea commit 090117d

File tree

5 files changed

+19
-36
lines changed

5 files changed

+19
-36
lines changed

test/tarantool-tests/gh-5813-resolving-of-c-symbols.test.lua

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,9 @@ local TMP_BINFILE = profilename("memprofdata.tmp.bin")
2424
local function tree_contains(node, name)
2525
if node == nil then
2626
return false
27+
elseif node.value.name == name then
28+
return true
2729
else
28-
for i = 1, #node.value do
29-
if node.value[i].name == name then
30-
return true
31-
end
32-
end
3330
return tree_contains(node.left, name) or tree_contains(node.right, name)
3431
end
3532
end

tools/memprof/parse.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ local function parse_location(reader, asource, symbols)
7878
else
7979
error("Unknown asource "..asource)
8080
end
81-
local loc = symtab.loc(symbols, args)
81+
local loc = symtab.loc(args)
8282
return symtab.id(loc), symtab.demangle(symbols, loc)
8383
end
8484

tools/sysprof/parse.lua

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ end
5959
local function parse_lfunc(reader, symbols)
6060
local addr = reader:read_uleb128()
6161
local line = reader:read_uleb128()
62-
local loc = symtab.loc(symbols, { addr = addr, line = line })
62+
local loc = symtab.loc({ addr = addr, line = line })
6363
loc.type = FRAME.LFUNC
6464
return symtab.demangle(symbols, loc)
6565
end
@@ -71,7 +71,7 @@ end
7171

7272
local function parse_cfunc(reader, symbols)
7373
local addr = reader:read_uleb128()
74-
local loc = symtab.loc(symbols, { addr = addr })
74+
local loc = symtab.loc({ addr = addr })
7575
loc.type = FRAME.CFUNC
7676
return symtab.demangle(symbols, loc)
7777
end
@@ -99,7 +99,7 @@ local function parse_host_callchain(reader, event, symbols)
9999
local addr = reader:read_uleb128()
100100

101101
while addr ~= 0 do
102-
local loc = symtab.loc(symbols, { addr = addr })
102+
local loc = symtab.loc({ addr = addr })
103103
table.insert(event.host.callchain, 1, symtab.demangle(symbols, loc))
104104
addr = reader:read_uleb128()
105105
end
@@ -113,14 +113,11 @@ local function parse_trace_callchain(reader, event, symbols)
113113
loc.addr = reader:read_uleb128()
114114
loc.line = reader:read_uleb128()
115115

116-
local gen = symtab.loc(symbols, loc).gen
117116
local name_lua = symtab.demangle(symbols, {
118117
addr = loc.addr,
119118
traceno = loc.traceno,
120-
gen = gen
121119
})
122120
event.lua.trace = loc
123-
event.lua.trace.gen = gen
124121
event.lua.trace.name = name_lua
125122
end
126123

tools/utils/avl.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,15 @@ end
7878
function M.insert(node, key, value)
7979
assert(key, "Key can't be nil")
8080
if node == nil then
81-
return create_node(key, { value })
81+
return create_node(key, value)
8282
end
8383

8484
if key < node.key then
8585
node.left = M.insert(node.left, key, value)
8686
elseif key > node.key then
8787
node.right = M.insert(node.right, key, value)
8888
else
89-
table.insert(node.value, value)
89+
node.value = value
9090
end
9191

9292
update_height(node)

tools/utils/symtab.lua

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,13 @@ local SYMTAB_TRACE = 2
2222

2323
local M = {}
2424

25-
function M.loc(symtab, args)
25+
function M.loc(args)
2626
local loc = {
2727
addr = args.addr or 0,
2828
line = args.line or 0,
2929
traceno = args.traceno or 0,
3030
}
3131

32-
if loc.traceno ~= 0 and symtab.trace[loc.traceno] then
33-
loc.gen = #symtab.trace[loc.traceno]
34-
elseif symtab.lfunc[loc.addr] then
35-
loc.gen = #symtab.lfunc[loc.addr]
36-
else
37-
local _, csym = avl.floor(symtab.cfunc, loc.addr)
38-
loc.gen = csym and #csym or 1
39-
end
40-
4132
return loc
4233
end
4334

@@ -56,10 +47,10 @@ function M.parse_sym_lfunc(reader, symtab)
5647
)
5748
end
5849

59-
table.insert(symtab.lfunc[sym_addr], {
50+
symtab.lfunc[sym_addr] = {
6051
source = sym_chunk,
6152
linedefined = sym_line,
62-
})
53+
}
6354
end
6455

6556
function M.parse_sym_trace(reader, symtab)
@@ -69,9 +60,9 @@ function M.parse_sym_trace(reader, symtab)
6960

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

72-
table.insert(symtab.trace[traceno], {
73-
start = M.loc(symtab, { addr = sym_addr, line = sym_line })
74-
})
63+
symtab.trace[traceno] = {
64+
start = M.loc({ addr = sym_addr, line = sym_line })
65+
}
7566
end
7667

7768
-- Parse a single entry in a symtab: .so library
@@ -136,7 +127,7 @@ end
136127

137128
function M.id(loc)
138129
return string_format(
139-
"f%#xl%dt%dg%d", loc.addr, loc.line, loc.traceno, loc.gen
130+
"f%#xl%dt%dg", loc.addr, loc.line, loc.traceno
140131
)
141132
end
142133

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

148139
local trace_str = string_format("TRACE [%d]", traceno)
149-
local gens = symtab.trace[traceno]
150-
local trace = gens and gens[loc.gen]
140+
local trace = symtab.trace[traceno]
151141

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

164154
local addr = loc.addr
165-
local gen = loc.gen
166155

167156
if addr == 0 then
168157
return "INTERNAL"
169158
end
170159

171-
if symtab.lfunc[addr] and symtab.lfunc[addr][gen] then
172-
local source = symtab.lfunc[addr][gen].source
160+
if symtab.lfunc[addr] then
161+
local source = symtab.lfunc[addr].source
173162
return string_format("%s:%d", symtab.alias[source] or source, loc.line)
174163
end
175164

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

178167
if key then
179-
return string_format("%s:%#x", value[gen].name, key)
168+
return string_format("%s:%#x", value.name, key)
180169
end
181170

182171
return string_format("CFUNC %#x", addr)

0 commit comments

Comments
 (0)