From: Sergey Kaplun via Tarantool-patches <tarantool-patches@dev.tarantool.org> To: Maxim Kokryashkin <m.kokryashkin@tarantool.org>, tarantool-patches@dev.tarantool.org Subject: Re: [Tarantool-patches] [PATCH luajit 1/2] test: add utility for parsing `jit.dump` Date: Mon, 22 May 2023 10:04:53 +0300 [thread overview] Message-ID: <ZGsUFSh884vBydJW@root> (raw) In-Reply-To: <ZGnKzhuCnB4pf1+w@root> Hi, again! Just some followup fixes, for the previous changes. On 21.05.23, Sergey Kaplun via Tarantool-patches wrote: <snipped> > > > >>+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 > =================================================================== > Fix luacheck warnings with the following changes: =================================================================== diff --git a/test/tarantool-tests/utils/jit_parse.lua b/test/tarantool-tests/utils/jit_parse.lua index 56267713..bd663196 100644 --- a/test/tarantool-tests/utils/jit_parse.lua +++ b/test/tarantool-tests/utils/jit_parse.lua @@ -65,7 +65,7 @@ local function parse_mcode(trace, line) end local header_handlers = { - start = function(ctx, line, trace_num) + start = function(ctx, trace_num, line) local traces = ctx.traces local trace = trace_new(trace_num) trace.parent, trace.parent_exitno = line:match('start (%d+)/(%d+)') @@ -76,23 +76,22 @@ local header_handlers = { ctx.parsing_trace = trace_num ctx.parsing = 'bc' end, - stop = function(ctx, line, trace_num) - local traces = ctx.traces + stop = function(ctx, trace_num) assert(ctx.parsing_trace == trace_num) ctx.parsing_trace = nil ctx.parsing = nil end, - abort = function(ctx, line, trace_num) + abort = function(ctx, trace_num) local traces = ctx.traces assert(ctx.parsing_trace == trace_num) ctx.parsing_trace = nil ctx.parsing = nil traces[trace_num] = nil end, - IR = function(ctx, line, trace_num) + IR = function(ctx) ctx.parsing = 'IR' end, - mcode = function(ctx, line, trace_num) + mcode = function(ctx) ctx.parsing = 'mcode' end, } @@ -110,7 +109,7 @@ local function parse_line(ctx, line) local trace_num, status = line:match('TRACE (%d+) (%w+)') if trace_num then if (header_handlers[status]) then - header_handlers[status](ctx, line, tonumber(trace_num)) + header_handlers[status](ctx, tonumber(trace_num), line) else error('Unknown trace status: ' .. status) end =================================================================== Branch is force-pushed. <snipped> > > >-- > > >Best regards, > > >Maxim Kokryashkin > > > > > -- > Best regards, > Sergey Kaplun -- Best regards, Sergey Kaplun
next prev parent reply other threads:[~2023-05-22 7:09 UTC|newest] Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-05-10 12:34 [Tarantool-patches] [PATCH luajit 0/2] Fix canonicalization of +-0.0 keys for IR_NEWREF Sergey Kaplun via Tarantool-patches 2023-05-10 12:34 ` [Tarantool-patches] [PATCH luajit 1/2] test: add utility for parsing `jit.dump` Sergey Kaplun via Tarantool-patches 2023-05-15 11:11 ` Maxim Kokryashkin via Tarantool-patches 2023-05-15 12:00 ` Maxim Kokryashkin via Tarantool-patches 2023-05-21 7:47 ` Sergey Kaplun via Tarantool-patches 2023-05-21 7:39 ` Sergey Kaplun via Tarantool-patches 2023-05-22 7:04 ` Sergey Kaplun via Tarantool-patches [this message] 2023-05-29 13:55 ` Maxim Kokryashkin via Tarantool-patches 2023-05-16 10:55 ` Sergey Bronnikov via Tarantool-patches 2023-05-22 7:02 ` Sergey Kaplun via Tarantool-patches 2023-05-22 9:14 ` Sergey Kaplun via Tarantool-patches 2023-05-10 12:34 ` [Tarantool-patches] [PATCH luajit 2/2] Fix canonicalization of +-0.0 keys for IR_NEWREF Sergey Kaplun via Tarantool-patches 2023-05-15 12:05 ` Maxim Kokryashkin via Tarantool-patches 2023-05-20 15:03 ` Sergey Kaplun via Tarantool-patches 2023-05-16 12:17 ` Sergey Bronnikov via Tarantool-patches 2023-05-20 14:54 ` Sergey Kaplun via Tarantool-patches 2023-05-22 7:55 ` Sergey Bronnikov via Tarantool-patches 2023-06-27 13:28 ` [Tarantool-patches] [PATCH luajit 1/3] test: split utils.lua into several modules Igor Munkin via Tarantool-patches 2023-06-27 13:35 ` Igor Munkin via Tarantool-patches 2023-06-28 11:36 ` Sergey Kaplun via Tarantool-patches 2023-06-28 16:07 ` Igor Munkin via Tarantool-patches 2023-07-04 17:10 ` [Tarantool-patches] [PATCH luajit 0/2] Fix canonicalization of +-0.0 keys for IR_NEWREF Igor Munkin via Tarantool-patches
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=ZGsUFSh884vBydJW@root \ --to=tarantool-patches@dev.tarantool.org \ --cc=m.kokryashkin@tarantool.org \ --cc=skaplun@tarantool.org \ --subject='Re: [Tarantool-patches] [PATCH luajit 1/2] test: add utility for parsing `jit.dump`' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox