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 431146EC55; Wed, 28 Jul 2021 16:43:47 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 431146EC55 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1627479827; bh=Sse0zn8h51ggpNqvP0zAtqOedzn+w9eWKYcvttIhlzo=; 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=ocnB8bE0cKroSvolSLXB4Foxt9Hk8fwnHeCex4hekF5dxq1ZW2g3tlKeqOC0uoy/M 45/QzR8NZib5VzulIm+FvAj2u0gOBe+YSL2IKbAep04FlkWrcY44ysH3f8KfxP+Wjo gxC3cRlF9u5YcYiF7Pu3LbT3xjE/nTCBl8+KkEZk= Received: from smtp47.i.mail.ru (smtp47.i.mail.ru [94.100.177.107]) (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 A85316EC5A for ; Wed, 28 Jul 2021 16:43:18 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org A85316EC5A Received: by smtp47.i.mail.ru with esmtpa (envelope-from ) id 1m8jq9-0003Ga-Jm; Wed, 28 Jul 2021 16:43:18 +0300 To: tarantool-patches@dev.tarantool.org, imun@tarantool.org, skaplun@tarantool.org Date: Wed, 28 Jul 2021 20:42:58 +0700 Message-Id: <20210728134259.1113235-2-m.shishatskiy@tarantool.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210728134259.1113235-1-m.shishatskiy@tarantool.org> References: <20210728134259.1113235-1-m.shishatskiy@tarantool.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-7564579A: 78E4E2B564C1792B X-77F55803: 4F1203BC0FB41BD941C43E597735A9C34755E0A9F196FCB739C645213AB7C8E0182A05F538085040F23325A92E0D7E1FA7AC806AE1B5FBEA940AA49A19570927946D57CBF7F493D4 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE75C385DEB91CEC222EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637107AA061ADD8C4B78638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8D88482049BD3709104E98A7649067074117882F4460429724CE54428C33FAD305F5C1EE8F4F765FC3A703B70628EAD7BA471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F446042972877693876707352033AC447995A7AD18618001F51B5FD3F9D2E47CDBA5A96583BA9C0B312567BB2376E601842F6C81A19E625A9149C048EEB28585415E75ADA9C0837EA9F3D197644AD6D5ED66289B52698AB9A7B718F8C46E0066C2D8992A16725E5C173C3A84C359B82F0B59EB8CDDBA3038C0950A5D36B5C8C57E37DE458B0BC6067A898B09E46D1867E19FE14079C09775C1D3CA48CF3D321E7403792E342EB15956EA79C166A417C69337E82CC275ECD9A6C639B01B78DA827A17800CE7E1BCFB2C0BE3F189731C566533BA786AA5CC5B56E945C8DA X-B7AD71C0: AC4F5C86D027EB782CDD5689AFBDA7A213B5FB47DCBC3458834459D11680B505D69DAB4247E33C3637C710319AE0595C X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C414F749A5E30D975C7BEA09003D200E085F843FE4A1E36633437A00C5D09D95569C2B6934AE262D3EE7EAB7254005DCED7532B743992DF240BDC6A1CF3F042BAD6DF99611D93F60EF795D7D556640A06E699F904B3F4130E343918A1A30D5E7FCCB5012B2E24CD356 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D3480A9008907CB2FD02B07D7A43347387ADF9073A5D7F2FE641E766218D32213935B3AF0995FF1C4E31D7E09C32AA3244C59AC5320A56053DC683C0194224DBBB33E8609A02908F271927AC6DF5659F194 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojiF1u9eOpfTQ4apZfYmvJ0A== X-Mailru-Sender: 2317F5BEA8D613097CB8A225516EF027BE1BAC68D3663C058BE79BF541606EDEB144B128E80AD666FF6B26DEAE20951894E739346DD9ABB838AE394B99C5394F99323991B04ED3930F27244EEAA5B9A5AE208404248635DF X-Mras: Ok Subject: [Tarantool-patches] [PATCH luajit v2 1/2] memprof: dump traceno if allocate from trace 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" When LuaJIT executes a trace, the trace number is stored in the virtual machine state. So, we can treat this number as an allocation event source in memprof and report allocation events from traces as well. Previously, all the allocations from traces were marked as INTERNAL. This patch introduces the functionality described above by adding a new allocation source type named ASOURCE_TRACE. If at the moment when allocation event occurs VM state indicates that trace executed, trace number streamed to a binary file: | loc-trace := trace-no | trace-no := Also, the memory profiler parser was adjusted to recognize this source type by extending structure: field , representing trace number, was added. Part of tarantool/tarantool#5814 --- Issue: https://github.com/tarantool/tarantool/issues/5814 Branch: https://github.com/tarantool/luajit/tree/shishqa/gh-5814-group-allocations-on-trace-by-trace-number CI: https://github.com/tarantool/tarantool/tree/shishqa/gh-5814-group-allocations-on-trace-by-trace-number src/lj_memprof.c | 14 ++++++++++++-- src/lj_memprof.h | 13 ++++++++----- tools/memprof/parse.lua | 22 ++++++++++++++-------- 3 files changed, 34 insertions(+), 15 deletions(-) diff --git a/src/lj_memprof.c b/src/lj_memprof.c index 2c1ef3b8..0c7e9e89 100644 --- a/src/lj_memprof.c +++ b/src/lj_memprof.c @@ -146,6 +146,14 @@ static void memprof_write_func(struct memprof *mp, uint8_t aevent) lua_assert(0); } +static void memprof_write_trace(struct memprof *mp, uint8_t aevent) +{ + struct lj_wbuf *out = &mp->out; + const global_State *g = mp->g; + lj_wbuf_addbyte(out, aevent | ASOURCE_TRACE); + lj_wbuf_addu64(out, (uint64_t)g->vmstate); +} + static void memprof_write_hvmstate(struct memprof *mp, uint8_t aevent) { lj_wbuf_addbyte(&mp->out, aevent | ASOURCE_INT); @@ -168,9 +176,11 @@ static const memprof_writer memprof_writers[] = { ** But since traces must follow the semantics of the original code, ** behaviour of Lua and JITted code must match 1:1 in terms of allocations, ** which makes using memprof with enabled JIT virtually redundant. - ** Hence use the stub below. + ** But if one wants to investigate allocations with JIT enabled, + ** memprof_write_trace() dumps trace number to the binary output. + ** It can be useful to compare with with jit.v or jit.dump outputs. */ - memprof_write_hvmstate /* LJ_VMST_TRACE */ + memprof_write_trace /* LJ_VMST_TRACE */ }; static void memprof_write_caller(struct memprof *mp, uint8_t aevent) diff --git a/src/lj_memprof.h b/src/lj_memprof.h index 3417475d..e3f55433 100644 --- a/src/lj_memprof.h +++ b/src/lj_memprof.h @@ -53,7 +53,7 @@ #define SYMTAB_LFUNC ((uint8_t)0) #define SYMTAB_FINAL ((uint8_t)0x80) -#define LJM_CURRENT_FORMAT_VERSION 0x01 +#define LJM_CURRENT_FORMAT_VERSION 0x02 /* ** Event stream format: @@ -69,11 +69,13 @@ ** event-realloc := event-header loc? oaddr osize naddr nsize ** event-free := event-header loc? oaddr osize ** event-header := -** loc := loc-lua | loc-c +** loc := loc-lua | loc-c | loc-trace ** loc-lua := sym-addr line-no ** loc-c := sym-addr +** loc-trace := trace-no ** sym-addr := ** line-no := +** trace-no := ** oaddr := ** naddr := ** osize := @@ -88,10 +90,10 @@ ** version: [VVVVVVVV] ** * VVVVVVVV: Byte interpreted as a plain integer version number ** -** event-header: [FUUUSSEE] +** event-header: [FUUSSSEE] ** * EE : 2 bits for representing allocation event type (AEVENT_*) -** * SS : 2 bits for representing allocation source type (ASOURCE_*) -** * UUU : 3 unused bits +** * SSS : 3 bits for representing allocation source type (ASOURCE_*) +** * UU : 2 unused bits ** * F : 0 for regular events, 1 for epilogue's *F*inal header ** (if F is set to 1, all other bits are currently ignored) */ @@ -105,6 +107,7 @@ #define ASOURCE_INT ((uint8_t)(1 << 2)) #define ASOURCE_LFUNC ((uint8_t)(2 << 2)) #define ASOURCE_CFUNC ((uint8_t)(3 << 2)) +#define ASOURCE_TRACE ((uint8_t)(4 << 2)) #define LJM_EPILOGUE_HEADER 0x80 diff --git a/tools/memprof/parse.lua b/tools/memprof/parse.lua index 12e2758f..2d3c71f0 100644 --- a/tools/memprof/parse.lua +++ b/tools/memprof/parse.lua @@ -11,7 +11,7 @@ local lshift = bit.lshift local string_format = string.format local LJM_MAGIC = "ljm" -local LJM_CURRENT_VERSION = 1 +local LJM_CURRENT_VERSION = 0x02 local LJM_EPILOGUE_HEADER = 0x80 @@ -24,8 +24,11 @@ local AEVENT_MASK = 0x3 local ASOURCE_INT = lshift(1, 2) local ASOURCE_LFUNC = lshift(2, 2) local ASOURCE_CFUNC = lshift(3, 2) +local ASOURCE_TRACE = lshift(4, 2) -local ASOURCE_MASK = lshift(0x3, 2) +local ASOURCE_MASK = lshift(0x7, 2) + +local EV_HEADER_MAX = ASOURCE_TRACE + AEVENT_REALLOC local M = {} @@ -59,20 +62,23 @@ local function link_to_previous(heap_chunk, e, nsize) end end -local function id_location(addr, line) - return string_format("f%#xl%d", addr, line), { +local function id_location(addr, line, traceno) + return string_format("f%#xl%dt%d", addr, line, traceno), { addr = addr, line = line, + traceno = traceno, } end local function parse_location(reader, asource) if asource == ASOURCE_INT then - return id_location(0, 0) + return id_location(0, 0, 0) elseif asource == ASOURCE_CFUNC then - return id_location(reader:read_uleb128(), 0) + return id_location(reader:read_uleb128(), 0, 0) elseif asource == ASOURCE_LFUNC then - return id_location(reader:read_uleb128(), reader:read_uleb128()) + return id_location(reader:read_uleb128(), reader:read_uleb128(), 0) + elseif asource == ASOURCE_TRACE then + return id_location(0, 0, reader:read_uleb128()) end error("Unknown asource "..asource) end @@ -140,7 +146,7 @@ local parsers = { } local function ev_header_is_valid(evh) - return evh <= 0x0f or evh == LJM_EPILOGUE_HEADER + return evh <= EV_HEADER_MAX or evh == LJM_EPILOGUE_HEADER end -- Splits event header into event type (aka aevent = allocation -- 2.32.0