Skip to content

Commit

Permalink
sysprof: fix a message with stop without run
Browse files Browse the repository at this point in the history
The function `misc.sysprof.stop()` reports that profiler is
already running:

| $ ./src/luajit -e 'print(misc.sysprof.stop())'
| nil     profiler is running already     22

both in `sysprof_error()` and fixes aforementioned problem.

Follows up tarantool/tarantool#781
  • Loading branch information
ligurio committed Feb 25, 2025
1 parent a8f0bf7 commit a9e1dbe
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/lib_misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,12 @@ LJLIB_CF(misc_sysprof_stop)
return sysprof_error(L, PROFILE_ERRUSE, err_details);
#else
int status = luaM_sysprof_stop(L);
if (LJ_UNLIKELY(status == PROFILE_ERRRUN)) {
lua_pushnil(L);
lua_pushstring(L, err2msg(LJ_ERR_PROF_NOTRUNNING));
lua_pushinteger(L, EINVAL);
return 3;
}
if (LJ_UNLIKELY(status != PROFILE_SUCCESS))
return prof_error(L, status, NULL);

Expand Down
3 changes: 2 additions & 1 deletion test/tarantool-tests/profilers/misclib-sysprof-lapi.test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,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 a9e1dbe

Please sign in to comment.