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 5F64C5C4552; Mon, 28 Aug 2023 18:24:44 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 5F64C5C4552 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1693236284; bh=bOB/Xs51j95X0oRP111MikHkYZ0/0NkoKg2fVbP5+tA=; 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=OWqF5sILKXqv6DqeWXuCf3UKUS4vEd6k4m71fkEa81kDLz4dhbO10A3DztGtLyycq gzoQWjB4eUnGhbeZiJP8BmxmZYR7BUW19RiHpZd6jW2XHuTQW269t1rSncUIfBw7y9 qnWrV7g0u1q0Tl/27q63qmjjdPeteRTMaCuLTNTk= Received: from mail-lf1-f52.google.com (mail-lf1-f52.google.com [209.85.167.52]) (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 88AD85C4555 for ; Mon, 28 Aug 2023 18:23:48 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 88AD85C4555 Received: by mail-lf1-f52.google.com with SMTP id 2adb3069b0e04-4ff8f2630e3so5139410e87.1 for ; Mon, 28 Aug 2023 08:23:48 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693236227; x=1693841027; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ae4EwPLWNNlc0DU9C9SJ/bkg0DGp+KStcJziQw4aEJ4=; b=VgF7Q4HF7d6U0UZBgft6R0+mFPKWz78E9RW0EmTz6Nen9Es9Oq36suVMhvbI8R19V6 h9+br5KR59rbxqM39cCeESpMbtStpJZKjiybvi/DyprUakkomIwqx7lw2exOMOng07TK CFaS4Bsge8hFdVvm4UAnGKuaUUuw3pmMsjAhWnIM2pgxvyizVzXWIDVI1Gvui8hGNm06 8fXB39FJ9sv3rbjl/AKEpZzfPoZnGAsVFc5t76GWqAxI4VzKpe9TZWFiGyoYGYthXbnq K8RCwuB9G4MoIBNg8uEUmtqADGRMXI91LbLuWZOpxH6W17YgcNPSGDDHeYUd0yXgsjVz BWCQ== X-Gm-Message-State: AOJu0YwSfqPV1uXUvg9IrlGIWpVVD4TQKFXIbfayQYovkXb4rQLMei0R hNlf9E8nTrJTiJSHI9TH6/kvSWHZtULfAg== X-Google-Smtp-Source: AGHT+IEsaTn5zhfs2iWsCKXyhcNcyAM3qvCFTQ/JnECHL+pKsD4R5ZBzo+j08kvpRFZEElcUIgV1/w== X-Received: by 2002:a05:6512:282c:b0:4fb:889c:c53d with SMTP id cf44-20020a056512282c00b004fb889cc53dmr20597895lfb.10.1693236227493; Mon, 28 Aug 2023 08:23:47 -0700 (PDT) Received: from fckxorg.mail.msk ([2a00:1148:b0ba:16:a3e8:bdc1:dbed:dbc8]) by smtp.gmail.com with ESMTPSA id t11-20020ac243ab000000b004fe36b790a1sm1622184lfl.128.2023.08.28.08.23.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Aug 2023 08:23:47 -0700 (PDT) X-Google-Original-From: Maxim Kokryashkin To: tarantool-patches@dev.tarantool.org, skaplun@tarantool.org, sergeyb@tarantool.org Date: Mon, 28 Aug 2023 18:23:36 +0300 Message-ID: X-Mailer: git-send-email 2.41.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH luajit 2/2] profilers: purge generation mechanism 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" 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. Follows up tarantool/tarantool#8700 --- .../gh-5813-resolving-of-c-symbols.test.lua | 7 ++-- tools/memprof/parse.lua | 2 +- tools/sysprof/parse.lua | 9 ++--- tools/utils/avl.lua | 4 +-- tools/utils/symtab.lua | 33 +++++++------------ 5 files changed, 19 insertions(+), 36 deletions(-) diff --git a/test/tarantool-tests/gh-5813-resolving-of-c-symbols.test.lua b/test/tarantool-tests/gh-5813-resolving-of-c-symbols.test.lua index 30b8a3ca..1581ee4b 100644 --- a/test/tarantool-tests/gh-5813-resolving-of-c-symbols.test.lua +++ b/test/tarantool-tests/gh-5813-resolving-of-c-symbols.test.lua @@ -24,12 +24,9 @@ local TMP_BINFILE = profilename("memprofdata.tmp.bin") local function tree_contains(node, name) if node == nil then return false + elseif node.value.name == name then + return true else - for i = 1, #node.value do - if node.value[i].name == name then - return true - end - end return tree_contains(node.left, name) or tree_contains(node.right, name) end end diff --git a/tools/memprof/parse.lua b/tools/memprof/parse.lua index 1b6eceb4..6fd7451b 100644 --- a/tools/memprof/parse.lua +++ b/tools/memprof/parse.lua @@ -78,7 +78,7 @@ local function parse_location(reader, asource, symbols) else error("Unknown asource "..asource) end - local loc = symtab.loc(symbols, args) + local loc = symtab.loc(args) return symtab.id(loc), symtab.demangle(symbols, loc) end diff --git a/tools/sysprof/parse.lua b/tools/sysprof/parse.lua index 451edecb..bb1cb02c 100755 --- a/tools/sysprof/parse.lua +++ b/tools/sysprof/parse.lua @@ -59,7 +59,7 @@ end local function parse_lfunc(reader, symbols) local addr = reader:read_uleb128() local line = reader:read_uleb128() - local loc = symtab.loc(symbols, { addr = addr, line = line }) + local loc = symtab.loc{ addr = addr, line = line } loc.type = FRAME.LFUNC return symtab.demangle(symbols, loc) end @@ -71,7 +71,7 @@ end local function parse_cfunc(reader, symbols) local addr = reader:read_uleb128() - local loc = symtab.loc(symbols, { addr = addr }) + local loc = symtab.loc{ addr = addr } loc.type = FRAME.CFUNC return symtab.demangle(symbols, loc) end @@ -99,7 +99,7 @@ local function parse_host_callchain(reader, event, symbols) local addr = reader:read_uleb128() while addr ~= 0 do - local loc = symtab.loc(symbols, { addr = addr }) + local loc = symtab.loc{ addr = addr } table.insert(event.host.callchain, 1, symtab.demangle(symbols, loc)) addr = reader:read_uleb128() end @@ -113,14 +113,11 @@ local function parse_trace_callchain(reader, event, symbols) loc.addr = reader:read_uleb128() loc.line = reader:read_uleb128() - local gen = symtab.loc(symbols, loc).gen local name_lua = symtab.demangle(symbols, { addr = loc.addr, traceno = loc.traceno, - gen = gen }) event.lua.trace = loc - event.lua.trace.gen = gen event.lua.trace.name = name_lua end diff --git a/tools/utils/avl.lua b/tools/utils/avl.lua index d5baa534..81ef9265 100644 --- a/tools/utils/avl.lua +++ b/tools/utils/avl.lua @@ -78,7 +78,7 @@ end function M.insert(node, key, value) assert(key, "Key can't be nil") if node == nil then - return create_node(key, { value }) + return create_node(key, value) end if key < node.key then @@ -86,7 +86,7 @@ function M.insert(node, key, value) elseif key > node.key then node.right = M.insert(node.right, key, value) else - table.insert(node.value, value) + node.value = value end update_height(node) diff --git a/tools/utils/symtab.lua b/tools/utils/symtab.lua index c26a9e8c..2afd2fd1 100644 --- a/tools/utils/symtab.lua +++ b/tools/utils/symtab.lua @@ -22,22 +22,13 @@ local SYMTAB_TRACE = 2 local M = {} -function M.loc(symtab, args) +function M.loc(args) local loc = { addr = args.addr or 0, line = args.line or 0, traceno = args.traceno or 0, } - if loc.traceno ~= 0 and symtab.trace[loc.traceno] then - loc.gen = #symtab.trace[loc.traceno] - elseif symtab.lfunc[loc.addr] then - loc.gen = #symtab.lfunc[loc.addr] - else - local _, csym = avl.floor(symtab.cfunc, loc.addr) - loc.gen = csym and #csym or 1 - end - return loc end @@ -56,10 +47,10 @@ function M.parse_sym_lfunc(reader, symtab) ) end - table.insert(symtab.lfunc[sym_addr], { + symtab.lfunc[sym_addr] = { source = sym_chunk, linedefined = sym_line, - }) + } end function M.parse_sym_trace(reader, symtab) @@ -69,9 +60,9 @@ function M.parse_sym_trace(reader, symtab) symtab.trace[traceno] = symtab.trace[traceno] or {} - table.insert(symtab.trace[traceno], { - start = M.loc(symtab, { addr = sym_addr, line = sym_line }) - }) + symtab.trace[traceno] = { + start = M.loc{ addr = sym_addr, line = sym_line } + } end -- Parse a single entry in a symtab: .so library @@ -136,7 +127,7 @@ end function M.id(loc) return string_format( - "f%#xl%dt%dg%d", loc.addr, loc.line, loc.traceno, loc.gen + "f%#xl%dt%dg", loc.addr, loc.line, loc.traceno ) end @@ -146,8 +137,7 @@ local function demangle_trace(symtab, loc) assert(traceno ~= 0, "Location is a trace") local trace_str = string_format("TRACE [%d]", traceno) - local gens = symtab.trace[traceno] - local trace = gens and gens[loc.gen] + local trace = symtab.trace[traceno] if trace then assert(trace.start.traceno == 0, "Trace start is not a trace") @@ -162,21 +152,20 @@ function M.demangle(symtab, loc) end local addr = loc.addr - local gen = loc.gen if addr == 0 then return "INTERNAL" end - if symtab.lfunc[addr] and symtab.lfunc[addr][gen] then - local source = symtab.lfunc[addr][gen].source + if symtab.lfunc[addr] then + local source = symtab.lfunc[addr].source return string_format("%s:%d", symtab.alias[source] or source, loc.line) end local key, value = avl.floor(symtab.cfunc, addr) if key then - return string_format("%s:%#x", value[gen].name, key) + return string_format("%s:%#x", value.name, key) end return string_format("CFUNC %#x", addr) -- 2.41.0