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 86A9C6EC55; Sat, 21 Aug 2021 15:51:52 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 86A9C6EC55 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1629550312; bh=V8Nn780T6df7QvmEq0QPJiQYYmW+wkCb9QvnOdxWSUQ=; 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=o1n5xk3KlPDy56R7I4OkiHWZWbMt4Bixl9tdK3uTNFVwCUEecvyS2Z65jqBBkYBq0 QdCL6O0HpIelrqxPlDNTUCJrQLOAM97+KwP3hMi+VbW5ivoc3SggYj1O5IAo9F78HC 6Hu26lCc7FCp/Nu3+qjbGCYjjZywTp0uySpgNb6k= Received: from smtp57.i.mail.ru (smtp57.i.mail.ru [217.69.128.37]) (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 889256EC5A for ; Sat, 21 Aug 2021 15:50:42 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 889256EC5A Received: by smtp57.i.mail.ru with esmtpa (envelope-from ) id 1mHQSP-0007xl-GG; Sat, 21 Aug 2021 15:50:42 +0300 To: tarantool-patches@dev.tarantool.org, imun@tarantool.org, skaplun@tarantool.org Date: Sat, 21 Aug 2021 19:50:01 +0700 Message-Id: <20210821125002.408132-4-m.shishatskiy@tarantool.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210821125002.408132-1-m.shishatskiy@tarantool.org> References: <20210821125002.408132-1-m.shishatskiy@tarantool.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD92087353F0EC44DD9BCE6B93DE0C6C3914462CDB1732D383C182A05F538085040A1C4A1DF2CA5918F0F5CC55E558F36FC7F264C716F672F3B5FD4898F9F12329B X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7227E4400968B082FEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637531CC3E3F637A59A8638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8617DB8B98B2A389C8F4C4EFB889C1552117882F4460429724CE54428C33FAD305F5C1EE8F4F765FC974A882099E279BDA471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F446042972877693876707352033AC447995A7AD18C26CFBAC0749D213D2E47CDBA5A96583BA9C0B312567BB2376E601842F6C81A19E625A9149C048EEB28585415E75ADA9A68A47777D5C6D9CD8FC6C240DEA7642DBF02ECDB25306B2B78CF848AE20165D0A6AB1C7CE11FEE35FF72824B19451C6BA3038C0950A5D36B5C8C57E37DE458B0BC6067A898B09E46D1867E19FE14079C09775C1D3CA48CF3D321E7403792E342EB15956EA79C166A417C69337E82CC275ECD9A6C639B01B78DA827A17800CE78DD9044B304389D4731C566533BA786AA5CC5B56E945C8DA X-B7AD71C0: AC4F5C86D027EB782CDD5689AFBDA7A213B5FB47DCBC3458834459D11680B505CC4EF59ED8B602CC7005DE4D3405E106 X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C414F749A5E30D975C8DC2057B3FE6961BCA58FA067CFDCCCBDD08B132451855839C2B6934AE262D3EE7EAB7254005DCED114C52B35DBB74F4E7EAB7254005DCEDD827CA74CCEABFF31E0A4E2319210D9B64D260DF9561598F01A9E91200F654B064D627B0D8D264A48E8E86DC7131B365E7726E8460B7C23C X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D3447DF5779098ECEE907085F7E6AEAD2BAB0C6BF0EC60AD53A3655424BE44AE9757C8AA1A30906E8501D7E09C32AA3244C744026FBBE6F5B707AEC0301CD6EB6A730363D8B7DA7DD44927AC6DF5659F194 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojzcVJReGZsqMYjI7lHCc1JQ== X-Mailru-Sender: 2317F5BEA8D613097CB8A225516EF02745036F1BE5D654E36DB8E7A8B4E12EDB1E9E08D8BAAD6C2FFF6B26DEAE20951894E739346DD9ABB838AE394B99C5394F99323991B04ED3930F27244EEAA5B9A5AE208404248635DF X-Mras: Ok Subject: [Tarantool-patches] [PATCH luajit v1 3/4] memprof: substitute long proto names with aliases 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" Sometimes a loaded chunk name can be multiline (actually, it is the Lua code itself). In order not to burden memprof parser output with big multiline names, aliases were introduced. The chunk name is replaced by `function_alias_N` (where N is a unique id) to be displayed in the allocation events report. All the aliases are printed in the end of parser's output under the header "ALIASES". Because of changes mentioned above, the API of changed: now symtab has additional `alias` assotiative table for storing aliases and `alias_count` counter to store number of aliases. Follows up 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 Tarantool branch: https://github.com/tarantool/tarantool/tree/shishqa/gh-5815-enrich-symtab-when-prototype-is-allocated tools/memprof.lua | 1 + tools/memprof/humanize.lua | 35 +++++++++++++++++++++++++++++++++++ tools/utils/symtab.lua | 14 +++++++++++++- 3 files changed, 49 insertions(+), 1 deletion(-) diff --git a/tools/memprof.lua b/tools/memprof.lua index 496a0d78..52e09fd9 100644 --- a/tools/memprof.lua +++ b/tools/memprof.lua @@ -106,6 +106,7 @@ local function dump(inputfile) end local dheap = process.form_heap_delta(events) view.leak_info(dheap) + view.aliases(symbols) os.exit(0) end diff --git a/tools/memprof/humanize.lua b/tools/memprof/humanize.lua index 0360362d..72e71080 100644 --- a/tools/memprof/humanize.lua +++ b/tools/memprof/humanize.lua @@ -5,6 +5,9 @@ local symtab = require "utils.symtab" +-- Assume that loaded string chunks have less than 9999 lines. +local ALIAS_MAX_LINE_NUMBER_LEN = 4 + local M = {} function M.render(events) @@ -98,4 +101,36 @@ function M.describe_location(symbols, loc) return symtab.demangle(symbols, loc) end +local function get_aliases(symbols) + local aliases = {} + for source, alias in pairs(symbols.alias) do + table.insert(aliases, { alias, source }) + end + table.sort(aliases, function(a, b) + return a[1] < b[1] + end) + return aliases +end + +local function format_source_prefix(lineno) + local line_str = tostring(lineno) + local line_str_len = line_str:len() + return line_str..string.rep(" ", ALIAS_MAX_LINE_NUMBER_LEN - line_str_len) +end + +function M.aliases(symbols) + if symbols.alias_count == 0 then return end + print("ALIASES:") + local aliases = get_aliases(symbols) + for _, alias in ipairs(aliases) do + print(alias[1]..":") + local lineno = 1 + for line in alias[2]:gmatch("(.-)\n") do + print(format_source_prefix(lineno)..'|'..line) + lineno = lineno + 1 + end + print("~\n") + end +end + return M diff --git a/tools/utils/symtab.lua b/tools/utils/symtab.lua index 601c9563..88fdb42e 100644 --- a/tools/utils/symtab.lua +++ b/tools/utils/symtab.lua @@ -58,6 +58,8 @@ function M.parse(reader) local symtab = { lfunc = {}, trace = {}, + alias = {}, + alias_count = 0, } local magic = reader:read_octets(3) local version = reader:read_octets(1) @@ -102,7 +104,17 @@ local function demangle_lfunc(symtab, loc) if addr == 0 then return "INTERNAL" elseif symtab.lfunc[addr] then - return string_format("%s:%d", symtab.lfunc[loc.addr].source, loc.line) + local name = symtab.lfunc[addr].source + if name:find('\n') == nil then + return string_format("%s:%d", name, loc.line) + end + if not symtab.alias[name] then + symtab.alias[name] = string_format( + "function_alias_%d", symtab.alias_count + ) + symtab.alias_count = symtab.alias_count + 1 + end + return string_format("%s:%d", symtab.alias[name], loc.line) end return string_format("CFUNC %#x", addr) end -- 2.32.0