Skip to content

Commit 54e7338

Browse files
ligurioBuristan
authored andcommitted
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 <skaplun@tarantool.org> Signed-off-by: Sergey Kaplun <skaplun@tarantool.org> (cherry picked from commit 441405c)
1 parent b3338d8 commit 54e7338

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

src/lib_misc.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,8 +336,14 @@ LJLIB_CF(misc_sysprof_stop)
336336
return prof_error(L, PROFILE_ERRUSE, err_details);
337337
#else
338338
int status = luaM_sysprof_stop(L);
339-
if (LJ_UNLIKELY(status != PROFILE_SUCCESS))
339+
if (LJ_UNLIKELY(status == PROFILE_ERRRUN)) {
340+
lua_pushnil(L);
341+
lua_pushstring(L, err2msg(LJ_ERR_PROF_NOTRUNNING));
342+
lua_pushinteger(L, EINVAL);
343+
return 3;
344+
} else if (LJ_UNLIKELY(status != PROFILE_SUCCESS)) {
340345
return prof_error(L, status, NULL);
346+
}
341347

342348
lua_pushboolean(L, 1);
343349
return 1;

test/tarantool-tests/profilers/misclib-sysprof-lapi.test.lua

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ local test = tap.test("misclib-sysprof-lapi"):skipcond({
1010
["Disabled due to #10803"] = os.getenv("LUAJIT_TEST_USE_VALGRIND"),
1111
})
1212

13-
test:plan(43)
13+
test:plan(44)
1414

1515
jit.off()
1616
-- XXX: Run JIT tuning functions in a safe frame to avoid errors
@@ -123,7 +123,8 @@ assert(res, err)
123123

124124
-- Not running.
125125
res, err, errno = misc.sysprof.stop()
126-
test:ok(res == nil and err, "result status and error with not running")
126+
test:is(res, nil, "result status with not running")
127+
test:ok(err:match("profiler is not running"), "error with not running")
127128
test:ok(type(errno) == "number", "errno with not running")
128129

129130
-- Bad path.

0 commit comments

Comments
 (0)