Skip to content

Commit

Permalink
sysprof: fix a message with stop without run
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ligurio committed Mar 7, 2025
1 parent 014847f commit c59c710
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
8 changes: 7 additions & 1 deletion src/lib_misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 3 additions & 2 deletions test/tarantool-tests/profilers/misclib-sysprof-lapi.test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit c59c710

Please sign in to comment.