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 DAB3570358; Wed, 15 Sep 2021 20:20:08 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org DAB3570358 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1631726408; bh=XyIDFYp/EuXD4yegmxvsnQxrHKWkY1tRwmFj3F784ws=; 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=aO6sP2RcrTBx4r830kyIAEed8pHofB42PPyQhXJPjMH85Qoah0LDAvE+7TGhzIO58 gWxqc4IKxMnk0HtCPb/3aVKopUXgPPx3fXUAt0OFAfGLBHKxaJdZVz/BANXtDlaFpb 07SYvLIr3hctOMAbPXJeVH9ufKQxDswDvnKJre5Y= Received: from mail-lj1-f169.google.com (mail-lj1-f169.google.com [209.85.208.169]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id EBFDA7189E for ; Wed, 15 Sep 2021 20:19:08 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org EBFDA7189E Received: by mail-lj1-f169.google.com with SMTP id f2so2397926ljn.1 for ; Wed, 15 Sep 2021 10:19:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=cnxqgYlPIJ5ntdDyPLfIiG/tWHUsyY544nxibM3FoWg=; b=DeR9GK+Zak2IFEek4X0lbclr9j1HwHx7GKXZoG0VT1SraqXs1yQwuX+Zgbi49j7Dyv LhZdGD16/pK8Aw5m15QdqSZ6j1RTbjvseQ3peDuag8ojFFMMXEzmxUR1ooqWJvZBsBqx zd5m417pGILB+rqVJkJqltdONfcFR795TJg5bjvNQoVQ6HKexD7plw6Q9EXnBWMdgmGm 7TcK3xUycwQY3MeGzSIgyGzx1iwxSrwrn47GaBngHomFQKx6XezD0lD3kjo2AxTc7mY4 SObuEokeeanV385vk2KqMWeZcpRK/cJqSO4lSpjC5k1gui49FAH3KuTl/9sxaPJpapHS DJ+A== X-Gm-Message-State: AOAM533KJOD5g4Bn0460SB/EUnRhIm45mslRyvDjQcNRnP1m08OLu05Z RPCeNs+SZvRbsbWwir/WD2Y/HA6LbpbIzQzN X-Google-Smtp-Source: ABdhPJzGHmQXbW24UXPuvdMsR2y7Ap05Aft/tZxzo+kkDKs9cNDNZpa+F+wB2TexEDyjLa+YFujJaw== X-Received: by 2002:a2e:7d0e:: with SMTP id y14mr968507ljc.251.1631726348203; Wed, 15 Sep 2021 10:19:08 -0700 (PDT) Received: from localhost.localdomain ([93.175.11.199]) by smtp.gmail.com with ESMTPSA id v5sm60271ljg.117.2021.09.15.10.19.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Sep 2021 10:19:07 -0700 (PDT) X-Google-Original-From: Maxim Kokryashkin To: tarantool-patches@dev.tarantool.org, imun@tarantool.org, skaplun@tarantool.org Date: Wed, 15 Sep 2021 20:19:01 +0300 Message-Id: <3cb24b983b346ee7e6b032c403534c6dee4094f3.1631725806.git.m.kokryashkin@tarantool.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH luajit v3 2/2] memprof: update memprof parser 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: Maxim Kokryashkin via Tarantool-patches Reply-To: Maxim Kokryashkin Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" This commit introduces demangling of C symbols to memprof parser. As symbol table format has changed, parser needed to be updated too. Now the parser supports new symbol table entries, containing data about symbols from shared objects, that were loaded at the moment of data collection. Also, now the parser supports symtab events in the event stream and extends the symtab corresponding to them. Closes tarantool/tarantool#5813 --- .../misclib-memprof-lapi.test.lua | 4 +-- tools/memprof.lua | 6 ++++ tools/memprof/parse.lua | 17 ++++++++- tools/memprof/process.lua | 7 ++++ tools/utils/symtab.lua | 35 +++++++++++++++---- 5 files changed, 60 insertions(+), 9 deletions(-) diff --git a/test/tarantool-tests/misclib-memprof-lapi.test.lua b/test/tarantool-tests/misclib-memprof-lapi.test.lua index 06d96b3b..bdb77549 100644 --- a/test/tarantool-tests/misclib-memprof-lapi.test.lua +++ b/test/tarantool-tests/misclib-memprof-lapi.test.lua @@ -61,10 +61,10 @@ local function fill_ev_type(events, symbols, event_type) name = "INTERNAL", num = event.num, } - elseif symbols[addr] then + elseif symbols.SYMTAB_LFUNC[addr] then ev_type[event.loc.line] = { name = string.format( - "%s:%d", symbols[addr].source, symbols[addr].linedefined + "%s:%d", symbols.SYMTAB_LFUNC[addr].source, symbols.SYMTAB_LFUNC[addr].linedefined ), num = event.num, } diff --git a/tools/memprof.lua b/tools/memprof.lua index 18b44fdd..8fbc6a3c 100644 --- a/tools/memprof.lua +++ b/tools/memprof.lua @@ -101,6 +101,12 @@ local function dump(inputfile) local reader = bufread.new(inputfile) local symbols = symtab.parse(reader) local events = memprof.parse(reader, symbols) + + -- TODO move this for to process.lua + for addr, event in pairs(events.symtab) do + symtab.add_cfunc(symbols, addr, event.name) + end + if not leak_only then view.profile_info(events, symbols) end diff --git a/tools/memprof/parse.lua b/tools/memprof/parse.lua index 12e2758f..61a95d0f 100644 --- a/tools/memprof/parse.lua +++ b/tools/memprof/parse.lua @@ -11,10 +11,11 @@ local lshift = bit.lshift local string_format = string.format local LJM_MAGIC = "ljm" -local LJM_CURRENT_VERSION = 1 +local LJM_CURRENT_VERSION = 2 local LJM_EPILOGUE_HEADER = 0x80 +local AEVENT_SYMTAB = 0 local AEVENT_ALLOC = 1 local AEVENT_FREE = 2 local AEVENT_REALLOC = 3 @@ -36,6 +37,7 @@ local function new_event(loc) free = 0, alloc = 0, primary = {}, + name = nil } end @@ -77,6 +79,17 @@ local function parse_location(reader, asource) error("Unknown asource "..asource) end +local function parse_symtab(reader, asource, events, heap) + local id = reader:read_uleb128() + local name = reader:read_string() + + if not events[id] then + events[id] = new_event(0) + end + + events[id].name = name +end + local function parse_alloc(reader, asource, events, heap) local id, loc = parse_location(reader, asource) @@ -134,6 +147,7 @@ local function parse_free(reader, asource, events, heap) end local parsers = { + [AEVENT_SYMTAB] = {evname = "symtab", parse = parse_symtab}, [AEVENT_ALLOC] = {evname = "alloc", parse = parse_alloc}, [AEVENT_FREE] = {evname = "free", parse = parse_free}, [AEVENT_REALLOC] = {evname = "realloc", parse = parse_realloc}, @@ -174,6 +188,7 @@ function M.parse(reader) realloc = {}, free = {}, heap = {}, + symtab = {} } local magic = reader:read_octets(3) diff --git a/tools/memprof/process.lua b/tools/memprof/process.lua index 0bcb965b..25a70878 100644 --- a/tools/memprof/process.lua +++ b/tools/memprof/process.lua @@ -56,4 +56,11 @@ function M.form_heap_delta(events, symbols) return dheap end +function M.enrich_symtab(events, symbols) + for event, addr in pairs(events.symtab) do + print(event.name) + symtab.add_cfunc(symtab, addr, event.name) + end +end + return M diff --git a/tools/utils/symtab.lua b/tools/utils/symtab.lua index 3ed1dd13..79f656ac 100644 --- a/tools/utils/symtab.lua +++ b/tools/utils/symtab.lua @@ -10,11 +10,12 @@ local band = bit.band local string_format = string.format local LJS_MAGIC = "ljs" -local LJS_CURRENT_VERSION = 1 +local LJS_CURRENT_VERSION = 2 local LJS_EPILOGUE_HEADER = 0x80 local LJS_SYMTYPE_MASK = 0x03 local SYMTAB_LFUNC = 0 +local SYMTAB_CFUNC = 1 local M = {} @@ -24,18 +25,33 @@ local function parse_sym_lfunc(reader, symtab) local sym_chunk = reader:read_string() local sym_line = reader:read_uleb128() - symtab[sym_addr] = { + symtab.SYMTAB_LFUNC[sym_addr] = { source = sym_chunk, linedefined = sym_line, } end +-- Parse a single entry in a symtab: .so library +local function parse_sym_cfunc(reader, symtab) + local addr = reader:read_uleb128() + local name = reader:read_string() + + symtab.SYMTAB_CFUNC[addr] = { + name = name + } +end + local parsers = { [SYMTAB_LFUNC] = parse_sym_lfunc, + [SYMTAB_CFUNC] = parse_sym_cfunc } function M.parse(reader) - local symtab = {} + local symtab = { + SYMTAB_LFUNC = {}, + SYMTAB_CFUNC = {} + } + local magic = reader:read_octets(3) local version = reader:read_octets(1) @@ -69,7 +85,6 @@ function M.parse(reader) parsers[sym_type](reader, symtab) end end - return symtab end @@ -80,11 +95,19 @@ function M.demangle(symtab, loc) return "INTERNAL" end - if symtab[addr] then - return string_format("%s:%d", symtab[addr].source, loc.line) + if symtab.SYMTAB_LFUNC[addr] then + return string_format("%s:%d", symtab.SYMTAB_LFUNC[addr].source, loc.line) + end + + if symtab.SYMTAB_CFUNC[addr] then + return string_format("%s:%#x", symtab.SYMTAB_CFUNC[addr].name, addr) end return string_format("CFUNC %#x", addr) end +function M.add_cfunc(symtab, addr, name) + symtab.SYMTAB_CFUNC[addr] = {name = name} +end + return M -- 2.33.0