[Tarantool-patches] [PATCH luajit v3 2/2] misc: add Lua API for memory profiler

Igor Munkin imun at tarantool.org
Mon Dec 28 05:49:14 MSK 2020


Sergey,

Thanks for the patch! LGTM with the several comments below.

On 28.12.20, Sergey Kaplun wrote:
> This patch introduces Lua API for LuaJIT memory profiler implemented in
> the scope of the previous patch.
> 
> Profiler returns true value if started/stopped successfully,
> returns nil on failure (plus an error message as a second result and a
> system-dependent error code as a third result).
> If LuaJIT is build without memory profiler both return `false`.

Typo: s/`false`/false/ considering true and nil above.

> 
> <lj_errmsg.h> have adjusted with three new errors

Typo: s/have adjusted/has been adjusted/.

> PROF_MISUSE/PROF_ISRUNNING/PROF_NOTRUNNING returned in case when
> profiler has used incorrectly/started/stopped already correspondingly.
> 
> Part of tarantool/tarantool#5442
> ---
> 
> Changes in v3:
>   * Fixed lj_mem_new misuse.
>   * Moved buffer inside ctx.
>   * Codestyle fixes.
> 
>  src/Makefile.dep |   5 +-
>  src/lib_misc.c   | 166 +++++++++++++++++++++++++++++++++++++++++++++++
>  src/lj_errmsg.h  |   7 ++
>  3 files changed, 176 insertions(+), 2 deletions(-)
> 

<snipped>

> diff --git a/src/lib_misc.c b/src/lib_misc.c
> index 6f7b9a9..619cfb7 100644
> --- a/src/lib_misc.c
> +++ b/src/lib_misc.c

<snipped>

> @@ -67,8 +75,166 @@ LJLIB_CF(misc_getmetrics)

<snipped>

> +/* local started, err, errno = misc.memprof.start(fname) */
> +LJLIB_CF(misc_memprof_start)
> +{

<snipped>

> +  if (LJ_UNLIKELY(memprof_status != PROFILE_SUCCESS)) {
> +    lj_mem_free(ctx->g, ctx, sizeof(*ctx));

This deallocation causes double free if PROFILE_ERRIO occurs, since the
ctx is released within on_stop callback.

ctx->stream should be closed if PROFILE_ERR(USE|RUN) occurs.

> +    switch (memprof_status) {

<snipped>

> +    }
> +  }
> +  lua_pushboolean(L, 1);
> +

Typo: Excess newline.

> +  return 1;
> +}

<snipped>

> -- 
> 2.28.0
> 

-- 
Best regards,
IM


More information about the Tarantool-patches mailing list