Tarantool development patches archive
 help / color / mirror / Atom feed
From: Sergey Ostanevich <sergos@tarantool.org>
To: Sergey Kaplun <skaplun@tarantool.org>
Cc: tarantool-patches@dev.tarantool.org
Subject: Re: [Tarantool-patches] [PATCH luajit v2 5/7] core: introduce memory profiler
Date: Sun, 27 Dec 2020 16:27:43 +0300	[thread overview]
Message-ID: <799CAEFC-C0C2-49B2-A695-0E2AE4AA55AD@tarantool.org> (raw)
In-Reply-To: <20201227115405.GA14702@root>

[-- Attachment #1: Type: text/plain, Size: 3839 bytes --]

LGTM

Sergos

> On 27 Dec 2020, at 14:54, Sergey Kaplun <skaplun@tarantool.org> wrote:
> 
> Hi, Sergos!
> 
> Thanks for the review!
> 
> On 27.12.20, Sergey Ostanevich wrote:
>> Hi!
>> 
>> Thanks for the patch! Just one question below, looks good otherwise.
>> 
>> Sergos
>> 
>>> diff --git a/src/lj_memprof.c b/src/lj_memprof.c
>>> new file mode 100644
>>> index 0000000..e0df057
>>> --- /dev/null
>>> +++ b/src/lj_memprof.c
>> <snipped>
>>> +static int memprof_stop(const struct lua_State *L)
>>> +{
>>> +  struct memprof *mp = &memprof;
>>> +  struct alloc *oalloc = &mp->orig_alloc;
>>> +  struct lj_wbuf *out = &mp->out;
>>> +  int return_status = PROFILE_SUCCESS;
>>> +  int saved_errno = 0;
>>> +  struct lua_State *main_L;
>>> +  int cb_status;
>>> +
>>> +  memprof_lock();
>>> +
>>> +  if (mp->state == MPS_HALT) {
>>> +    errno = mp->saved_errno;
>>> +    mp->state = MPS_IDLE
>>> +    memprof_unlock();
>>> +    return PROFILE_ERRIO;
>>> +  }
>>> +
>>> +  if (mp->state != MPS_PROFILE) {
>>> +    memprof_unlock();
>>> +    return PROFILE_ERRRUN;
>>> +  }
>>> +
>> 
>>> +  if (L != NULL && mp->g != G(L)) {
>>> +    memprof_unlock();
>>> +    return PROFILE_ERR;
>>> +  }
>>> +
>>> +  mp->state = MPS_IDLE;
>>> +
>>> +  lua_assert(mp->g != NULL);
>>> +  main_L = mainthread(mp->g);
>>> +
>>> +  lua_assert(memprof_allocf == lua_getallocf(main_L, NULL));
>>> +  lua_assert(oalloc->allocf != NULL);
>>> +  lua_assert(oalloc->state != NULL);
>>> +  lua_setallocf(main_L, oalloc->allocf, oalloc->state);
>>> +
>>> +  if (LJ_UNLIKELY(lj_wbuf_test_flag(out, STREAM_STOP))) {
>>> +    lua_assert(lj_wbuf_test_flag(out, STREAM_ERR_IO));
>>> +    mp->state = MPS_HALT;
>>> +    /* on_stop call may change errno value. */
>>> +    mp->saved_errno = lj_wbuf_errno(out);
>>> +    /* Ignore possible errors. mp->opt.buf == NULL here. */
>>> +    mp->opt.on_stop(mp->opt.ctx, mp->opt.buf);
>>> +    lj_wbuf_terminate(out);
>>> +    memprof_unlock();
>>> +    return PROFILE_ERRIO;
>>> +  }
>>> +  lj_wbuf_addbyte(out, LJM_EPILOGUE_HEADER);
>>> +
>>> +  lj_wbuf_flush(out);
>>> +
>>> +  cb_status = mp->opt.on_stop(mp->opt.ctx, mp->opt.buf);
>>> +  if (LJ_UNLIKELY(lj_wbuf_test_flag(out, STREAM_ERR_IO) || cb_status != 0)) {
>>> +    saved_errno = lj_wbuf_errno(out);
>> 
>> Previous return of PROFILE_ERRIO causes MPS_HALT. Should it be the same?
> 
> Yes, you're right! Previous MPS_HALT is redundant -- profiler anyway
> should stop (IDLE) immediately, there is no reason to set HALT there.
> Thanks! Fixed!
> 
> See the iterative diff below. Branch is force-pushed.
> 
>> 
>>> +    return_status = PROFILE_ERRIO;
>>> +  }
>>> +
>>> +  lj_wbuf_terminate(out);
>>> +
>>> +  memprof_unlock();
>>> +  errno = saved_errno;
>>> +  return return_status;
>>> +}
>> 
> 
> ===================================================================
> diff --git a/src/lj_memprof.c b/src/lj_memprof.c
> index e0df057..998cbea 100644
> --- a/src/lj_memprof.c
> +++ b/src/lj_memprof.c
> @@ -354,13 +354,13 @@ static int memprof_stop(const struct lua_State *L)
> 
>   if (LJ_UNLIKELY(lj_wbuf_test_flag(out, STREAM_STOP))) {
>     lua_assert(lj_wbuf_test_flag(out, STREAM_ERR_IO));
> -    mp->state = MPS_HALT;
>     /* on_stop call may change errno value. */
> -    mp->saved_errno = lj_wbuf_errno(out);
> +    saved_errno = lj_wbuf_errno(out);
>     /* Ignore possible errors. mp->opt.buf == NULL here. */
>     mp->opt.on_stop(mp->opt.ctx, mp->opt.buf);
>     lj_wbuf_terminate(out);
>     memprof_unlock();
> +    errno = saved_errno;
>     return PROFILE_ERRIO;
>   }
>   lj_wbuf_addbyte(out, LJM_EPILOGUE_HEADER);
> ===================================================================
> 
> -- 
> Best regards,
> Sergey Kaplun


[-- Attachment #2: Type: text/html, Size: 31522 bytes --]

  reply	other threads:[~2020-12-27 13:27 UTC|newest]

Thread overview: 52+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-25 15:26 [Tarantool-patches] [PATCH luajit v2 0/7] LuaJIT " Sergey Kaplun
2020-12-25 15:26 ` [Tarantool-patches] [PATCH luajit v2 1/7] utils: introduce leb128 reader and writer Sergey Kaplun
2020-12-25 21:42   ` Igor Munkin
2020-12-26  9:32     ` Sergey Kaplun
2020-12-26 13:57       ` Sergey Kaplun
2020-12-26 18:47         ` Sergey Ostanevich
2020-12-25 15:26 ` [Tarantool-patches] [PATCH luajit v2 2/7] core: introduce write buffer module Sergey Kaplun
2020-12-26 14:22   ` Igor Munkin
2020-12-26 15:26     ` Sergey Kaplun
2020-12-26 19:03       ` Sergey Ostanevich
2020-12-26 19:37         ` Sergey Kaplun
2020-12-28  1:43           ` Sergey Kaplun
2020-12-25 15:26 ` [Tarantool-patches] [PATCH luajit v2 3/7] vm: introduce VM states for Lua and fast functions Sergey Kaplun
2020-12-26 19:07   ` Sergey Ostanevich
2020-12-27 23:48   ` Igor Munkin
2020-12-28  3:54     ` Sergey Kaplun
2020-12-25 15:26 ` [Tarantool-patches] [PATCH luajit v2 4/7] core: introduce new mem_L field Sergey Kaplun
2020-12-26 19:12   ` Sergey Ostanevich
2020-12-26 19:42     ` Sergey Kaplun
2020-12-27 13:09   ` Igor Munkin
2020-12-27 17:44     ` Sergey Kaplun
2020-12-25 15:26 ` [Tarantool-patches] [PATCH luajit v2 5/7] core: introduce memory profiler Sergey Kaplun
2020-12-27 10:58   ` Sergey Ostanevich
2020-12-27 11:54     ` Sergey Kaplun
2020-12-27 13:27       ` Sergey Ostanevich [this message]
2020-12-27 16:44   ` Igor Munkin
2020-12-27 21:47     ` Sergey Kaplun
2020-12-25 15:26 ` [Tarantool-patches] [PATCH luajit v2 6/7] misc: add Lua API for " Sergey Kaplun
2020-12-27 11:54   ` Sergey Ostanevich
2020-12-27 13:42     ` Sergey Kaplun
2020-12-27 15:37       ` Sergey Ostanevich
2020-12-27 18:58   ` Igor Munkin
2020-12-28  0:14     ` Sergey Kaplun
2020-12-25 15:26 ` [Tarantool-patches] [PATCH luajit v2 7/7] tools: introduce a memory profile parser Sergey Kaplun
2020-12-26 22:56   ` Igor Munkin
2020-12-27  7:16     ` Sergey Kaplun
2020-12-28  5:30       ` Sergey Kaplun
2020-12-28  5:33         ` Igor Munkin
2020-12-28  6:28           ` Sergey Kaplun
2020-12-28  6:31             ` Igor Munkin
2020-12-27 13:24   ` Sergey Ostanevich
2020-12-27 16:02     ` Sergey Kaplun
2020-12-27 21:55       ` Sergey Ostanevich
2020-12-28  2:05 ` [Tarantool-patches] [PATCH luajit v3 2/2] misc: add Lua API for memory profiler Sergey Kaplun
2020-12-28  2:49   ` Igor Munkin
2020-12-28  5:19     ` Sergey Kaplun
2020-12-28  2:06 ` [Tarantool-patches] [PATCH luajit v3 1/2] core: introduce " Sergey Kaplun
2020-12-28  3:59   ` Igor Munkin
2020-12-28  4:05 ` [Tarantool-patches] [PATCH luajit v3 3/7] vm: introduce VM states for Lua and fast functions Sergey Kaplun
2020-12-28  5:14   ` Igor Munkin
2020-12-28  6:01 ` [Tarantool-patches] [PATCH luajit v2 0/7] LuaJIT memory profiler Alexander V. Tikhonov
2020-12-28  8:15 ` Igor Munkin

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=799CAEFC-C0C2-49B2-A695-0E2AE4AA55AD@tarantool.org \
    --to=sergos@tarantool.org \
    --cc=skaplun@tarantool.org \
    --cc=tarantool-patches@dev.tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH luajit v2 5/7] core: introduce memory profiler' \
    /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