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 0E5E5440F5A; Wed, 10 May 2023 15:39:35 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 0E5E5440F5A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1683722375; bh=LVR4EdVW5ABgub+q+nJyedzREr0TNvOi69oHH57RXRw=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=QYFQHCUdsMx5+187TMwLkSyrIgDT9X5glPFb6wfs813B+lRxqMnwOEStSRw5lDwIo 9XU5AYaFZ+yPzQ2N+ua35PhSDM3aSWeK3zii0OqQOz8utz7liGRE+VgANsRMZsiWSZ /q8jXG02/PagCf7qk46bNG/p4h50r8nbCrf8Wmv8= 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 54DF5440F5A for ; Wed, 10 May 2023 15:39:04 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 54DF5440F5A Received: by smtpng1.m.smailru.net with esmtpa (envelope-from ) id 1pwj5z-0007mJ-1o; Wed, 10 May 2023 15:39:03 +0300 To: Maxim Kokryashkin , Sergey Bronnikov Date: Wed, 10 May 2023 15:34:58 +0300 Message-Id: <44354d682d3cabf5a3ab1a268f900d7e6f981020.1683720396.git.skaplun@tarantool.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Mailru-Src: smtp X-4EC0790: 10 X-7564579A: EEAE043A70213CC8 X-77F55803: 4F1203BC0FB41BD9CDD72DB02570E1E6C28BDE17B2796FFDBAEF94A0693FAF2B1313CFAB8367EF908E2BE116634AD74D9A4B75338FB1C1BBDED92584EC441C866BCCDC235F80B9212CB18641EECF04CF X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7A3295C83650092F9EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637F356C90F3414EBBD8638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8C738D32B2D2D457F9CE7289028BDD902117882F4460429724CE54428C33FAD305F5C1EE8F4F765FC112FDFC3C1A25714A471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F4460429728776938767073520C24E1E72F37C03A0E5D25F19253116ADD2E47CDBA5A96583BA9C0B312567BB231DD303D21008E29813377AFFFEAFD269A417C69337E82CC2E827F84554CEF50127C277FBC8AE2E8BA83251EDC214901ED5E8D9A59859A8B67257B14DC1D4E3CB089D37D7C0E48F6C5571747095F342E88FB05168BE4CE3AF X-C1DE0DAB: 0D63561A33F958A5C96CEDA46AA62A3E9AF4754A0BA323D83729D7C6F4FA30E4F87CCE6106E1FC07E67D4AC08A07B9B06A1CB4668A9CA5FA9C5DF10A05D560A950611B66E3DA6D700B0A020F03D25A0997E3FB2386030E77 X-C8649E89: 1C3962B70DF3F0ADE00A9FD3E00BEEDF3FED46C3ACD6F73ED3581295AF09D3DF87807E0823442EA2ED31085941D9CD0AF7F820E7B07EA4CF30C405D258784F4C83BBD24FF66050681347E476D9EFA23DFC03D1309D91C0B7065B4C0772F80DDCB48303DC63DA819C7912A17B7D013E81D64E577C541B0BD6F4E8A8FB6BF8EBF5 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2bioj6KE94DszzaoqjHX6ruvQPQ== X-DA7885C5: A03F422A528BE930427A1874C577093128EF3B4846750DFAFCB77E4EBF92EF31262E2D401490A4A0DB037EFA58388B346E8BC1A9835FDE71 X-Mailru-Sender: 689FA8AB762F73933AF1F914F131DBF5A05A2DF9EE4B8D501DA830CB23010D1B0FBE9A32752B8C9C2AA642CC12EC09F1FB559BB5D741EB962F61BD320559CF1EFD657A8799238ED55FEEDEB644C299C0ED14614B50AE0675 X-Mras: Ok Subject: [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" This commit adds simple parser for traces to be analyzed in the test. For now nothing too fancy at all -- just start `jit.dump` to temporary 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 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 jdump = require('jit.dump') + +local M = {} + +local trace_mt = {} +trace_mt.__index = trace_mt + +-- Find and return the first IR ref and value matched the pattern +-- for the trace. +trace_mt.has_ir = function(trace, ir_pattern) + for i = 1, #trace.ir do + local ir = trace.ir[i] + if ir:match(ir_pattern) then + return i, ir + end + end +end + +local function trace_new(n) + return setmetatable({ + number = n, + parent = nil, + parent_exitno = nil, + start_loc = nil, + bc = {}, + ir = {}, + mcode = {}, + snaps = {}, + }, trace_mt) +end + +local function parse_bc(trace, line) + trace.bc[#trace.bc + 1] = line +end + +local function parse_snap(trace, n_snap, line) + assert(trace.snaps[n_snap] == nil) + trace[n_snap] = {ref = #trace.ir + 1, slots = line:match('%[(.*)%]$'),} +end + +local function parse_ir(trace, line) + local n_snap = line:match('SNAP%s+#(%d+)') + if n_snap then + parse_snap(trace, n_snap, line) + return + end + + local current_ins, ir = line:match('^(%d+)%s+(.*)$') + current_ins = tonumber(current_ins) + -- Insert NOP instruction hidden in IR dump. + if current_ins ~= #trace.ir + 1 then + trace.ir[#trace.ir + 1] = 'nil NOP' + end + assert(current_ins == #trace.ir + 1) + trace.ir[current_ins] = ir +end + +local function parse_mcode(trace, line) + -- Skip loop label. + if line == '-> LOOP:' then + return + end + local addr, instruction = line:match('^(%w+)%s+(.*)$') + 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 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 + elseif status == 'IR' then + ctx.parsing = 'IR' + elseif status == 'mcode' then + ctx.parsing = 'mcode' + else + error('Unknown trace status: ' .. status) + end +end + +local function parse_line(ctx, line) + if line == '' then + return + end + + if line:match('TRACE flush') then + ctx.traces = {} + return + end + + local trace_num, status = line:match('TRACE (%d+) (%w+)') + if trace_num then + parse_trace_hdr(ctx, line, tonumber(trace_num), status) + return + end + + assert(ctx.parsing_trace) + + local trace = ctx.traces[ctx.parsing_trace] + if ctx.parsing == 'bc' then + parse_bc(trace, line) + elseif ctx.parsing == 'IR' then + parse_ir(trace, line) + elseif ctx.parsing == 'mcode' then + parse_mcode(trace, line) + end +end + +local JDUMP_FILE + +local function parse_jit_dump() + local ctx = {traces = {}} + for line in io.lines(JDUMP_FILE) do + 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' + 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