Skip to content

Commit d489b40

Browse files
committed
misc: introduce flags with profiler support status
The patch introduce flags in module "misc" with support status for sysprof and memprof: `misc.sysprof.available` and `misc.memprof.available`. Both flags are boolean and always available on platforms supported by profilers (Windows is not supported). Resolves tarantool/tarantool#12215
1 parent 3ed650f commit d489b40

File tree

5 files changed

+26
-4
lines changed

5 files changed

+26
-4
lines changed

src/lib_misc.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,8 @@ LJLIB_CF(misc_sysprof_report)
389389
#endif /* !LJ_HASSYSPROF */
390390
}
391391

392+
LJLIB_PUSH(top-2) LJLIB_SET(available)
393+
392394
/* ----- misc.memprof module ---------------------------------------------- */
393395

394396
#define LJLIB_MODULE_misc_memprof
@@ -459,6 +461,8 @@ LJLIB_CF(misc_memprof_stop)
459461
}
460462
#endif /* !LJ_TARGET_WINDOWS */
461463

464+
LJLIB_PUSH(top-2) LJLIB_SET(available)
465+
462466
#include "lj_libdef.h"
463467

464468
/* ------------------------------------------------------------------------ */
@@ -477,7 +481,9 @@ LUALIB_API int luaopen_misc(struct lua_State *L)
477481

478482
LJ_LIB_REG(L, LUAM_MISCLIBNAME, misc);
479483
#if !LJ_TARGET_WINDOWS
484+
lua_pushboolean(L, LJ_HASMEMPROF);
480485
LJ_LIB_REG(L, LUAM_MISCLIBNAME ".memprof", misc_memprof);
486+
lua_pushboolean(L, LJ_HASSYSPROF);
481487
LJ_LIB_REG(L, LUAM_MISCLIBNAME ".sysprof", misc_sysprof);
482488
#endif /* !LJ_TARGET_WINDOWS */
483489
return 1;

test/tarantool-tests/profilers/misclib-memprof-lapi-disabled.test.lua

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ local test = tap.test('misclib-memprof-lapi-disabled'):skipcond({
33
['Memprof is enabled'] = not os.getenv('LUAJIT_DISABLE_MEMPROF'),
44
})
55

6-
test:plan(6)
6+
test:plan(8)
77

88
-- Attempt to start memprof when it is disabled.
99
local res, err, errno = misc.memprof.start()
@@ -19,4 +19,8 @@ test:ok(err:match('profiler is disabled'),
1919
'error on stop when memprof is disabled')
2020
test:ok(type(errno) == 'number', 'errno on start when memprof is disabled')
2121

22+
test:ok(type(misc.memprof.available) == 'boolean',
23+
'misc.memprof.available exists')
24+
test:ok(misc.memprof.available == false, 'misc.memprof.available is false')
25+
2226
test:done(true)

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ local test = tap.test("misclib-memprof-lapi"):skipcond({
1111
["Memprof is disabled"] = os.getenv("LUAJIT_DISABLE_MEMPROF"),
1212
})
1313

14-
test:plan(5)
14+
test:plan(7)
1515

1616
local jit_opt_default = {
1717
3, -- level
@@ -270,4 +270,8 @@ test:test("jit-output", function(subtest)
270270
jit.opt.start(unpack(jit_opt_default))
271271
end)
272272

273+
test:ok(type(misc.memprof.available) == 'boolean',
274+
'misc.memprof.available exists')
275+
test:ok(misc.memprof.available == true, 'misc.memprof.available is true')
276+
273277
test:done(true)

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ local test = tap.test('misclib-sysprof-lapi-disabled'):skipcond({
33
['Sysprof is enabled'] = not os.getenv('LUAJIT_DISABLE_SYSPROF'),
44
})
55

6-
test:plan(9)
6+
test:plan(11)
77

88
-- Attempt to start sysprof when sysprof is disabled.
99
local res, err, errno = misc.sysprof.start()
@@ -26,4 +26,8 @@ test:ok(err:match('profiler is disabled'),
2626
'error on stop when sysprof is disabled')
2727
test:ok(type(errno) == 'number', 'errno on start when sysprof is disabled')
2828

29+
test:ok(type(misc.sysprof.available) == 'boolean',
30+
'misc.sysprof.available exists')
31+
test:ok(misc.sysprof.available == false, 'misc.sysprof.available is false')
32+
2933
test:done(true)

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

Lines changed: 5 additions & 1 deletion
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(45)
13+
test:plan(47)
1414

1515
jit.off()
1616
-- XXX: Run JIT tuning functions in a safe frame to avoid errors
@@ -228,4 +228,8 @@ check_mode("C", 100)
228228

229229
os.remove(TMP_BINFILE)
230230

231+
test:ok(type(misc.sysprof.available) == 'boolean',
232+
'misc.sysprof.available exists')
233+
test:ok(misc.sysprof.available == true, 'misc.sysprof.available is true')
234+
231235
test:done(true)

0 commit comments

Comments
 (0)