From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id A48C970152; Thu, 2 Dec 2021 14:04:08 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org A48C970152 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1638443048; bh=Ol3O+u1Cj9AAF8XTFzIEFKAEIQFnWPDemyIZd1WsgNM=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=F/nNnKYLPuAitUg06lLs9HQPH4oVYdpuwYNhHCo57Lpx+DLN89TKA1qFy7Bv6cro9 FiLM9LabAmAtz8ft45f4WBql+UPfsy0+8iXRnt1Jgcr7ZJtoG7ZltNl2vieMPu4D9t HwIC5RRyB94GsjAiLbv6VHtMuR4+ilUb/C1HCOjc= Received: from smtp17.mail.ru (smtp17.mail.ru [94.100.176.154]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id D973E70152 for ; Thu, 2 Dec 2021 14:03:38 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org D973E70152 Received: by smtp17.mail.ru with esmtpa (envelope-from ) id 1msjsI-0005pZ-0S; Thu, 02 Dec 2021 14:03:38 +0300 To: tarantool-patches@dev.tarantool.org, imun@tarantool.org, skaplun@tarantool.org Date: Thu, 2 Dec 2021 14:03:27 +0300 Message-Id: <20211202110329.664738-2-m.shishatskiy@tarantool.org> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211202110329.664738-1-m.shishatskiy@tarantool.org> References: <20211202110329.664738-1-m.shishatskiy@tarantool.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-7564579A: B8F34718100C35BD X-77F55803: 4F1203BC0FB41BD93822B471089FF64DF8A896E06A6C08F273E2B333A65AEC09182A05F5380850407FC9A1A2155B3B0C649BF265A26B5F599B7468506DBBF30AD1173C7A0EBE0EA4 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE705B093C0FC4B30B9EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006379448E89E2A57838D8638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D81825CFF3B6DC2A1AFD8656B83D6D9AE2117882F4460429724CE54428C33FAD305F5C1EE8F4F765FCF1175FABE1C0F9B6A471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F446042972877693876707352033AC447995A7AD18C26CFBAC0749D213D2E47CDBA5A96583BA9C0B312567BB2376E601842F6C81A19E625A9149C048EEB28585415E75ADA9C0837EA9F3D197644AD6D5ED66289B52698AB9A7B718F8C46E0066C2D8992A16725E5C173C3A84C384CE97E0F2853DA0BA3038C0950A5D36B5C8C57E37DE458B0BC6067A898B09E46D1867E19FE14079C09775C1D3CA48CF3D321E7403792E342EB15956EA79C166A417C69337E82CC275ECD9A6C639B01B78DA827A17800CE7A3CCBC2573AEBDE1C4224003CC83647689D4C264860C145E X-B7AD71C0: BCAA75B3C340DBBEEF3A853C90EA8D50F01536074D6990B7EE9D5CB6078CC77C9164F20852A3053C5FA128949B992996 X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C414F749A5E30D975CBD1FC2C1415E7E9D653F86A97DD78AB5B345B174C4C1691C9C2B6934AE262D3EE7EAB7254005DCED7532B743992DF240BDC6A1CF3F042BAD6DF99611D93F60EF6EFF71F1B3C06F72699F904B3F4130E343918A1A30D5E7FCCB5012B2E24CD356 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34D2AC226BFD4557241D9C994AE5C1FA76A86A7E212958A7BF79E8A81486574A6242B8C18D27EF98B51D7E09C32AA3244CCF37F67B4B633F49C9B901EF1DAB739BFE8DA44ABE2443F7927AC6DF5659F194 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojMMFVqzO9sR3HJHdT4LJTnw== X-Mailru-Sender: EFA0F3A8419EF216ABF90D481445BA3F6DD0837CB4C5CE7A649BF265A26B5F59E5E949923882BAAD2376072A51849BFFE66B5C1DBFD5D09D5E022D45988A037B448E0EA96F20AB367402F9BA4338D657ED14614B50AE0675 X-Mras: Ok Subject: [Tarantool-patches] [PATCH luajit v2 1/3] memprof: add symbol epochs X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Mikhail Shishatskiy via Tarantool-patches Reply-To: Mikhail Shishatskiy Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" There may be situations, when new prototype or trace has the same address than the previously dumped one. In this case, the new symtab entry will shadow the preceeding, and if we demangle symbols when all the events are parsed, we can get irrelevant information. For this reason, the symtab now stores not a single entry, but array of entries for each location. The structure was extended by the field representing the generation of symtab entry associated with this particular location entry. Also, the API has extended by function symtab.new_loc(symbols, addr, line, traceno) so that it can assign an epoch for a new location. Part of 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 .../misclib-memprof-lapi.test.lua | 12 ++-- tools/memprof/parse.lua | 41 +++++++------- tools/utils/symtab.lua | 55 +++++++++++++------ 3 files changed, 67 insertions(+), 41 deletions(-) diff --git a/test/tarantool-tests/misclib-memprof-lapi.test.lua b/test/tarantool-tests/misclib-memprof-lapi.test.lua index 7919c61f..dd973f2a 100644 --- a/test/tarantool-tests/misclib-memprof-lapi.test.lua +++ b/test/tarantool-tests/misclib-memprof-lapi.test.lua @@ -70,7 +70,7 @@ local function generate_parsed_output(payload) local reader = bufread.new(TMP_BINFILE) local symbols = symtab.parse(reader) - local events = memprof.parse(reader) + local events = memprof.parse(reader, symbols) -- We don't need it any more. os.remove(TMP_BINFILE) @@ -86,13 +86,15 @@ local function fill_ev_type(events, symbols, event_type) for _, event in pairs(events[event_type]) do local addr = event.loc.addr local traceno = event.loc.traceno + local epoch = event.loc.epoch if traceno ~= 0 and symbols.trace[traceno] then - local trace_loc = symbols.trace[traceno].start + local trace_loc = symbols.trace[traceno][epoch].start addr = trace_loc.addr + epoch = trace_loc.epoch ev_type.trace[traceno] = { name = string.format("TRACE [%d] %s:%d", - traceno, symbols.lfunc[addr].source, trace_loc.line + traceno, symbols.lfunc[addr][epoch].source, trace_loc.line ), num = event.num, } @@ -104,7 +106,9 @@ local function fill_ev_type(events, symbols, event_type) elseif symbols.lfunc[addr] then ev_type.line[event.loc.line] = { name = string.format( - "%s:%d", symbols.lfunc[addr].source, symbols.lfunc[addr].linedefined + "%s:%d", + symbols.lfunc[addr][epoch].source, + symbols.lfunc[addr][epoch].linedefined ), num = event.num, } diff --git a/tools/memprof/parse.lua b/tools/memprof/parse.lua index 47dbaee4..be5844a4 100644 --- a/tools/memprof/parse.lua +++ b/tools/memprof/parse.lua @@ -64,29 +64,28 @@ local function link_to_previous(heap_chunk, e, nsize) end end -local function parse_location(reader, asource) - local loc = { - addr = 0, - line = 0, - traceno = 0, - } +local function parse_location(reader, asource, symbols) + local addr = 0 + local line = 0 + local traceno = 0 if asource == ASOURCE_INT then -- luacheck: ignore elseif asource == ASOURCE_CFUNC then - loc.addr = reader:read_uleb128() + addr = reader:read_uleb128() elseif asource == ASOURCE_LFUNC then - loc.addr = reader:read_uleb128() - loc.line = reader:read_uleb128() + addr = reader:read_uleb128() + line = reader:read_uleb128() elseif asource == ASOURCE_TRACE then - loc.traceno = reader:read_uleb128() - loc.addr = reader:read_uleb128() + traceno = reader:read_uleb128() + addr = reader:read_uleb128() else error("Unknown asource "..asource) end + local loc = symtab.new_loc(symbols, addr, line, traceno) return symtab.id(loc), loc end -local function parse_alloc(reader, asource, events, heap) - local id, loc = parse_location(reader, asource) +local function parse_alloc(reader, asource, events, heap, symbols) + local id, loc = parse_location(reader, asource, symbols) local naddr = reader:read_uleb128() local nsize = reader:read_uleb128() @@ -101,8 +100,8 @@ local function parse_alloc(reader, asource, events, heap) heap[naddr] = {nsize, id, loc} end -local function parse_realloc(reader, asource, events, heap) - local id, loc = parse_location(reader, asource) +local function parse_realloc(reader, asource, events, heap, symbols) + local id, loc = parse_location(reader, asource, symbols) local oaddr = reader:read_uleb128() local osize = reader:read_uleb128() @@ -123,8 +122,8 @@ local function parse_realloc(reader, asource, events, heap) heap[naddr] = {nsize, id, loc} end -local function parse_free(reader, asource, events, heap) - local id, loc = parse_location(reader, asource) +local function parse_free(reader, asource, events, heap, symbols) + local id, loc = parse_location(reader, asource, symbols) local oaddr = reader:read_uleb128() local osize = reader:read_uleb128() @@ -157,7 +156,7 @@ local function ev_header_split(evh) return band(evh, AEVENT_MASK), band(evh, ASOURCE_MASK) end -local function parse_event(reader, events) +local function parse_event(reader, events, symbols) local ev_header = reader:read_octet() assert(ev_header_is_valid(ev_header), "Bad ev_header "..ev_header) @@ -171,12 +170,12 @@ local function parse_event(reader, events) assert(parser, "Bad aevent "..aevent) - parser.parse(reader, asource, events[parser.evname], events.heap) + parser.parse(reader, asource, events[parser.evname], events.heap, symbols) return true end -function M.parse(reader) +function M.parse(reader, symbols) local events = { alloc = {}, realloc = {}, @@ -201,7 +200,7 @@ function M.parse(reader) )) end - while parse_event(reader, events) do + while parse_event(reader, events, symbols) do -- Empty body. end diff --git a/tools/utils/symtab.lua b/tools/utils/symtab.lua index c7fcf77c..c758b67e 100644 --- a/tools/utils/symtab.lua +++ b/tools/utils/symtab.lua @@ -19,16 +19,37 @@ local SYMTAB_TRACE = 1 local M = {} +function M.new_loc(symtab, addr, line, traceno) + local loc = { + addr = addr, + line = line, + traceno = traceno, + epoch = 1, + } + + if traceno ~= 0 and symtab.trace[traceno] then + loc.epoch = #symtab.trace[traceno] + elseif symtab.lfunc[addr] then + loc.epoch = #symtab.lfunc[addr] + end + + return loc +end + -- Parse a single entry in a symtab: lfunc symbol. local function parse_sym_lfunc(reader, symtab) local sym_addr = reader:read_uleb128() local sym_chunk = reader:read_string() local sym_line = reader:read_uleb128() - symtab.lfunc[sym_addr] = { + if not symtab.lfunc[sym_addr] then + symtab.lfunc[sym_addr] = {} + end + + table.insert(symtab.lfunc[sym_addr], { source = sym_chunk, linedefined = sym_line, - } + }) end local function parse_sym_trace(reader, symtab) @@ -37,17 +58,14 @@ local function parse_sym_trace(reader, symtab) local sym_addr = reader:read_uleb128() local sym_line = reader:read_uleb128() - symtab.trace[traceno] = { + if not symtab.trace[traceno] then + symtab.trace[traceno] = {} + end + + table.insert(symtab.trace[traceno], { addr = trace_addr, - -- The structure is the same as the one - -- yielded from the function - -- in the module. - start = { - addr = sym_addr, - line = sym_line, - traceno = 0, - }, - } + start = M.new_loc(symtab, sym_addr, sym_line, 0) + }) end local parsers = { @@ -98,7 +116,9 @@ function M.parse(reader) end function M.id(loc) - return string_format("f%#xl%dt%d", loc.addr, loc.line, loc.traceno) + return string_format( + "f%#xl%dt%de%d", loc.addr, loc.line, loc.traceno, loc.epoch + ) end local function demangle_trace(symtab, loc) @@ -108,7 +128,8 @@ local function demangle_trace(symtab, loc) assert(traceno ~= 0, "Location is a trace") local trace_str = string_format("TRACE [%d] %#x", traceno, addr) - local trace = symtab.trace[traceno] + local epochs = symtab.trace[traceno] + local trace = epochs and epochs[loc.epoch] -- If trace, which was remembered in the symtab, has not -- been flushed, associate it with a proto, where trace @@ -131,8 +152,10 @@ function M.demangle(symtab, loc) return "INTERNAL" end - if symtab.lfunc[addr] then - return string_format("%s:%d", symtab.lfunc[addr].source, loc.line) + if symtab.lfunc[addr] and symtab.lfunc[addr][loc.epoch] then + return string_format( + "%s:%d", symtab.lfunc[addr][loc.epoch].source, loc.line + ) end return string_format("CFUNC %#x", addr) -- 2.33.1