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 C6102131B0A1; Wed, 5 Mar 2025 17:48:10 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org C6102131B0A1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1741186090; bh=irFT2vMyklr0Ok3iSB2daPSx3RT7/SA7goR78RhrLu8=; h=Date:To:Cc:References:In-Reply-To:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=LS3f2iK6fFHY4+nEFDUS7POG5le/WfARoBVEiybCiPtjNYvQkqy6OTDJff16c84QV WqibGCtPyN/D2+qW2iSAQR546HiXCiz1wLta06djnZsvU1IA7ZCZp/It4C/XfrtK3i dSsHvcWdkP0srfSXqbU9z2DNBCG+WRrrgwmmERts= Received: from send175.i.mail.ru (send175.i.mail.ru [95.163.59.14]) (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 DBA3D131B09F for ; Wed, 5 Mar 2025 17:48:09 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org DBA3D131B09F Received: by exim-smtp-8cb569c79-hlcnb with esmtpa (envelope-from ) id 1tpq2a-00000000FJO-2inf; Wed, 05 Mar 2025 17:48:09 +0300 Content-Type: multipart/alternative; boundary="------------0JSncoor9W0b1v2PFlqvzqxX" Message-ID: Date: Wed, 5 Mar 2025 17:48:03 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US To: Sergey Kaplun Cc: Sergey Bronnikov , tarantool-patches@dev.tarantool.org References: <881980705ead69f58c0474d5f49c00603e4c6e72.1740050074.git.sergeyb@tarantool.org> <52e2b52f-33a8-4f06-bcd8-ec8aa9fc457a@tarantool.org> In-Reply-To: X-Mailru-Src: smtp X-4EC0790: 10 X-7564579A: EEAE043A70213CC8 X-77F55803: 4F1203BC0FB41BD9D70A5F1A44F40AC4DEFAD4FC5E42960B3A3B94E6CA274DBF1313CFAB8367EF908E2BE116634AD74D47F3C7E36AFF9654411046492FDDF806B2107FEAFC059C5C9E43535646E756D131E418E160CADA48 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE742D9BD90C58D50E0EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637AC83A81C8FD4AD23D82A6BABE6F325AC2E85FA5F3EDFCBAA7353EFBB55337566AE3F01DD33DDBDC845BF07C30AABDDAC7607841E7351EFE6F765A9A6CF8263E3389733CBF5DBD5E913377AFFFEAFD269176DF2183F8FC7C07E7E81EEA8A9722B8941B15DA834481FCF19DD082D7633A0EF3E4896CB9E6436389733CBF5DBD5E9D5E8D9A59859A8B6D52CD31C43BF465FCC7F00164DA146DA6F5DAA56C3B73B237318B6A418E8EAB8D32BA5DBAC0009BE9E8FC8737B5C224958C1606C78F2434E76E601842F6C81A12EF20D2F80756B5FB606B96278B59C4276E601842F6C81A127C277FBC8AE2E8B6A4E49BB0F3BA1413AA81AA40904B5D99C9F4D5AE37F343AD1F44FA8B9022EA23BBE47FD9DD3FB595F5C1EE8F4F765FC72CEEB2601E22B093A03B725D353964B0B7D0EA88DDEDAC722CA9DD8327EE4930A3850AC1BE2E735DD0078234547CCE7C4224003CC83647689D4C264860C145E X-C1DE0DAB: 0D63561A33F958A50249E5E2BE9258135002B1117B3ED696E25EBAC1935705273D2BBC1EF78EDEBE823CB91A9FED034534781492E4B8EEAD3CCD70CEBBF18A22BDAD6C7F3747799A X-C8649E89: 1C3962B70DF3F0ADE00A9FD3E00BEEDF3FED46C3ACD6F73ED3581295AF09D3DF87807E0823442EA2ED31085941D9CD0AF7F820E7B07EA4CF0FC21B6B516D11202F1A20CCD461F4A60C53729A0B0F26158650B0D2BC7AC8423D7E4ABC8EFFEBBE2C10F42E4F22A8B6EE23D470759079476C00B302C45C6E9BA453D18A1A3785D65F4332CA8FE04980913E6812662D5F2AB9AF64DB4688768036DF5FE9C0001AF333F2C28C22F508233FCF178C6DD14203 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu53w8ahmwBjZKM/YPHZyZHvz5uv+WouB9+ObcCpyrx6l7KImUglyhkEat/+ysWwi0gdhEs0JGjl6ggRWTy1haxBpVdbIX1nthFXMZebaIdHP2ghjoIc/363UZI6Kf1ptIMVQiWK+2I7Y2sf4+n0qo3kDs= X-Mailru-Sender: 520A125C2F17F0B1E52FEF5D219D614047F3C7E36AFF9654411046492FDDF8063C403835C67B1F160152A3D17938EB451EB5A0BCEC6A560B3DDE9B364B0DF289BE2DA36745F2EEB5CEBA01FB949A1F1EEAB4BC95F72C04283CDA0F3B3F5B9367 X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH luajit 4/8][v3] sysprof: introduce specific errors and default mode 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 Bronnikov via Tarantool-patches Reply-To: Sergey Bronnikov Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" This is a multi-part message in MIME format. --------------0JSncoor9W0b1v2PFlqvzqxX Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Hi, Sergey, also added err_details to processing of PROFILE_ERRIO as discussed: diff --git a/src/lib_misc.c b/src/lib_misc.c index 79cfaf7b..83669268 100644 --- a/src/lib_misc.c +++ b/src/lib_misc.c @@ -267,6 +267,7 @@ static int parse_sysprof_opts(lua_State *L, struct luam_Sysprof_Options *opt,      status = set_output_path(path, opt);      if (status != PROFILE_SUCCESS) { +      *err_details = path;        lj_mem_free(ctx->g, ctx, sizeof(*ctx));        return status;      } @@ -293,7 +294,7 @@ static int sysprof_error(lua_State *L, int status, const char *err_details)        lua_pushinteger(L, EINVAL);        return 3;      case PROFILE_ERRIO: -      return luaL_fileresult(L, 0, NULL); +      return luaL_fileresult(L, 0, err_details);  #endif      default:        lj_assertL(0, "bad sysprof error %d", status); diff --git a/test/tarantool-tests/profilers/misclib-sysprof-lapi.test.lua b/test/tarantool-tests/profilers/misclib-sysprof-lapi.test.lua index 32ce75bc..9fa779a7 100644 --- a/test/tarantool-tests/profilers/misclib-sysprof-lapi.test.lua +++ b/test/tarantool-tests/profilers/misclib-sysprof-lapi.test.lua @@ -128,8 +128,9 @@ test:ok(type(errno) == "number", "errno with not running")  -- Bad path.  res, err, errno = misc.sysprof.start({ mode = "C", path = BAD_PATH }) -test:ok(res == nil and err:match("No such file or directory"), -        "result status and error with bad path") +test:ok(res == nil, "result status with bad path") +local error_msg = ("%s: No such file or directory"):format(BAD_PATH) +test:ok(err == error_msg, "error with bad path") test:ok(type(errno) == "number", "errno with bad path")  -- Path is not a string. On 05.03.2025 10:55, Sergey Kaplun wrote: > Hi, Sergey! > Thanks for the fixes! > LGTM, after fixing 3 minor nits below. > > On 24.02.25, Sergey Bronnikov wrote: >> Hi, Sergey, >> >> changes applied and force-pushed. >> >> Sergey >> >> On 24.02.2025 15:46, Sergey Kaplun via Tarantool-patches wrote: >>> Hi, Sergey! >>> Thanks for the fixes! >>> LGTM, after the final polishing, please consider my comments below. >>> >>> On 20.02.25, Sergey Bronnikov wrote: > > >>>> --- >>>> src/lib_misc.c | 77 ++++++++++++------- >>>> src/lj_errmsg.h | 5 ++ >>>> .../profilers/misclib-sysprof-lapi.test.lua | 68 ++++++++++++++-- >>>> 3 files changed, 114 insertions(+), 36 deletions(-) >>>> >>>> diff --git a/src/lib_misc.c b/src/lib_misc.c >>>> index 5b7a4b62..1fd06dd1 100644 >>>> --- a/src/lib_misc.c >>>> +++ b/src/lib_misc.c >>>> @@ -14,6 +14,7 @@ >>>> >>>> #include "lj_obj.h" >>>> #include "lj_str.h" >>>> +#include "lj_strfmt.h" >>> Please add the corresponding include (after lj_str.h) in to >>> avoid conflicts when we use this file (for crossbuilds or whatever). > There is no corresponding update on the branch. > > > >>>> -static int parse_sysprof_opts(lua_State *L, struct luam_Sysprof_Options *opt, int idx) { >>>> - GCtab *options = lj_lib_checktab(L, idx); >>>> +static int parse_sysprof_opts(lua_State *L, struct luam_Sysprof_Options *opt, >>>> + const char **err_details) { >>> Nit: Please, replace every 8 spaces with one tab. >> Fixed: >> >> --- a/src/lib_misc.c >> +++ b/src/lib_misc.c >> @@ -180,7 +180,7 @@ static int set_output_path(const char *path, struct >> luam_Sysprof_Options *opt) { >>  } >> >>  static int parse_sysprof_opts(lua_State *L, struct >> luam_Sysprof_Options *opt, >> -                             const char **err_details) { >> +                             const char **err_details) { > Thanks! > Please apply the following patch. It fixes all patchset-related places. > > =================================================================== > diff --git a/src/lib_misc.c b/src/lib_misc.c > index 94ec6564..79cfaf7b 100644 > --- a/src/lib_misc.c > +++ b/src/lib_misc.c > @@ -199,13 +199,13 @@ static int parse_sysprof_opts(lua_State *L, struct luam_Sysprof_Options *opt, > cTValue *mode_opt = lj_tab_getstr(options, lj_str_newlit(L, "mode")); > if (mode_opt) { > if (!tvisstr(mode_opt)) { > - *err_details = err2msg(LJ_ERR_PROF_DETAILS_BADMODE); > - return PROFILE_ERRUSE; > + *err_details = err2msg(LJ_ERR_PROF_DETAILS_BADMODE); > + return PROFILE_ERRUSE; > } > mode = strVdata(mode_opt); > if (strlen(mode) == 0 || mode[1] != '\0') { > - *err_details = err2msg(LJ_ERR_PROF_DETAILS_BADMODE); > - return PROFILE_ERRUSE; > + *err_details = err2msg(LJ_ERR_PROF_DETAILS_BADMODE); > + return PROFILE_ERRUSE; > } > } > > @@ -223,8 +223,8 @@ static int parse_sysprof_opts(lua_State *L, struct luam_Sysprof_Options *opt, > opt->mode = LUAM_SYSPROF_CALLGRAPH; > break; > default: > - *err_details = err2msg(LJ_ERR_PROF_DETAILS_BADMODE); > - return PROFILE_ERRUSE; > + *err_details = err2msg(LJ_ERR_PROF_DETAILS_BADMODE); > + return PROFILE_ERRUSE; > } > } > > @@ -235,8 +235,8 @@ static int parse_sysprof_opts(lua_State *L, struct luam_Sysprof_Options *opt, > if (interval && tvisnumber(interval)) { > int32_t signed_interval = numberVint(interval); > if (signed_interval < 1) { > - *err_details = err2msg(LJ_ERR_PROF_DETAILS_BADINTERVAL); > - return PROFILE_ERRUSE; > + *err_details = err2msg(LJ_ERR_PROF_DETAILS_BADINTERVAL); > + return PROFILE_ERRUSE; > } > opt->interval = signed_interval; > } > @@ -281,9 +281,9 @@ static int sysprof_error(lua_State *L, int status, const char *err_details) > case PROFILE_ERRUSE: > lua_pushnil(L); > if (err_details) > - lj_strfmt_pushf(L, "%s: %s", err2msg(LJ_ERR_PROF_MISUSE), err_details); > + lj_strfmt_pushf(L, "%s: %s", err2msg(LJ_ERR_PROF_MISUSE), err_details); > else > - lua_pushstring(L, err2msg(LJ_ERR_PROF_MISUSE)); > + lua_pushstring(L, err2msg(LJ_ERR_PROF_MISUSE)); > lua_pushinteger(L, EINVAL); > return 3; > #if LJ_HASSYSPROF > =================================================================== > >>    int n = (int)(L->top - L->base); > > >>>> +test:is(res, false, "res with not a table") >>>> +test:ok(err:match("table expected, got string"), >>>> + "error with not a table") >>>> +test:is(errno, nil, "errno with not a table") >>> There is no need to check or declare the `errno` variable. It's always >>> `nil` for the case when the error is raised. >> The check is cheap, why not? > This is kind of misleading, plus this is a dead check. It is __always__ > `nil`, or we will get an error in the first test and the second test. > Since we are not testing `pcall()` implementation here, let's just drop > it (it is even cheaper :)). > > > --------------0JSncoor9W0b1v2PFlqvzqxX Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit

