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 sets a path to
the profiling output file. By default, the path is `sysprof.bin`.
`misc.memprof.start()` requires setting a path to the profiling
output file. The patch fixes this inconsistency by introducing a
default path to the memprof profiling output file - `memprof.bin`.
  • Loading branch information
ligurio committed Mar 6, 2025
1 parent a103caf commit 9bc9530
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/lib_misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,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 @@ -395,7 +397,8 @@ LJLIB_CF(misc_memprof_start)
return sysprof_error(L, PROFILE_ERRUSE, err_details);
#else
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
local tap = require('tap')
local test = tap.test('misc-memprof-lapi-default-file'):skipcond({
['Memprof is implemented for x86_64 only'] = jit.arch ~= 'x86' and
jit.arch ~= 'x64',
['Memprof is disabled'] = os.getenv('LUAJIT_DISABLE_MEMPROF'),
})

test:plan(1)

local tools = require('utils.tools')

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

subtest:plan(1)

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

local res, err = misc.memprof.start()
-- Want to cleanup carefully if something went wrong.
if not res then
test:fail('sysprof was not started: ' .. err)
os.remove(default_output_file)
end

res, err = misc.memprof.stop()
-- Want to cleanup carefully if something went wrong.
if not res then
test:fail('sysprof was not stopped: ' .. err)
os.remove(default_output_file)
end


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

-- We don't need it anymore.
os.remove(default_output_file)
end)

test:done(true)

0 comments on commit 9bc9530

Please sign in to comment.