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 43D006ECE3; Mon, 4 Jul 2022 00:39:25 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 43D006ECE3 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1656884365; bh=7VeSHKV0pp8xro98JgBjPqirtRyyOfYHAllhbDjif34=; 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=MrgCm2LGQRQT7oufLJB6NAJM6RZXh/YRNmDwm0QdLkFRGHOoinTTNKc2aEb+Tkryo zwocMw+OICQRA1n5XKjakRHDHicDRhb9fODtv/343YqZCfoH1Qyfdk44OA6KYusnqQ JRn/QtxAGTef1934Q/UDHOZxp2DmrwM3NPh40slc= Received: from mail-lf1-f45.google.com (mail-lf1-f45.google.com [209.85.167.45]) (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 470C76DB1E for ; Mon, 4 Jul 2022 00:38:27 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 470C76DB1E Received: by mail-lf1-f45.google.com with SMTP id y16so12720948lfb.9 for ; Sun, 03 Jul 2022 14:38:27 -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=O4pWdUkd1Psv5POPGh55god0vScR7SzF4jfRE9YJgAY=; b=IFFvshjXD4T4xAQirKZ94kmyJa02iaIUcC2jH/iOtqcXRtHUpTLTQafP2wtDeNlkAx 5HTachmLNofu3imnCAzW6DUf6z1dRiXJYQh3M78zbDNPn6SQix04TZ6SajCWyvTG7pGy 9NJDmir5wkzc5cgv0rOLvdjDHfkXVW//J9oZP25iah4kgjeXbFEm0SK6RgYKNV/WajgS eOLF0P/cXpQbWeVwXIrb6lBFkaFtw9FjZEzU8Nq0L3O14Tg4Rkrjx61IcCdLE2dmQWRt DLNDOl5o3BMHPbQjp+cg/cavISlEeo4VLgbbFjWVIat6YfZtEU3X8PGjpRhvi7ONQTpn VdVw== X-Gm-Message-State: AJIora/uUhG0rI59H9I+qMm94t4IollFZh+F2ecuDeCtmTSDxFV6vmQb s/0NPwSUV6DAgnbqKvV6BcYI+Tg6n+fxwmtLsiw= X-Google-Smtp-Source: AGRyM1u0DeGgrcsol0LqwVjlLbvC0nYHV25m6/kaPd4ukYxdodwpb93yCkfbM1kbj/RNQVHqlKK02w== X-Received: by 2002:ac2:4bcf:0:b0:47f:86f2:812d with SMTP id o15-20020ac24bcf000000b0047f86f2812dmr15953063lfq.400.1656884306603; Sun, 03 Jul 2022 14:38:26 -0700 (PDT) Received: from localhost.localdomain ([2a00:1370:8176:4756:d639:b1a3:1b97:ec28]) by smtp.gmail.com with ESMTPSA id u11-20020a05651220cb00b0047faa01edd9sm4870480lfr.229.2022.07.03.14.38.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Jul 2022 14:38:26 -0700 (PDT) X-Google-Original-From: Maxim Kokryashkin To: tarantool-patches@dev.tarantool.org, imun@tarantool.org, skaplun@tarantool.org Date: Mon, 4 Jul 2022 00:38:15 +0300 Message-Id: <83b89e5c769469d19f0bc9144667685801f3cb51.1656883823.git.m.kokryashkin@tarantool.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH luajit 2/2] sysprof: add stack sandwich support 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 stack sandwich support to the sysprof's parser. Sandwich is handled the following way: 1. If there is a `lua_cpcall` in the C stack trace, nothing is done on the C stack and the corresponding frame on the Lua stack is removed. 2. If there is a `lua_call`/`lua_pcall`, then next chunk of frames is from the Lua stack. That chunk ends with either a CFUNC, or a stack trace end. Resolves tarantool/tarantool#7244 --- tools/sysprof/collapse.lua | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/tools/sysprof/collapse.lua b/tools/sysprof/collapse.lua index b0c4afc8..b815baf3 100755 --- a/tools/sysprof/collapse.lua +++ b/tools/sysprof/collapse.lua @@ -39,9 +39,11 @@ local function insert(name, node, is_leaf) end local function insert_lua_callchain(chain, lua, symbols) + local ins_cnt = 0 for _,fr in pairs(lua.callchain) do local name_lua + ins_cnt = ins_cnt + 1 if fr.type == parse.FRAME.FFUNC then name_lua = vmdef.ffnames[fr.ffid] else @@ -58,38 +60,43 @@ local function insert_lua_callchain(chain, lua, symbols) gen = fr.gen }) end + + if fr.type == parse.FRAME.CFUNC then + -- C function encountered, the next chunk + -- of frames is located on the C stack. + break + end end table.insert(chain, 1, { name = name_lua }) end + table.remove(lua.callchain, ins_cnt) end + -- merge lua and host callchains into one callchain representing -- transfer of control local function merge(event, symbols, sep_vmst) local cc = {} - local lua_inserted = false for _,h_fr in pairs(event.host.callchain) do local name_host = symtab.demangle(symbols, { addr = h_fr.addr, gen = h_fr.gen }) + table.insert(cc, 1, { name = name_host }) - -- We assume that usually the transfer of control - -- looks like: - -- HOST -> LUA -> HOST - -- so for now, lua callchain starts from lua_pcall() call - if name_host == 'lua_pcall' then - insert_lua_callchain(cc, event.lua, symbols) - lua_inserted = true + if string.match(name_host, '^lua_cpcall') ~= nil then + -- Any C function is present on both the C and the Lua + -- stacks. It is more convenient to get its info from the host stack, + -- since it has information about child frames. + table.remove(event.lua.callchain, 1) end - table.insert(cc, 1, { name = name_host }) - end + if string.match(name_host, '^lua_p?call') ~= nil then + insert_lua_callchain(cc, event.lua, symbols) + end - if lua_inserted == false then - insert_lua_callchain(cc, event.lua, symbols) end if sep_vmst == true then -- 2.36.1