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 87BFF6FC87; Wed, 29 Sep 2021 23:08:34 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 87BFF6FC87 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1632946114; bh=ZXmGmdU3cYiD3CvMRZwLBYij8pZ+FiXOaWch6Iag1GA=; 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=BuvLi++wiLXkhNtyvIBQQcYdarxAl0Hdo7icNu0pDuhr4I6HarMsnOJN1GQnxl5HT icX9jbYG1EKGHdKMYrhdyHZBFW5LIRWcheLeYoMJK8WQfJtRXAby5juCRtEWkTqSvJ fkOJIVQfXRjiW427RtqBoHD2L8k+HaLX4g12Y4c8= Received: from smtp59.i.mail.ru (smtp59.i.mail.ru [217.69.128.39]) (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 3BEAA6FC87 for ; Wed, 29 Sep 2021 23:08:03 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 3BEAA6FC87 Received: by smtp59.i.mail.ru with esmtpa (envelope-from ) id 1mVfs2-0000Jo-89; Wed, 29 Sep 2021 23:08:02 +0300 To: tarantool-patches@dev.tarantool.org, imun@tarantool.org, skaplun@tarantool.org Date: Wed, 29 Sep 2021 23:07:55 +0300 Message-Id: <20210929200758.149446-2-m.shishatskiy@tarantool.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210929200758.149446-1-m.shishatskiy@tarantool.org> References: <20210929200758.149446-1-m.shishatskiy@tarantool.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD96A58C36AA2E996498302BFE8288A953FFF2204EAAF1B1FDF182A05F538085040C4CADA2412773E2205A3DFE746FCFE217C4CF1C9BB09E1EBBBCAF4151EF6E249 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE757F64E7FD849EB4FEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637991D0D3E51C637188F08D7030A58E5AD1A62830130A00468AEEEE3FBA3A834EE7353EFBB553375665D501480F54144109565D6F3FBE27A438B4847EA3284F3D1A471835C12D1D9774AD6D5ED66289B5278DA827A17800CE77A825AB47F0FC8649FA2833FD35BB23D2EF20D2F80756B5F868A13BD56FB6657A471835C12D1D977725E5C173C3A84C317B107DEF921CE79117882F4460429728AD0CFFFB425014E868A13BD56FB6657D81D268191BDAD3DC09775C1D3CA48CF9B5048E0FA8C4E96BA3038C0950A5D36C8A9BA7A39EFB766EC990983EF5C0329BA3038C0950A5D36D5E8D9A59859A8B6AB09403E6B1EC9F476E601842F6C81A1F004C906525384307823802FF610243DF43C7A68FF6260569E8FC8737B5C2249EC8D19AE6D49635B68655334FD4449CB9ECD01F8117BC8BEAAAE862A0553A39223F8577A6DFFEA7CFA80D66F452D417A43847C11F186F3C59DAA53EE0834AAEE X-B7AD71C0: AC4F5C86D027EB782CDD5689AFBDA7A213B5FB47DCBC3458F0AFF96BAACF4158235E5A14AD4A4A4625E192CAD1D9E79DB194B0D77246B867E8548E72384D540E X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C414F749A5E30D975C5D501480F54144109565D6F3FBE27A438B4847EA3284F3D19C2B6934AE262D3EE7EAB7254005DCED7532B743992DF240BDC6A1CF3F042BAD6DF99611D93F60EF9EAAB76869E07C3E699F904B3F4130E343918A1A30D5E7FCCB5012B2E24CD356 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34AEC7C2AC3C44791D1C1CE66BD3E1097AF3614A3C3429E2216951DB469DBF84963FD7DB776167C4821D7E09C32AA3244C1461BF46EFF365DCEE4599847995313C5595C85A795C7BAE927AC6DF5659F194 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojsAIehEB+JdnmuLqk+e0G0w== X-Mailru-Sender: EFA0F3A8419EF21635BFE795C6CB22C9C9126EDF0F70E29305A3DFE746FCFE216CCF71F689FD47EE2376072A51849BFFE66B5C1DBFD5D09D5E022D45988A037B448E0EA96F20AB367402F9BA4338D657ED14614B50AE0675 X-Mras: Ok Subject: [Tarantool-patches] [PATCH luajit v4 1/4] test: separate memprof Lua API tests into subtests 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" As the number of memprof test cases is expected to grow, memprof tests are separated into subtests to encapsulate test cases and be able to skip some of the subtests. Also, output generation and parsing separated into a dedicated function `generate_parsed_output`, which allows one to run memprof on different payloads, passing payload funtion as an argument. 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 .../misclib-memprof-lapi.test.lua | 169 ++++++++++-------- 1 file changed, 94 insertions(+), 75 deletions(-) diff --git a/test/tarantool-tests/misclib-memprof-lapi.test.lua b/test/tarantool-tests/misclib-memprof-lapi.test.lua index 06d96b3b..9de4bd98 100644 --- a/test/tarantool-tests/misclib-memprof-lapi.test.lua +++ b/test/tarantool-tests/misclib-memprof-lapi.test.lua @@ -7,7 +7,7 @@ require("utils").skipcond( local tap = require("tap") local test = tap.test("misc-memprof-lapi") -test:plan(13) +test:plan(3) jit.off() jit.flush() @@ -22,7 +22,7 @@ local symtab = require "utils.symtab" local TMP_BINFILE = arg[0]:gsub(".+/([^/]+)%.test%.lua$", "%.%1.memprofdata.tmp.bin") local BAD_PATH = arg[0]:gsub(".+/([^/]+)%.test%.lua$", "%1/memprofdata.tmp.bin") -local function payload() +local function default_payload() -- Preallocate table to avoid table array part reallocations. local _ = table_new(100, 0) @@ -37,7 +37,7 @@ local function payload() collectgarbage() end -local function generate_output(filename) +local function generate_output(filename, payload) -- Clean up all garbage to avoid pollution of free. collectgarbage() @@ -52,6 +52,25 @@ local function generate_output(filename) assert(res, err) end +local function generate_parsed_output(payload) + local res, err = pcall(generate_output, TMP_BINFILE, payload) + + -- Want to cleanup carefully if something went wrong. + if not res then + os.remove(TMP_BINFILE) + error(err) + end + + local reader = bufread.new(TMP_BINFILE) + local symbols = symtab.parse(reader) + local events = memprof.parse(reader) + + -- We don't need it any more. + os.remove(TMP_BINFILE) + + return symbols, events +end + local function fill_ev_type(events, symbols, event_type) local ev_type = {} for _, event in pairs(events[event_type]) do @@ -86,85 +105,85 @@ local function check_alloc_report(alloc, line, function_line, nevents) return true end --- Not a directory. -local res, err, errno = misc.memprof.start(BAD_PATH) -test:ok(res == nil and err:match("No such file or directory")) -test:ok(type(errno) == "number") - --- Profiler is running. -res, err = misc.memprof.start(TMP_BINFILE) -assert(res, err) -res, err, errno = misc.memprof.start(TMP_BINFILE) -test:ok(res == nil and err:match("profiler is running already")) -test:ok(type(errno) == "number") +-- Test profiler API. +test:test("smoke", function(subtest) + subtest:plan(6) -res, err = misc.memprof.stop() -assert(res, err) + -- Not a directory. + local res, err, errno = misc.memprof.start(BAD_PATH) + subtest:ok(res == nil and err:match("No such file or directory")) + subtest:ok(type(errno) == "number") --- Profiler is not running. -res, err, errno = misc.memprof.stop() -test:ok(res == nil and err:match("profiler is not running")) -test:ok(type(errno) == "number") + -- Profiler is running. + res, err = misc.memprof.start(TMP_BINFILE) + assert(res, err) + res, err, errno = misc.memprof.start(TMP_BINFILE) + subtest:ok(res == nil and err:match("profiler is running already")) + subtest:ok(type(errno) == "number") --- Test profiler output and parse. -res, err = pcall(generate_output, TMP_BINFILE) + res, err = misc.memprof.stop() + assert(res, err) --- Want to cleanup carefully if something went wrong. -if not res then - os.remove(TMP_BINFILE) - error(err) -end + -- Profiler is not running. + res, err, errno = misc.memprof.stop() + subtest:ok(res == nil and err:match("profiler is not running")) + subtest:ok(type(errno) == "number") +end) -local reader = bufread.new(TMP_BINFILE) -local symbols = symtab.parse(reader) -local events = memprof.parse(reader, symbols) - --- We don't need it any more. -os.remove(TMP_BINFILE) - -local alloc = fill_ev_type(events, symbols, "alloc") -local free = fill_ev_type(events, symbols, "free") - --- Check allocation reports. The second argument is a line number --- of the allocation event itself. The third is a line number of --- the corresponding function definition. The last one is --- the number of allocations. --- 1 event - alocation of table by itself + 1 allocation --- of array part as far it is bigger than LJ_MAX_COLOSIZE (16). -test:ok(check_alloc_report(alloc, 27, 25, 2)) --- 100 strings allocations. -test:ok(check_alloc_report(alloc, 32, 25, 100)) - --- Collect all previous allocated objects. -test:ok(free.INTERNAL.num == 102) - --- Tests for leak-only option. --- See also https://github.com/tarantool/tarantool/issues/5812. -local heap_delta = process.form_heap_delta(events, symbols) -local tab_alloc_stats = heap_delta[form_source_line(27)] -local str_alloc_stats = heap_delta[form_source_line(32)] -test:ok(tab_alloc_stats.nalloc == tab_alloc_stats.nfree) -test:ok(tab_alloc_stats.dbytes == 0) -test:ok(str_alloc_stats.nalloc == str_alloc_stats.nfree) -test:ok(str_alloc_stats.dbytes == 0) +-- Test profiler output and parse. +test:test("output", function(subtest) + subtest:plan(7) + + local symbols, events = generate_parsed_output(default_payload) + + local alloc = fill_ev_type(events, symbols, "alloc") + local free = fill_ev_type(events, symbols, "free") + + -- Check allocation reports. The second argument is a line + -- number of the allocation event itself. The third is a line + -- number of the corresponding function definition. The last + -- one is the number of allocations. 1 event - alocation of + -- table by itself + 1 allocation of array part as far it is + -- bigger than LJ_MAX_COLOSIZE (16). + subtest:ok(check_alloc_report(alloc, 27, 25, 2)) + -- 100 strings allocations. + subtest:ok(check_alloc_report(alloc, 32, 25, 100)) + + -- Collect all previous allocated objects. + subtest:ok(free.INTERNAL.num == 102) + + -- Tests for leak-only option. + -- See also https://github.com/tarantool/tarantool/issues/5812. + local heap_delta = process.form_heap_delta(events, symbols) + local tab_alloc_stats = heap_delta[form_source_line(27)] + local str_alloc_stats = heap_delta[form_source_line(32)] + subtest:ok(tab_alloc_stats.nalloc == tab_alloc_stats.nfree) + subtest:ok(tab_alloc_stats.dbytes == 0) + subtest:ok(str_alloc_stats.nalloc == str_alloc_stats.nfree) + subtest:ok(str_alloc_stats.dbytes == 0) +end) -- Test for https://github.com/tarantool/tarantool/issues/5842. --- We are not interested in this report. -misc.memprof.start("/dev/null") --- We need to cause stack resize for local variables at function --- call. Let's create a new coroutine (all slots are free). --- It has 1 slot for dummy frame + 39 free slots + 5 extra slots --- (so-called red zone) + 2 * LJ_FR2 slots. So 50 local variables --- is enough. -local payload_str = "" -for i = 1, 50 do - payload_str = payload_str..("local v%d = %d\n"):format(i, i) -end -local f, errmsg = loadstring(payload_str) -assert(f, errmsg) -local co = coroutine.create(f) -coroutine.resume(co) -misc.memprof.stop() +test:test("stack-resize", function(subtest) + subtest:plan(0) + + -- We are not interested in this report. + misc.memprof.start("/dev/null") + -- We need to cause stack resize for local variables at function + -- call. Let's create a new coroutine (all slots are free). + -- It has 1 slot for dummy frame + 39 free slots + 5 extra slots + -- (so-called red zone) + 2 * LJ_FR2 slots. So 50 local + -- variables is enough. + local payload_str = "" + for i = 1, 50 do + payload_str = payload_str..("local v%d = %d\n"):format(i, i) + end + local f, errmsg = loadstring(payload_str) + assert(f, errmsg) + local co = coroutine.create(f) + coroutine.resume(co) + misc.memprof.stop() +end) jit.on() os.exit(test:check() and 0 or 1) -- 2.33.0