Skip to content

Commit

Permalink
sysprof: disable proto and trace dumps in default
Browse files Browse the repository at this point in the history
There is no need to dump proto or trace information for sysprof
in the default mode. Moreover, attempts to do so will lead to
segmentation fault due to uninitialized buffer. This commit
disables proto and trace dumps in the default mode.

Resolves tarantool/tarantool#7264

Reviewed-by: Sergey Kaplun <skaplun@tarantool.org>
Reviewed-by: Igor Munkin <imun@tarantool.org>
Signed-off-by: Igor Munkin <imun@tarantool.org>
  • Loading branch information
mkokryashkin authored and igormunkin committed Jul 15, 2022
1 parent 36b4b80 commit 1019a57
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/lj_sysprof.c
Expand Up @@ -524,7 +524,7 @@ void lj_sysprof_add_proto(const struct GCproto *pt)
{
struct sysprof *sp = &sysprof;

if (sp->state != SPS_PROFILE)
if (sp->state != SPS_PROFILE || sp->opt.mode == LUAM_SYSPROF_DEFAULT)
return;

/*
Expand All @@ -543,7 +543,7 @@ void lj_sysprof_add_trace(const struct GCtrace *tr)
{
struct sysprof *sp = &sysprof;

if (sp->state != SPS_PROFILE)
if (sp->state != SPS_PROFILE || sp->opt.mode == LUAM_SYSPROF_DEFAULT)
return;

/* See the comment about the sysprof state above. */
Expand Down
@@ -0,0 +1,49 @@
-- Sysprof is implemented for x86 and x64 architectures only.
require('utils').skipcond(
jit.arch ~= 'x86' and jit.arch ~= 'x64' or jit.os ~= 'Linux'
or require('ffi').abi('gc64'),
jit.arch..' architecture or '..jit.os..
' OS is NIY for sysprof'
)

local tap = require('tap')
local test = tap.test('gh-7264-add-proto-trace-sysprof-default.test.lua')
test:plan(2)

local chunk = [[
return function()
local a = 'teststring'
end
]]

local function allocate()
local a = {}
for _ = 1, 3 do
table.insert(a, 'teststring')
end
return a
end

-- Proto creation during the sysprof runtime.
jit.off()

assert(misc.sysprof.start({ mode = 'D' }))
-- The first call yields the anonymous function created by loading
-- <chunk> proto. As a result the child proto function is yielded.
-- The second call invokes the child proto function to trigger
-- <lj_sysprof_add_proto> call.
assert(load(chunk))()()
test:ok(misc.sysprof.stop(), 'new proto in sysprof runtime')

-- Trace creation during the sysprof runtime.
jit.flush()
jit.opt.start('hotloop=1')
jit.on()

assert(misc.sysprof.start({ mode = 'D' }))
-- Run <allocate> function to record a new trace. As a result,
-- <lj_sysprof_add_trace> is triggered to be invoked.
allocate()
test:ok(misc.sysprof.stop(), 'trace record in sysprof runtime')

os.exit(test:check() and 0 or 1)

0 comments on commit 1019a57

Please sign in to comment.