Skip to content

Commit 3dee112

Browse files
committed
memprof: refactor heap_chunk data structure
The memprof parser used to have the `heap_chunk` data structure using numeric indices for its values, which is hardly readable and maintainable. This patch replaces these numeric indices with corresponding string keys. Part of tarantool/tarantool#5994
1 parent 3764010 commit 3dee112

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

tools/memprof/parse.lua

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,22 +45,30 @@ local function new_event(loc)
4545
}
4646
end
4747

48+
local function new_heap_chunk(size, id, loc)
49+
return {
50+
size = size,
51+
id = id,
52+
loc = loc,
53+
}
54+
end
55+
4856
local function link_to_previous(heap_chunk, e, nsize)
4957
-- Memory at this chunk was allocated before we start tracking.
5058
if heap_chunk then
5159
-- Save Lua code location (line) by address (id).
52-
if not e.primary[heap_chunk[2]] then
53-
e.primary[heap_chunk[2]] = {
54-
loc = heap_chunk[3],
60+
if not e.primary[heap_chunk.id] then
61+
e.primary[heap_chunk.id] = {
62+
loc = heap_chunk.loc,
5563
allocated = 0,
5664
freed = 0,
5765
count = 0,
5866
}
5967
end
6068
-- Save information about delta for memory heap.
61-
local location_data = e.primary[heap_chunk[2]]
69+
local location_data = e.primary[heap_chunk.id]
6270
location_data.allocated = location_data.allocated + nsize
63-
location_data.freed = location_data.freed + heap_chunk[1]
71+
location_data.freed = location_data.freed + heap_chunk.size
6472
location_data.count = location_data.count + 1
6573
end
6674
end
@@ -95,7 +103,7 @@ local function parse_alloc(reader, asource, events, heap, symbols)
95103
e.num = e.num + 1
96104
e.alloc = e.alloc + nsize
97105

98-
heap[naddr] = {nsize, id, loc}
106+
heap[naddr] = new_heap_chunk(nsize, id, loc)
99107
end
100108

101109
local function parse_realloc(reader, asource, events, heap, symbols)
@@ -117,7 +125,7 @@ local function parse_realloc(reader, asource, events, heap, symbols)
117125
link_to_previous(heap[oaddr], e, nsize)
118126

119127
heap[oaddr] = nil
120-
heap[naddr] = {nsize, id, loc}
128+
heap[naddr] = new_heap_chunk(nsize, id, loc)
121129
end
122130

123131
local function parse_free(reader, asource, events, heap, symbols)

0 commit comments

Comments
 (0)