Skip to content

Commit 20eef3f

Browse files
ligurioBuristan
authored andcommitted
sysprof: allow calling sysprof.report before stop
It is not allowed to call a function `sysprof.report()` without stopping the profiler. However, sometimes it may be useful to analyze numbers provided by the report without stopping the profiler. The patch removes the appropriate condition and allows reporting without stopping. Resolves tarantool/tarantool#11229 Reviewed-by: Sergey Kaplun <[email protected]> Signed-off-by: Sergey Kaplun <[email protected]> (cherry picked from commit c619bda)
1 parent 2fd8699 commit 20eef3f

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

src/lj_sysprof.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -532,8 +532,6 @@ int lj_sysprof_stop(lua_State *L)
532532
int lj_sysprof_report(struct luam_Sysprof_Counters *counters)
533533
{
534534
const struct sysprof *sp = &sysprof;
535-
if (sp->state != SPS_IDLE)
536-
return PROFILE_ERRUSE;
537535
memcpy(counters, &sp->counters, sizeof(sp->counters));
538536
return PROFILE_SUCCESS;
539537
}

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

Lines changed: 17 additions & 2 deletions
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(44)
13+
test:plan(45)
1414

1515
jit.off()
1616
-- XXX: Run JIT tuning functions in a safe frame to avoid errors
@@ -166,13 +166,28 @@ test:is(err, nil, "no error with good interval 1")
166166
test:is(errno, nil, "no errno with good interval 1")
167167
misc.sysprof.stop()
168168

169+
-- Intermediate sysprof.report().
170+
assert(misc.sysprof.start({
171+
mode = "D",
172+
interval = 1,
173+
path = "/dev/null",
174+
}))
175+
176+
payload()
177+
178+
local report = misc.sysprof.report()
179+
-- Check the profile is not empty.
180+
test:ok(report.samples > 0,
181+
"number of samples is greater than 0 for the default payload")
182+
assert(misc.sysprof.stop())
183+
169184
-- DEFAULT MODE
170185

171186
if not pcall(generate_output, { mode = "D", interval = 100 }) then
172187
test:fail('`default` mode with interval 100')
173188
end
174189

175-
local report = misc.sysprof.report()
190+
report = misc.sysprof.report()
176191

177192
-- Check the profile is not empty.
178193
test:ok(report.samples > 0,

0 commit comments

Comments
 (0)