Hi, Sergey,

also added err_details to processing of PROFILE_ERRIO as discussed:

diff --git a/src/lib_misc.c b/src/lib_misc.c
index 79cfaf7b..83669268 100644
--- a/src/lib_misc.c
+++ b/src/lib_misc.c
@@ -267,6 +267,7 @@ static int parse_sysprof_opts(lua_State *L, struct luam_Sysprof_Options *opt,
 
     status = set_output_path(path, opt);
     if (status != PROFILE_SUCCESS) {
+      *err_details = path;
       lj_mem_free(ctx->g, ctx, sizeof(*ctx));
       return status;
     }
@@ -293,7 +294,7 @@ static int sysprof_error(lua_State *L, int status, const char *err_details)
       lua_pushinteger(L, EINVAL);
       return 3;
     case PROFILE_ERRIO:
-      return luaL_fileresult(L, 0, NULL);
+      return luaL_fileresult(L, 0, err_details);
 #endif
     default:
       lj_assertL(0, "bad sysprof error %d", status);
diff --git a/test/tarantool-tests/profilers/misclib-sysprof-lapi.test.lua b/test/tarantool-tests/profilers/misclib-sysprof-lapi.test.lua
index 32ce75bc..9fa779a7 100644
--- a/test/tarantool-tests/profilers/misclib-sysprof-lapi.test.lua
+++ b/test/tarantool-tests/profilers/misclib-sysprof-lapi.test.lua
@@ -128,8 +128,9 @@ test:ok(type(errno) == "number", "errno with not running")
 
 -- Bad path.
 res, err, errno = misc.sysprof.start({ mode = "C", path = BAD_PATH })
-test:ok(res == nil and err:match("No such file or directory"),
-        "result status and error with bad path")
+test:ok(res == nil, "result status with bad path")
+local error_msg = ("%s: No such file or directory"):format(BAD_PATH)
+test:ok(err == error_msg, "error with bad path")
 test:ok(type(errno) == "number", "errno with bad path")
 
 -- Path is not a string.

On 05.03.2025 10:55, Sergey Kaplun wrote:
Hi, Sergey!
Thanks for the fixes!
LGTM, after fixing 3 minor nits below.

On 24.02.25, Sergey Bronnikov wrote:
Hi, Sergey,

changes applied and force-pushed.

Sergey

On 24.02.2025 15:46, Sergey Kaplun via Tarantool-patches wrote:
Hi, Sergey!
Thanks for the fixes!
LGTM, after the final polishing, please consider my comments below.

On 20.02.25, Sergey Bronnikov wrote:
<snipped>

---
  src/lib_misc.c                                | 77 ++++++++++++-------
  src/lj_errmsg.h                               |  5 ++
  .../profilers/misclib-sysprof-lapi.test.lua   | 68 ++++++++++++++--
  3 files changed, 114 insertions(+), 36 deletions(-)

diff --git a/src/lib_misc.c b/src/lib_misc.c
index 5b7a4b62..1fd06dd1 100644
--- a/src/lib_misc.c
+++ b/src/lib_misc.c
@@ -14,6 +14,7 @@
  
  #include "lj_obj.h"
  #include "lj_str.h"
+#include "lj_strfmt.h"
Please add the corresponding include (after lj_str.h) in <src/Makefile.dep.original> to
avoid conflicts when we use this file (for crossbuilds or whatever).
There is no corresponding update on the branch.


        
<snipped>

-static int parse_sysprof_opts(lua_State *L, struct luam_Sysprof_Options *opt, int idx) {
-  GCtab *options = lj_lib_checktab(L, idx);
+static int parse_sysprof_opts(lua_State *L, struct luam_Sysprof_Options *opt,
+	                      const char **err_details) {
Nit: Please, replace every 8 spaces with one tab.
Fixed:

--- a/src/lib_misc.c
+++ b/src/lib_misc.c
@@ -180,7 +180,7 @@ static int set_output_path(const char *path, struct 
luam_Sysprof_Options *opt) {
  }

  static int parse_sysprof_opts(lua_State *L, struct 
luam_Sysprof_Options *opt,
-                             const char **err_details) {
+                             const char **err_details) {
Thanks!
Please apply the following patch. It fixes all patchset-related places.

===================================================================
diff --git a/src/lib_misc.c b/src/lib_misc.c
index 94ec6564..79cfaf7b 100644
--- a/src/lib_misc.c
+++ b/src/lib_misc.c
@@ -199,13 +199,13 @@ static int parse_sysprof_opts(lua_State *L, struct luam_Sysprof_Options *opt,
     cTValue *mode_opt = lj_tab_getstr(options, lj_str_newlit(L, "mode"));
     if (mode_opt) {
       if (!tvisstr(mode_opt)) {
-        *err_details = err2msg(LJ_ERR_PROF_DETAILS_BADMODE);
-        return PROFILE_ERRUSE;
+	*err_details = err2msg(LJ_ERR_PROF_DETAILS_BADMODE);
+	return PROFILE_ERRUSE;
       }
       mode = strVdata(mode_opt);
       if (strlen(mode) == 0 || mode[1] != '\0') {
-        *err_details = err2msg(LJ_ERR_PROF_DETAILS_BADMODE);
-        return PROFILE_ERRUSE;
+	*err_details = err2msg(LJ_ERR_PROF_DETAILS_BADMODE);
+	return PROFILE_ERRUSE;
       }
     }
 
@@ -223,8 +223,8 @@ static int parse_sysprof_opts(lua_State *L, struct luam_Sysprof_Options *opt,
         opt->mode = LUAM_SYSPROF_CALLGRAPH;
         break;
       default:
-        *err_details = err2msg(LJ_ERR_PROF_DETAILS_BADMODE);
-        return PROFILE_ERRUSE;
+	*err_details = err2msg(LJ_ERR_PROF_DETAILS_BADMODE);
+	return PROFILE_ERRUSE;
     }
   }
 
@@ -235,8 +235,8 @@ static int parse_sysprof_opts(lua_State *L, struct luam_Sysprof_Options *opt,
     if (interval && tvisnumber(interval)) {
       int32_t signed_interval = numberVint(interval);
       if (signed_interval < 1) {
-        *err_details = err2msg(LJ_ERR_PROF_DETAILS_BADINTERVAL);
-        return PROFILE_ERRUSE;
+	*err_details = err2msg(LJ_ERR_PROF_DETAILS_BADINTERVAL);
+	return PROFILE_ERRUSE;
       }
       opt->interval = signed_interval;
     }
@@ -281,9 +281,9 @@ static int sysprof_error(lua_State *L, int status, const char *err_details)
     case PROFILE_ERRUSE:
       lua_pushnil(L);
       if (err_details)
-        lj_strfmt_pushf(L, "%s: %s", err2msg(LJ_ERR_PROF_MISUSE), err_details);
+	lj_strfmt_pushf(L, "%s: %s", err2msg(LJ_ERR_PROF_MISUSE), err_details);
       else
-        lua_pushstring(L, err2msg(LJ_ERR_PROF_MISUSE));
+	lua_pushstring(L, err2msg(LJ_ERR_PROF_MISUSE));
       lua_pushinteger(L, EINVAL);
       return 3;
 #if LJ_HASSYSPROF
===================================================================

    int n = (int)(L->top - L->base);
<snipped>

+test:is(res, false, "res with not a table")
+test:ok(err:match("table expected, got string"),
+        "error with not a table")
+test:is(errno, nil, "errno with not a table")
There is no need to check or declare the `errno` variable. It's always
`nil` for the case when the error is raised.
The check is cheap, why not?
This is kind of misleading, plus this is a dead check. It is __always__
`nil`, or we will get an error in the first test and the second test.
Since we are not testing `pcall()` implementation here, let's just drop
it (it is even cheaper :)).

<snipped>

--------------0JSncoor9W0b1v2PFlqvzqxX--