[Tarantool-patches] [PATCH luajit v1 03/11] profile: introduce profiler writing module

Sergey Kaplun skaplun at tarantool.org
Fri Dec 25 00:20:37 MSK 2020


On 24.12.20, Sergey Ostanevich wrote:
> Hi!
> 
> Thanks for the changes. Although I see no new patch - I look into the 
> origin/skaplun/gh-5442-luajit-memory-profiler under third_party/luajit

Yes, I'm adding some updates relating to Igor's review for RFC, naming
and commit messages.

> 
> +void lj_wbuf_init(struct lj_wbuf *buf, lj_wbuf_writer writer, void *ctx,
> +                 uint8_t *mem, size_t size)
> +{
> +  lua_assert(size >= LEB128_U64_MAXSIZE);
> 
> Is it meaningful to allocate just 10bytes?

No, but at least we should check it. We need at least 10bytes buffer to
write huge addresses leb128-encoded.

> 
> +/* Writes n bytes from an arbitrary buffer src to the buffer. */
> +void lj_wbuf_addn(struct lj_wbuf *buf, const void *src, size_t n)
> +{
> +  if (LJ_UNLIKELY(lj_wbuf_test_flag(buf, STREAM_STOP)))
> +    return;
> +  /*
> +  ** Very unlikely: We are told to write a large buffer at once.
> +  ** Buffer not belong to us so we must to pump data
> +  ** through buffer.
> +  */
> +  while (LJ_UNLIKELY(n > buf->size)) {
> +    const size_t left = wbuf_left(buf);
> +    memcpy(buf->pos, src, left);
> 
> I’m afraid the src pointer is not progress through the while() loop

Thank you very much! Nice catch! Fixed.

> 
> 
> +    buf->pos += (ptrdiff_t)left;
> +    lj_wbuf_flush(buf);
> +    n -= left;
> +  }
> 
> 
> Sergos.
> 
> 

<snipped>

> 

-- 
Best regards,
Sergey Kaplun


More information about the Tarantool-patches mailing list