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 5F31C72FFE2; Tue, 12 Dec 2023 14:56:17 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 5F31C72FFE2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1702382177; bh=EkgQmhEkN7rP3bc/1mN9/VGtgYguRPTS33YOEKOzr0k=; 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=JnJAdwcQfqq49V2U4Hrd2BwNRjw+Ij6JrKDmXXqv5T0GfZUG7x6stC2GoI/ujbWan 0YPW2Egd7s9Fb5WRgydsKZSryss0CcRSA5vqdVJKqKw2BpuADNKWDoNHRj14nRseuP Jqh57MkMB6uR8Sazkw2H2NDphhSQODoJBFkYC+Fc= Received: from smtp36.i.mail.ru (smtp36.i.mail.ru [95.163.41.77]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 7373772FA48 for ; Tue, 12 Dec 2023 14:56:16 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 7373772FA48 Received: by smtp36.i.mail.ru with esmtpa (envelope-from ) id 1rD1N1-006RRm-2A; Tue, 12 Dec 2023 14:56:16 +0300 Date: Tue, 12 Dec 2023 14:51:43 +0300 To: Maxim Kokryashkin Message-ID: References: <4fb82034fcac21359f79b81cc6643054fc432be3.1701888856.git.m.kokryashkin@tarantool.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4fb82034fcac21359f79b81cc6643054fc432be3.1701888856.git.m.kokryashkin@tarantool.org> X-Mailru-Src: smtp X-4EC0790: 10 X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD97533543916A0F71AB5E10F7FD024E024A75B922889D28DA8CD62213F67905E7AF73E034330C1A39B4AF8F32ABE7E33665A180EB630036409DB077C1F076B10D7 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE700B5EAEB6F2DE1BDEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006376AEB812070489DF38638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8D6DED6CD4723601C8234FC52C18C1283117882F4460429724CE54428C33FAD305F5C1EE8F4F765FCECADA55FE5B58BB7A471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F446042972877693876707352033AC447995A7AD186FD1C55BDD38FC3FD2E47CDBA5A96583BA9C0B312567BB2376E601842F6C81A19E625A9149C048EE140C956E756FBB7A452896749CDDA0A6D8FC6C240DEA76429C9F4D5AE37F343AA9539A8B242431040A6AB1C7CE11FEE32A336C651863509103F1AB874ED89028C4224003CC836476E2F48590F00D11D6E2021AF6380DFAD1A18204E546F3947CD2DCF9CF1F528DBC2E808ACE2090B5E1725E5C173C3A84C3C5EA940A35A165FF2DBA43225CD8A89F890A246B268E114E6D8C47C27EEC5E9FB5C8C57E37DE458BEDA766A37F9254B7 X-C1DE0DAB: 0D63561A33F958A5D02297C2126F32B6B57FC875E17EDB895A203102514DED5DF87CCE6106E1FC07E67D4AC08A07B9B06A1CB4668A9CA5FACB5012B2E24CD356 X-C8649E89: 1C3962B70DF3F0ADE00A9FD3E00BEEDF3FED46C3ACD6F73ED3581295AF09D3DF87807E0823442EA2ED31085941D9CD0AF7F820E7B07EA4CFE19D5FCE08DF84F27233B851A1594886B8D430238CA2F3C8C55A19B990218709D1BAA24A4D7F85D861E41F2809366B386E2A7EA4D8C1A780D329D612C539354AA74DFFEFA5DC0E7F02C26D483E81D6BE5EF9655DD6DEA7D65774BB76CC95456EEC5B5AD62611EEC62B5AFB4261A09AF0 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojm/AwjadTR3Qe7rUT5wYatg== X-Mailru-Sender: 11C2EC085EDE56FAC07928AF2646A769CF1C8AEF86B7E9FEBB0E052AEC5AD6127962F9E9328436E1DEDBA653FF35249392D99EB8CC7091A70E183A470755BFD208F19895AA18418972D6B4FCE48DF648AE208404248635DF X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH luajit v2 6/6] profilers: print user-friendly errors 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 fixes! Please consider my comments below. On 06.12.23, Maxim Kokryashkin wrote: > --- > Makefile.original | 2 +- > .../gh-5688-tool-cli-flag.test.lua | 4 +- > ...17-profile-parsers-error-handling.test.lua | 90 +++++++++++++++++++ > tools/CMakeLists.txt | 4 + > tools/memprof.lua | 11 +-- > tools/sysprof.lua | 10 +-- > tools/sysprof/parse.lua | 2 +- > tools/utils/safe_event_reader.lua | 34 +++++++ > tools/utils/symtab.lua | 2 +- > 9 files changed, 144 insertions(+), 15 deletions(-) > create mode 100644 test/tarantool-tests/gh-9217-profile-parsers-error-handling.test.lua > create mode 100644 tools/utils/safe_event_reader.lua I suggest renaming to the so it will be match . > > diff --git a/Makefile.original b/Makefile.original > index 2a56d648..1ef6fbe6 100644 > --- a/Makefile.original > +++ b/Makefile.original > diff --git a/test/tarantool-tests/gh-5688-tool-cli-flag.test.lua b/test/tarantool-tests/gh-5688-tool-cli-flag.test.lua > index 75293f11..ec958031 100644 > --- a/test/tarantool-tests/gh-5688-tool-cli-flag.test.lua > +++ b/test/tarantool-tests/gh-5688-tool-cli-flag.test.lua > @@ -42,7 +42,7 @@ local SMOKE_CMD_SET = { > local MEMPROF_CMD_SET = { > { > cmd = MEMPROF_PARSER .. BAD_PATH, > - like = 'fopen, errno: 2', > + like = 'Failed to open', > }, > { > cmd = MEMPROF_PARSER .. TMP_BINFILE_MEMPROF, > @@ -61,7 +61,7 @@ local MEMPROF_CMD_SET = { > local SYSPROF_CMD_SET = { > { > cmd = SYSPROF_PARSER .. BAD_PATH, > - like = 'fopen, errno: 2', > + like = 'Failed to open', > }, > { > cmd = SYSPROF_PARSER .. TMP_BINFILE_SYSPROF, After adding the original error message, these changes appear not to be necessary. We can still add matching with updated error messages to the `fopen()` error too. Like the following: | like = 'Failed to open.*fopen, errno: 2' > diff --git a/test/tarantool-tests/gh-9217-profile-parsers-error-handling.test.lua b/test/tarantool-tests/gh-9217-profile-parsers-error-handling.test.lua > new file mode 100644 > index 00000000..c2e0f0a6 > --- /dev/null > +++ b/test/tarantool-tests/gh-9217-profile-parsers-error-handling.test.lua > diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt > index a4adc15b..7f728787 100644 > --- a/tools/CMakeLists.txt > +++ b/tools/CMakeLists.txt > diff --git a/tools/memprof.lua b/tools/memprof.lua > index 537cb869..d491b3dc 100644 > --- a/tools/memprof.lua > +++ b/tools/memprof.lua > diff --git a/tools/sysprof.lua b/tools/sysprof.lua > index 8449b23f..9c0c23c9 100644 > --- a/tools/sysprof.lua > +++ b/tools/sysprof.lua > diff --git a/tools/utils/safe_event_reader.lua b/tools/utils/safe_event_reader.lua > new file mode 100644 > index 00000000..39246a9d > --- /dev/null > +++ b/tools/utils/safe_event_reader.lua > @@ -0,0 +1,34 @@ > +local bufread = require('utils.bufread') > +local symtab = require('utils.symtab') > + > +local function make_error_handler(fmt, inputfile) > + return function(err) > + io.stderr:write(string.format(fmt, inputfile)) > + io.stderr:write(string.format('\nOriginal error: %s', err)) Typo: s/%s/%s\n/ > + os.exit(1, true) > + end For now the output is the following: | 14:09:05 jobs:0 burii@root:~/reviews/luajit/refactor-profilers$ | >>> LUA_PATH="src/?.lua;tools/?.lua;;" src/luajit -ts /tmp/memprof.bin | Failed to parse profile data from /tmp/memprof.bin. | Original error: tools/sysprof/parse.lua:240: Bad LJP format prologue: ljm14:30:50 jobs:0 burii@root:~/reviews/luajit/refactor-profilers$[1] | >>> I suppose the following format is more readable: | Failed to parse profile data from /tmp/memprof.bin: | tools/sysprof/parse.lua:240: Bad LJP format prologue: ljm The ident level is one tab. > +end > + > +local function safe_event_reader(parser, inputfile) > + local _, reader = xpcall( > + bufread.new, > + make_error_handler('Failed to open %s.', inputfile), > + inputfile > + ) > + > + local _, symbols = xpcall( > + symtab.parse, > + make_error_handler('Failed to parse symtab from %s.', inputfile), > + reader > + ) > + > + local _, events = xpcall( > + parser, > + make_error_handler('Failed to parse profile data from %s.', inputfile), > + reader, > + symbols > + ) > + return events, symbols > +end > + > +return safe_event_reader Nit: If we return this function at once, do we need to name it? Feel free to ignore. > diff --git a/tools/utils/symtab.lua b/tools/utils/symtab.lua > index 0c878e7a..c4aefef7 100644 > --- a/tools/utils/symtab.lua > +++ b/tools/utils/symtab.lua > -- > 2.43.0 > -- Best regards, Sergey Kaplun