From 441405c398d625fda304b16bb10f119bfd822696 Mon Sep 17 00:00:00 2001 From: Sergey Bronnikov Date: Tue, 4 Feb 2025 11:48:05 +0300 Subject: [PATCH] sysprof: fix a message with stop without run When sysprof is not started, the function `misc.sysprof.stop()` reports that the profiler is already running: | $ ./src/luajit -e 'print(misc.sysprof.stop())' | nil profiler is running already 22 The patch fixes that: | $ ./src/luajit -e 'print(misc.sysprof.stop())' | nil profiler is not running 22 Follows up tarantool/tarantool#781 Reviewed-by: Sergey Kaplun Signed-off-by: Sergey Kaplun --- src/lib_misc.c | 8 +++++++- .../profilers/misclib-sysprof-lapi.test.lua | 5 +++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/lib_misc.c b/src/lib_misc.c index 1c81fd8099..034ff87851 100644 --- a/src/lib_misc.c +++ b/src/lib_misc.c @@ -336,8 +336,14 @@ LJLIB_CF(misc_sysprof_stop) return prof_error(L, PROFILE_ERRUSE, err_details); #else int status = luaM_sysprof_stop(L); - if (LJ_UNLIKELY(status != PROFILE_SUCCESS)) + if (LJ_UNLIKELY(status == PROFILE_ERRRUN)) { + lua_pushnil(L); + lua_pushstring(L, err2msg(LJ_ERR_PROF_NOTRUNNING)); + lua_pushinteger(L, EINVAL); + return 3; + } else if (LJ_UNLIKELY(status != PROFILE_SUCCESS)) { return prof_error(L, status, NULL); + } lua_pushboolean(L, 1); return 1; diff --git a/test/tarantool-tests/profilers/misclib-sysprof-lapi.test.lua b/test/tarantool-tests/profilers/misclib-sysprof-lapi.test.lua index 91ea461bfa..f316c39078 100644 --- a/test/tarantool-tests/profilers/misclib-sysprof-lapi.test.lua +++ b/test/tarantool-tests/profilers/misclib-sysprof-lapi.test.lua @@ -10,7 +10,7 @@ local test = tap.test("misclib-sysprof-lapi"):skipcond({ ["Disabled due to #10803"] = os.getenv("LUAJIT_TEST_USE_VALGRIND"), }) -test:plan(43) +test:plan(44) jit.off() -- XXX: Run JIT tuning functions in a safe frame to avoid errors @@ -123,7 +123,8 @@ assert(res, err) -- Not running. res, err, errno = misc.sysprof.stop() -test:ok(res == nil and err, "result status and error with not running") +test:is(res, nil, "result status with not running") +test:ok(err:match("profiler is not running"), "error with not running") test:ok(type(errno) == "number", "errno with not running") -- Bad path.