Skip to content

Commit

Permalink
memprof: set default path to profiling output file
Browse files Browse the repository at this point in the history
sysprof has an optional parameter `path`, that set a path to
profiling output file, by default the path is `sysprof.bin`.
`misc.memprof.start()` requires to set a path to profiling output
file. The patch fixes this inconsistency by introducing a default
path to memprof profiling output file - `memprof.bin`.
  • Loading branch information
ligurio committed Feb 13, 2025
1 parent b4770a8 commit 219a2bb
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/lib_misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,8 @@ LJLIB_CF(misc_sysprof_report)

#define LJLIB_MODULE_misc_memprof

#define MEMPROF_DEFAULT_OUTPUT "memprof.bin"

/* local started, err, errno = misc.memprof.start(fname) */
LJLIB_CF(misc_memprof_start)
{
Expand All @@ -407,7 +409,8 @@ LJLIB_CF(misc_memprof_start)
return sysprof_error(L, PROFILE_ERRUSE, err_details);
#endif /* !LJ_HASMEMPROF */
struct lj_memprof_options opt = {0};
const char *fname = strdata(lj_lib_checkstr(L, 1));
GCstr *s = lj_lib_optstr(L, 1);
const char *fname = s ? strdata(s) : MEMPROF_DEFAULT_OUTPUT;
struct profile_ctx *ctx;
int memprof_status;

Expand Down
32 changes: 31 additions & 1 deletion test/tarantool-tests/profilers/misclib-memprof-lapi.test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ local test = tap.test("misc-memprof-lapi"):skipcond({
["Disabled due to LuaJIT/LuaJIT#606"] = os.getenv("LUAJIT_TABLE_BUMP"),
})

test:plan(5)
test:plan(6)

local jit_opt_default = {
3, -- level
Expand All @@ -28,6 +28,7 @@ local bufread = require "utils.bufread"
local memprof = require "memprof.parse"
local process = require "memprof.process"
local symtab = require "utils.symtab"
local tools = require "utils.tools"
local profilename = require("utils").tools.profilename

local TMP_BINFILE = profilename("memprofdata.tmp.bin")
Expand Down Expand Up @@ -269,4 +270,33 @@ test:test("jit-output", function(subtest)
jit.opt.start(unpack(jit_opt_default))
end)

test:test("default-output-file", function(subtest)

subtest:plan(1)

local def_output_file = 'memprof.bin'
os.remove(def_output_file)

jit.opt.start(3, "hotloop=10")
jit.flush()

local res, err = pcall(generate_output, nil, default_payload)

-- Want to cleanup carefully if something went wrong.
if not res then
os.remove(def_output_file)
error(err)
end

local profile_buf = tools.read_file(def_output_file)
subtest:ok(profile_buf ~= nil and #profile_buf ~= 0,
'default output file is not empty')

-- We don't need it any more.
os.remove(def_output_file)

-- Restore default JIT settings.
jit.opt.start(unpack(jit_opt_default))
end)

test:done(true)

0 comments on commit 219a2bb

Please sign in to comment.