From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp33.i.mail.ru (smtp33.i.mail.ru [94.100.177.93]) (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 7FC2D4765E3 for ; Sun, 27 Dec 2020 13:58:52 +0300 (MSK) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.120.23.2.4\)) From: Sergey Ostanevich In-Reply-To: <036ac4034b714d9c3338246fd1bb3b373ef94b64.1608907726.git.skaplun@tarantool.org> Date: Sun, 27 Dec 2020 13:58:50 +0300 Content-Transfer-Encoding: quoted-printable Message-Id: <308C8690-5434-4E09-8BA1-91A3F39F1318@tarantool.org> References: <036ac4034b714d9c3338246fd1bb3b373ef94b64.1608907726.git.skaplun@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 Kaplun Cc: tarantool-patches@dev.tarantool.org 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 =3D &memprof; > + struct alloc *oalloc =3D &mp->orig_alloc; > + struct lj_wbuf *out =3D &mp->out; > + int return_status =3D PROFILE_SUCCESS; > + int saved_errno =3D 0; > + struct lua_State *main_L; > + int cb_status; > + > + memprof_lock(); > + > + if (mp->state =3D=3D MPS_HALT) { > + errno =3D mp->saved_errno; > + mp->state =3D MPS_IDLE > + memprof_unlock(); > + return PROFILE_ERRIO; > + } > + > + if (mp->state !=3D MPS_PROFILE) { > + memprof_unlock(); > + return PROFILE_ERRRUN; > + } > + > + if (L !=3D NULL && mp->g !=3D G(L)) { > + memprof_unlock(); > + return PROFILE_ERR; > + } > + > + mp->state =3D MPS_IDLE; > + > + lua_assert(mp->g !=3D NULL); > + main_L =3D mainthread(mp->g); > + > + lua_assert(memprof_allocf =3D=3D lua_getallocf(main_L, NULL)); > + lua_assert(oalloc->allocf !=3D NULL); > + lua_assert(oalloc->state !=3D 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 =3D MPS_HALT; > + /* on_stop call may change errno value. */ > + mp->saved_errno =3D lj_wbuf_errno(out); > + /* Ignore possible errors. mp->opt.buf =3D=3D 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 =3D mp->opt.on_stop(mp->opt.ctx, mp->opt.buf); > + if (LJ_UNLIKELY(lj_wbuf_test_flag(out, STREAM_ERR_IO) || cb_status = !=3D 0)) { > + saved_errno =3D lj_wbuf_errno(out); Previous return of PROFILE_ERRIO causes MPS_HALT. Should it be the same? > + return_status =3D PROFILE_ERRIO; > + } > + > + lj_wbuf_terminate(out); > + > + memprof_unlock(); > + errno =3D saved_errno; > + return return_status; > +}