[Tarantool-patches] [PATCH luajit 7/7] memprof: set default path to profiling output file

Sergey Bronnikov estetus at gmail.com
Thu Feb 13 14:10:51 MSK 2025


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`.
---
 src/lib_misc.c                                |  5 ++-
 ...misclib-memprof-lapi-default-file.test.lua | 41 +++++++++++++++++++
 2 files changed, 45 insertions(+), 1 deletion(-)
 create mode 100644 test/tarantool-tests/profilers/misclib-memprof-lapi-default-file.test.lua

diff --git a/src/lib_misc.c b/src/lib_misc.c
index 7666d85f..4f5d72fc 100644
--- a/src/lib_misc.c
+++ b/src/lib_misc.c
@@ -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)
 {
@@ -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;
 
diff --git a/test/tarantool-tests/profilers/misclib-memprof-lapi-default-file.test.lua b/test/tarantool-tests/profilers/misclib-memprof-lapi-default-file.test.lua
new file mode 100644
index 00000000..b6233d4a
--- /dev/null
+++ b/test/tarantool-tests/profilers/misclib-memprof-lapi-default-file.test.lua
@@ -0,0 +1,41 @@
+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 def_output_file = 'memprof.bin'
+  os.remove(def_output_file)
+
+  local res, err = misc.memprof.start()
+  -- Should start successfully.
+  assert(res, err)
+
+  res, err = misc.memprof.stop()
+  -- Should stop successfully.
+  assert(res, err)
+
+  -- 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)
+end)
+
+test:done(true)
-- 
2.34.1



More information about the Tarantool-patches mailing list