From: Sergey Kaplun <skaplun@tarantool.org> To: Sergey Ostanevich <sergos@tarantool.org> Cc: tarantool-patches@dev.tarantool.org Subject: Re: [Tarantool-patches] [PATCH luajit v1 09/11] misc: add Lua API for memory profiler Date: Fri, 25 Dec 2020 00:25:20 +0300 [thread overview] Message-ID: <20201224212520.GN9101@root> (raw) In-Reply-To: <77487E42-42F7-48B0-A795-2117966BAA98@tarantool.org> Hi! Thanks for the review! On 24.12.20, Sergey Ostanevich wrote: > Hi! > > Thanks for the patch! > Although, the patch might be outdate, still I have some comments below > that are still relevant in branch. > > > diff --git a/src/lib_misc.c b/src/lib_misc.c > > index 6f7b9a9..d3b5ab4 100644 > > --- a/src/lib_misc.c > > +++ b/src/lib_misc.c > <snipped> > > + > > +/* local started, err, errno = misc.memprof.start(fname) */ > > +LJLIB_CF(misc_memprof_start) > > +{ > > + struct luam_Prof_options opt = {0}; > > + struct memprof_ctx *ctx; > > + const char *fname; > > + int memprof_status; > > + int started; > > + > > + fname = strdata(lj_lib_checkstr(L, 1)); > > + > > + ctx = lj_mem_new(L, sizeof(*ctx)); > > + if (ctx == NULL) > > + goto errmem; > > + > > + opt.ctx = ctx; > > + opt.writer = buffer_writer_default; > > + opt.on_stop = on_stop_cb_default; > > + opt.len = STREAM_BUFFER_SIZE; > > + opt.buf = (uint8_t *)lj_mem_new(L, STREAM_BUFFER_SIZE); > > + if (NULL == opt.buf) { > > + lj_mem_free(G(L), ctx, sizeof(*ctx)); > > + goto errmem; > > + } > > + > > + ctx->g = G(L); > > + ctx->stream = fopen(fname, "wb"); > > + > > + if (ctx->stream == NULL) { > > + memprof_ctx_free(ctx, opt.buf); > > + return luaL_fileresult(L, 0, fname); > > + } > > + > > + memprof_status = ljp_memprof_start(L, &opt); > > + started = memprof_status == LUAM_PROFILE_SUCCESS; > > + > > + if (LJ_UNLIKELY(!started)) { > > + fclose(ctx->stream); > > + remove(fname); > > + memprof_ctx_free(ctx, opt.buf); > > + switch (memprof_status) { > > + case LUAM_PROFILE_ERRRUN: > > + lua_pushnil(L); > > + setstrV(L, L->top++, lj_err_str(L, LJ_ERR_PROF_ISRUNNING)); > > + return 2; > > + case LUAM_PROFILE_ERRMEM: > > + /* Unreachable for now. */ > > + goto errmem; > > + case LUAM_PROFILE_ERRIO: > > + return luaL_fileresult(L, 0, fname); > > + default: > > + break; > > This one means, that you can return ‘false’ without any err/errno set. Thanks! I've forgotten to add `lua_assert(0)`. This case is unreachable, but in release build we should show to the user that something goes wrong. > > > + } > > + } > > + lua_pushboolean(L, started); > > + > > + return 1; > > +errmem: > > + lua_pushnil(L); > > + setstrV(L, L->top++, lj_err_str(L, LJ_ERR_ERRMEM)); > > + return 2; > > +} > > + > > +/* local stopped, err, errno = misc.memprof.stop() */ > > +LJLIB_CF(misc_memprof_stop) > > +{ > > + int status = ljp_memprof_stop(); > > + int stopped_successfully = status == LUAM_PROFILE_SUCCESS; > > + if (!stopped_successfully) { > > + switch (status) { > > + case LUAM_PROFILE_ERRRUN: > > + lua_pushnil(L); > > + setstrV(L, L->top++, lj_err_str(L, LJ_ERR_PROF_NOTRUNNING)); > > + return 2; > > + case LUAM_PROFILE_ERRIO: > > + return luaL_fileresult(L, 0, NULL); > > + default: > > + break; > > Ditto > > > + } > > + } > > + lua_pushboolean(L, stopped_successfully); > > + return 1; > > +} > > + > -- Best regards, Sergey Kaplun
next prev parent reply other threads:[~2020-12-24 21:26 UTC|newest] Thread overview: 42+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-12-16 19:13 [Tarantool-patches] [PATCH luajit v1 00/11] LuaJIT " Sergey Kaplun 2020-12-16 19:13 ` [Tarantool-patches] [PATCH luajit v1 01/11] build: add src dir in building Sergey Kaplun 2020-12-20 21:27 ` Igor Munkin 2020-12-23 18:20 ` Sergey Kaplun 2020-12-16 19:13 ` [Tarantool-patches] [PATCH luajit v1 02/11] utils: introduce leb128 reader and writer Sergey Kaplun 2020-12-20 22:44 ` Igor Munkin 2020-12-23 22:34 ` Sergey Kaplun 2020-12-24 9:11 ` Igor Munkin 2020-12-25 8:46 ` Sergey Kaplun 2020-12-23 16:50 ` Sergey Ostanevich 2020-12-23 22:36 ` Sergey Kaplun 2020-12-16 19:13 ` [Tarantool-patches] [PATCH luajit v1 03/11] profile: introduce profiler writing module Sergey Kaplun 2020-12-21 9:24 ` Igor Munkin 2020-12-24 6:46 ` Sergey Kaplun 2020-12-24 15:45 ` Sergey Ostanevich 2020-12-24 21:20 ` Sergey Kaplun 2020-12-25 9:37 ` Igor Munkin 2020-12-25 10:13 ` Sergey Kaplun 2020-12-16 19:13 ` [Tarantool-patches] [PATCH luajit v1 04/11] profile: introduce symtab write module Sergey Kaplun 2020-12-21 10:30 ` Igor Munkin 2020-12-24 7:00 ` Sergey Kaplun 2020-12-24 9:36 ` Igor Munkin 2020-12-25 8:45 ` Sergey Kaplun 2020-12-16 19:13 ` [Tarantool-patches] [PATCH luajit v1 05/11] vm: introduce LFUNC and FFUNC vmstates Sergey Kaplun 2020-12-25 11:07 ` Sergey Ostanevich 2020-12-25 11:23 ` Sergey Kaplun 2020-12-16 19:13 ` [Tarantool-patches] [PATCH luajit v1 06/11] core: introduce new mem_L field Sergey Kaplun 2020-12-16 19:13 ` [Tarantool-patches] [PATCH luajit v1 07/11] debug: move debug_frameline to public module API Sergey Kaplun 2020-12-20 22:46 ` Igor Munkin 2020-12-24 6:50 ` Sergey Kaplun 2020-12-16 19:13 ` [Tarantool-patches] [PATCH luajit v1 08/11] profile: introduce memory profiler Sergey Kaplun 2020-12-16 19:13 ` [Tarantool-patches] [PATCH luajit v1 09/11] misc: add Lua API for " Sergey Kaplun 2020-12-24 16:32 ` Sergey Ostanevich 2020-12-24 21:25 ` Sergey Kaplun [this message] 2020-12-16 19:13 ` [Tarantool-patches] [PATCH luajit v1 10/11] tools: introduce tools directory Sergey Kaplun 2020-12-20 22:46 ` Igor Munkin 2020-12-24 6:47 ` Sergey Kaplun 2020-12-16 19:13 ` [Tarantool-patches] [PATCH luajit v1 11/11] profile: introduce profile parser Sergey Kaplun 2020-12-24 23:09 ` Igor Munkin 2020-12-25 8:41 ` Sergey Kaplun 2020-12-21 10:43 ` [Tarantool-patches] [PATCH luajit v1 00/11] LuaJIT memory profiler Igor Munkin 2020-12-24 7:02 ` Sergey Kaplun
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=20201224212520.GN9101@root \ --to=skaplun@tarantool.org \ --cc=sergos@tarantool.org \ --cc=tarantool-patches@dev.tarantool.org \ --subject='Re: [Tarantool-patches] [PATCH luajit v1 09/11] misc: add Lua API for 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