Tarantool development patches archive
 help / color / mirror / Atom feed
From: Sergey Bronnikov via Tarantool-patches <tarantool-patches@dev.tarantool.org>
To: tarantool-patches@dev.tarantool.org,
	Sergey Kaplun <skaplun@tarantool.org>,
	sergos@tarantool.org
Subject: [Tarantool-patches] [PATCH luajit 8/8][v3] memprof: set default path to profiling output file
Date: Thu, 20 Feb 2025 14:21:56 +0300	[thread overview]
Message-ID: <e33751601ee37fe00dd4be7900437c37a3f3e97c.1740050074.git.sergeyb@tarantool.org> (raw)
In-Reply-To: <cover.1740050074.git.sergeyb@tarantool.org>

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 to set a path to profiling output
file. The patch fixes this inconsistency by introducing a default
path to the memprof profiling output file - `memprof.bin`.
---
 src/lib_misc.c                                |  5 ++-
 ...misclib-memprof-lapi-default-file.test.lua | 37 +++++++++++++++++++
 2 files changed, 41 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 d98cf3f0..92dc6e2a 100644
--- a/src/lib_misc.c
+++ b/src/lib_misc.c
@@ -387,11 +387,14 @@ 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)
 {
   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;
   if (!LJ_HASMEMPROF) {
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..ae8a73c9
--- /dev/null
+++ b/test/tarantool-tests/profilers/misclib-memprof-lapi-default-file.test.lua
@@ -0,0 +1,37 @@
+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 _, _ = misc.memprof.start()
+
+  local res, err = misc.memprof.stop()
+
+  -- Want to cleanup carefully if something went wrong.
+  if not res then
+    os.remove(default_output_file)
+    error(err)
+  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 any more.
+  os.remove(default_output_file)
+end)
+
+test:done(true)
-- 
2.43.0


      parent reply	other threads:[~2025-02-20 11:26 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-20 11:21 [Tarantool-patches] [PATCH luajit 0/8][v3] Fix profilers issues Sergey Bronnikov via Tarantool-patches
2025-02-20 11:21 ` [Tarantool-patches] [PATCH luajit 1/8][v3] test: add descriptions to sysprof testcases Sergey Bronnikov via Tarantool-patches
2025-02-20 11:21 ` [Tarantool-patches] [PATCH luajit 2/8][v3] test: align test title with test filename Sergey Bronnikov via Tarantool-patches
2025-02-20 11:21 ` [Tarantool-patches] [PATCH luajit 3/8][v3] sysprof: fix typo in the comment Sergey Bronnikov via Tarantool-patches
2025-02-20 11:21 ` [Tarantool-patches] [PATCH luajit 4/8][v3] sysprof: introduce specific errors and default mode Sergey Bronnikov via Tarantool-patches
2025-02-20 11:21 ` [Tarantool-patches] [PATCH luajit 5/8][v3] test: introduce flag LUAJIT_DISABLE_MEMPROF Sergey Bronnikov via Tarantool-patches
2025-02-20 11:21 ` [Tarantool-patches] [PATCH luajit 6/8][v3] ci: add workflow with disabled profilers Sergey Bronnikov via Tarantool-patches
2025-02-20 11:21 ` [Tarantool-patches] [PATCH luajit 7/8][v3] misc: specific message for " Sergey Bronnikov via Tarantool-patches
2025-02-20 11:21 ` Sergey Bronnikov via Tarantool-patches [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e33751601ee37fe00dd4be7900437c37a3f3e97c.1740050074.git.sergeyb@tarantool.org \
    --to=tarantool-patches@dev.tarantool.org \
    --cc=estetus@gmail.com \
    --cc=sergos@tarantool.org \
    --cc=skaplun@tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH luajit 8/8][v3] memprof: set default path to profiling output file' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox