[Tarantool-patches] [PATCH luajit 5/7] memprof: add profile common section

Maxim Kokryashkin max.kokryashkin at gmail.com
Wed Sep 8 20:50:48 MSK 2021


A Lua API for sysprof needs to be introduced, but sysprof's C API is quite
similar with memprof's. Considering this, there are some structures and
functions that should be common between memprof's and sysprof's
implementations of Lua API to avoid duplication.

Part of tarantool/tarantool#781
---
 src/lib_misc.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/src/lib_misc.c b/src/lib_misc.c
index 1dab08cc..a44476e0 100644
--- a/src/lib_misc.c
+++ b/src/lib_misc.c
@@ -75,9 +75,7 @@ LJLIB_CF(misc_getmetrics)
 
 #include "lj_libdef.h"
 
-/* ----- misc.memprof module ---------------------------------------------- */
-
-#define LJLIB_MODULE_misc_memprof
+/* --------- profile common  ---------------------------------------------- */
 
 /*
 ** Yep, 8Mb. Tuned in order not to bother the platform with too often flushes.
@@ -85,7 +83,7 @@ LJLIB_CF(misc_getmetrics)
 #define STREAM_BUFFER_SIZE (8 * 1024 * 1024)
 
 /* Structure given as ctx to memprof writer and on_stop callback. */
-struct memprof_ctx {
+struct profile_ctx {
   /* Output file stream for data. */
   FILE *stream;
   /* Profiled global_State for lj_mem_free at on_stop callback. */
@@ -101,7 +99,7 @@ struct memprof_ctx {
 static size_t buffer_writer_default(const void **buf_addr, size_t len,
 				    void *opt)
 {
-  struct memprof_ctx *ctx = opt;
+  struct profile_ctx *ctx = opt;
   FILE *stream = ctx->stream;
   const void * const buf_start = *buf_addr;
   const void *data = *buf_addr;
@@ -140,19 +138,22 @@ static size_t buffer_writer_default(const void **buf_addr, size_t len,
 /* Default on stop callback. Just close the corresponding stream. */
 static int on_stop_cb_default(void *opt, uint8_t *buf)
 {
-  struct memprof_ctx *ctx = opt;
+  struct profile_ctx *ctx = opt;
   FILE *stream = ctx->stream;
   UNUSED(buf);
   lj_mem_free(ctx->g, ctx, sizeof(*ctx));
   return fclose(stream);
 }
 
+/* ----- misc.memprof module ---------------------------------------------- */
+
+#define LJLIB_MODULE_misc_memprof
 /* 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));
-  struct memprof_ctx *ctx;
+  struct profile_ctx *ctx;
   int memprof_status;
 
   /*
-- 
2.33.0



More information about the Tarantool-patches mailing list