diff --git a/src/lua/fiber.c b/src/lua/fiber.c index f6abfdbd2a9a3f57d53174127042b42f27549a5a..fdbd8fa4c243dd49748cd2f824d94fa6c638ca20 100644 --- a/src/lua/fiber.c +++ b/src/lua/fiber.c @@ -197,7 +197,7 @@ fiber_backtrace_cb(int frameno, void *frameret, const char *func, size_t offset, #endif static int -lbox_fiber_statof(struct fiber *f, void *cb_ctx) +lbox_fiber_statof(struct fiber *f, void *cb_ctx, bool backtrace) { struct lua_State *L = (struct lua_State *) cb_ctx; @@ -227,26 +227,52 @@ lbox_fiber_statof(struct fiber *f, void *cb_ctx) lua_settable(L, -3); lua_settable(L, -3); + if (backtrace) { #ifdef ENABLE_BACKTRACE - lua_pushstring(L, "backtrace"); - lua_newtable(L); - if (f != fiber()) - backtrace_foreach(fiber_backtrace_cb, &f->ctx, L); - lua_settable(L, -3); + lua_pushstring(L, "backtrace"); + lua_newtable(L); + if (f != fiber()) + backtrace_foreach(fiber_backtrace_cb, &f->ctx, L); + lua_settable(L, -3); #endif /* ENABLE_BACKTRACE */ - + } lua_settable(L, -3); return 0; } +static int +lbox_fiber_statof_bt(struct fiber *f, void *cb_ctx) +{ + return lbox_fiber_statof(f, cb_ctx, true); +} + +static int +lbox_fiber_statof_nobt(struct fiber *f, void *cb_ctx) +{ + return lbox_fiber_statof(f, cb_ctx, false); +} + /** * Return fiber statistics. */ static int lbox_fiber_info(struct lua_State *L) { + bool do_backtrace = true; + if (lua_istable(L, 1)) { + lua_pushstring(L, "backtrace"); + lua_gettable(L, 1); + if (lua_isnil(L, -1)){ + lua_pop(L, 1); + lua_pushstring(L, "bt"); + lua_gettable(L, 1); + } + if (!lua_isnil(L, -1)) + do_backtrace = lua_toboolean(L, -1); + lua_pop(L, 1); + } lua_newtable(L); - fiber_stat(lbox_fiber_statof, L); + fiber_stat(do_backtrace ? lbox_fiber_statof_bt : lbox_fiber_statof_nobt, L); lua_createtable(L, 0, 1); lua_pushliteral(L, "mapping"); /* YAML will use block mode */ lua_setfield(L, -2, LUAL_SERIALIZE); diff --git a/test/app/fiber.result b/test/app/fiber.result index 699bf3d740b73388e336a93798e8a5ea4875b57f..08d38ef7be4c44e003e94d81d55d1218cc1033dc 100644 --- a/test/app/fiber.result +++ b/test/app/fiber.result @@ -826,6 +826,20 @@ info[f3:id()] ~= nil --- - true ... +info = fiber.info({bt = false}) +--- +... +info[f1:id()].backtrace == nil +--- +- true +... +info = fiber.info({backtrace = false}) +--- +... +info[f1:id()].backtrace == nil +--- +- true +... f1:cancel() --- ... diff --git a/test/app/fiber.test.lua b/test/app/fiber.test.lua index e9da622d2d7dc58e78e2d2a9083b04f5eb20debe..ad3da0991623853150c4909d07c9610a98eb2f66 100644 --- a/test/app/fiber.test.lua +++ b/test/app/fiber.test.lua @@ -325,6 +325,11 @@ info[f1:id()] ~= nil info[f2:id()] ~= nil info[f3:id()] ~= nil +info = fiber.info({bt = false}) +info[f1:id()].backtrace == nil +info = fiber.info({backtrace = false}) +info[f1:id()].backtrace == nil + f1:cancel() f2:cancel() f3:cancel()