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 19AFA45B1D9; Sun, 21 May 2023 10:44:06 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 19AFA45B1D9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1684655046; bh=HBZzkUPR2lNXMUKTQKMUwDHoRkYhRSP6yAozzy6bTYw=; h=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=kTa4l5ypIIXItFObD8mh8TBwIyNUZlaA0V9WRvjYCt1cIk1TzIT2e7rZdWVrvMXsT bWaN6XBkU/ZXsKoMA/S3lCJJ++CqpqXkdogDmRcTys6gSr7aKfOCqN6KjnGlaZnF1D rEoRSQO2TaMzU/8fNDuBipN8uq7HezuaY7jjin3g= Received: from smtpng1.i.mail.ru (smtpng1.i.mail.ru [94.100.181.251]) (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 713C7385C01 for ; Sun, 21 May 2023 10:44:04 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 713C7385C01 Received: by smtpng1.m.smailru.net with esmtpa (envelope-from ) id 1q0djX-0007PI-J8; Sun, 21 May 2023 10:44:04 +0300 Date: Sun, 21 May 2023 10:39:58 +0300 To: Maxim Kokryashkin Message-ID: References: <44354d682d3cabf5a3ab1a268f900d7e6f981020.1683720396.git.skaplun@tarantool.org> <1684149117.34095260@f521.i.mail.ru> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <1684149117.34095260@f521.i.mail.ru> X-Mailru-Src: smtp X-4EC0790: 10 X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD921E8753A900160F1BB957990A28171DD09D8AFDFA21B5BCF182A05F5380850409351A5650C4BD1D795FF3D1AD37E7794459D43ABB60A3915B83A7E1379365A21 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7AC4684DF4EC4B256EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006374FA524FBD8B89EAA8638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D84400551EDF87ABF53FC192609C137E2A117882F4460429724CE54428C33FAD305F5C1EE8F4F765FC20302DFC78685446A471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F4460429728776938767073520437C869540D2AB0FCB629EEF1311BF91D2E47CDBA5A96583BA9C0B312567BB231DD303D21008E29813377AFFFEAFD269A417C69337E82CC2E827F84554CEF50127C277FBC8AE2E8BA83251EDC214901ED5E8D9A59859A8B613439FA09F3DCB32089D37D7C0E48F6C5571747095F342E88FB05168BE4CE3AF X-C1DE0DAB: 0D63561A33F958A58EC57C189F45BD23B0BFDB499C6240309B929C441881E69DF87CCE6106E1FC07E67D4AC08A07B9B06A1CB4668A9CA5FACB5012B2E24CD356 X-C8649E89: 1C3962B70DF3F0ADE00A9FD3E00BEEDF3FED46C3ACD6F73ED3581295AF09D3DF87807E0823442EA2ED31085941D9CD0AF7F820E7B07EA4CF877CA10660BCB528B6B40DCD1A46990983230ACE7BB8B4432626BE56BFB127A9422E0C78D0E1535544C44B1DB2C1FC29C45C6869C64907DAC8BECF0ADF1FDC3BA8CAA110EC39F0D1 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2bioj5fgIvaFza06CkZHZyfjz3A== X-DA7885C5: 180EE6B435872C46AB75CCA7F51B380AD1C0DC21418F1A1220BC0091DE99C62C262E2D401490A4A0DB037EFA58388B346E8BC1A9835FDE71 X-Mailru-Sender: 689FA8AB762F73930F533AC2B33E986BDF498A4BE784758D6969C330B21399470FBE9A32752B8C9C2AA642CC12EC09F1FB559BB5D741EB962F61BD320559CF1EFD657A8799238ED55FEEDEB644C299C0ED14614B50AE0675 X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH luajit 1/2] test: add utility for parsing `jit.dump` 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: Sergey Kaplun via Tarantool-patches Reply-To: Sergey Kaplun Cc: tarantool-patches@dev.tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" Hi, Maxim! Thanks for the review! Please consider my answers below. On 15.05.23, Maxim Kokryashkin wrote: > > Hi, Sergey! > Thanks for the patch! > Please consider my comments below. >   > >  > >>This commit adds simple parser for traces to be analyzed in the test. > >Typo: s/adds/adds a/ Fixed. > >>For now nothing too fancy at all -- just start `jit.dump` to temporary > >Typo: s/temporary/a temporary/ Fixed. > >>file and parse and remove this file when dump is stopped. The array > >>with resulting traces is returned. > >> > >>For now, just find a single IR by pattern and return ref number and IR, > >>if exists. More functionality may be added if it will be necessary for > >Typo: s/if exists/if they exist/ > >Typo: s/it will be/it is/ Fixed, thanks! > >>tests. > >>--- > >> test/tarantool-tests/utils/jit_parse.lua | 156 +++++++++++++++++++++++ > >> 1 file changed, 156 insertions(+) > >> create mode 100644 test/tarantool-tests/utils/jit_parse.lua > >> > >>diff --git a/test/tarantool-tests/utils/jit_parse.lua b/test/tarantool-tests/utils/jit_parse.lua > >>new file mode 100644 > >>index 00000000..fe8e0e08 > >>--- /dev/null > >>+++ b/test/tarantool-tests/utils/jit_parse.lua > >>@@ -0,0 +1,156 @@ > >>+local function parse_trace_hdr(ctx, line, trace_num, status) > >>+ local traces = ctx.traces > >>+ if status == 'start' then > >>+ local trace = trace_new(trace_num) > >>+ trace.parent, trace.parent_exitno = line:match('start (%d+)/(%d+)') > >>+ -- XXX: Assume, that source line can't contain spaces. > >>+ -- For example, it's not "(command line)". > >>+ trace.start_loc = line:match(' ([^%s]+)$') > >>+ traces[trace_num] = trace > >>+ ctx.parsing_trace = trace_num > >>+ ctx.parsing = 'bc' > >>+ elseif status == 'stop' then > >>+ assert(ctx.parsing_trace == trace_num) > >>+ ctx.parsing_trace = nil > >>+ ctx.parsing = nil > >>+ elseif status == 'abort' then > >>+ assert(ctx.parsing_trace == trace_num) > >>+ ctx.parsing_trace = nil > >>+ ctx.parsing = nil > >>+ traces[trace_num] = nil > >Two branches below are almost identical. Is it possible to avoid > >duplication? I suppose, no, especially since we may want to do some more work for aborted traces (I just don't sure for now). > >Side note: Also, I like it much more when switch-like constructions > >in Lua are implemented with tables, because it seems to be cleaner. > >Feel free to ignore. Rewritten in this way, see the iterative patch below. Branch is force-pushed. =================================================================== diff --git a/test/tarantool-tests/utils/jit_parse.lua b/test/tarantool-tests/utils/jit_parse.lua index fe8e0e08..7e8f879e 100644 --- a/test/tarantool-tests/utils/jit_parse.lua +++ b/test/tarantool-tests/utils/jit_parse.lua @@ -64,9 +64,9 @@ local function parse_mcode(trace, line) trace.mcode[#trace.mcode + 1] = {addr = addr, instruction = instruction,} end -local function parse_trace_hdr(ctx, line, trace_num, status) - local traces = ctx.traces - if status == 'start' then +local header_handlers = { + start = function(ctx, line, trace_num) + local traces = ctx.traces local trace = trace_new(trace_num) trace.parent, trace.parent_exitno = line:match('start (%d+)/(%d+)') -- XXX: Assume, that source line can't contain spaces. @@ -75,23 +75,27 @@ local function parse_trace_hdr(ctx, line, trace_num, status) traces[trace_num] = trace ctx.parsing_trace = trace_num ctx.parsing = 'bc' - elseif status == 'stop' then + end, + stop = function(ctx, line, trace_num) + local traces = ctx.traces assert(ctx.parsing_trace == trace_num) ctx.parsing_trace = nil ctx.parsing = nil - elseif status == 'abort' then + end, + abort = function(ctx, line, trace_num) + local traces = ctx.traces assert(ctx.parsing_trace == trace_num) ctx.parsing_trace = nil ctx.parsing = nil traces[trace_num] = nil - elseif status == 'IR' then + end, + IR = function(ctx, line, trace_num) ctx.parsing = 'IR' - elseif status == 'mcode' then + end, + mcode = function(ctx, line, trace_num) ctx.parsing = 'mcode' - else - error('Unknown trace status: ' .. status) - end -end + end, +} local function parse_line(ctx, line) if line == '' then @@ -105,7 +109,11 @@ local function parse_line(ctx, line) local trace_num, status = line:match('TRACE (%d+) (%w+)') if trace_num then - parse_trace_hdr(ctx, line, tonumber(trace_num), status) + if (header_handlers[status]) then + header_handlers[status](ctx, line, tonumber(trace_num)) + else + error('Unknown trace status: ' .. status) + end return end =================================================================== > >>+ elseif status == 'IR' then > >>+ ctx.parsing = 'IR' > >>+ elseif status == 'mcode' then > >>+ ctx.parsing = 'mcode' > >>+ else > >>+ error('Unknown trace status: ' .. status) > >>+ end > >>+end > >>+ > >>+ > >>+local JDUMP_FILE > >>+ > >>+local function parse_jit_dump() > >>+ local ctx = {traces = {}} > >>+ for line in io.lines(JDUMP_FILE) do > >I think we should perform error checking for that io operation. It is done under the hood: | $ src/luajit -e 'for _ in io.lines("unexisted") do end ' | src/luajit: (command line):1: bad argument #1 to 'lines' (unexisted: No such file or directory) | stack traceback: | [C]: in function 'lines' | (command line):1: in main chunk | [C]: at 0x55b73c281064 > >>+ parse_line(ctx, line) > >>+ end > >>+ return ctx.traces > >>+end > >>+ > >>+M.start = function(flags) > >>+ assert(JDUMP_FILE == nil, 'jit_parse is already running') > >>+ -- Always use plain text output. > >>+ flags = flags .. 'T' > >Nit: What if either `A` or `H` is present in the flags? I believe, no > >one is going to do such things, but anyway it is worth considering > >as a thing to check. Feel free to ignore. It is rewritten by the last flag (i.e. appended `T`). > >>+ JDUMP_FILE = os.tmpname() > >>+ jdump.start(flags, JDUMP_FILE) > >>+end > >>+ > >>+M.finish = function() > >>+ assert(JDUMP_FILE ~= nil, 'jit_parse is not running') > >>+ jdump.off() > >>+ local traces = parse_jit_dump() > >>+ os.remove(JDUMP_FILE) > >>+ JDUMP_FILE = nil > >>+ return traces > >>+end > >>+ > >>+-- Turn off compilation for these modules to avoid side effects. > >>+jit.off(true, true) > >>+jit.off(jdump.on, true) > >>+jit.off(jdump.off, true) > >>+ > >>+return M > >>-- > >>2.34.1 > >-- > >Best regards, > >Maxim Kokryashkin > >  -- Best regards, Sergey Kaplun