From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp52.i.mail.ru (smtp52.i.mail.ru [94.100.177.112]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id DC75C4765E3 for ; Sun, 27 Dec 2020 14:54:51 +0300 (MSK) Date: Sun, 27 Dec 2020 14:54:05 +0300 From: Sergey Kaplun Message-ID: <20201227115405.GA14702@root> References: <036ac4034b714d9c3338246fd1bb3b373ef94b64.1608907726.git.skaplun@tarantool.org> <308C8690-5434-4E09-8BA1-91A3F39F1318@tarantool.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <308C8690-5434-4E09-8BA1-91A3F39F1318@tarantool.org> Subject: Re: [Tarantool-patches] [PATCH luajit v2 5/7] core: introduce memory profiler List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Sergey Ostanevich Cc: tarantool-patches@dev.tarantool.org 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 > > > +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