Re: Tracking memory usage by function

  • From: "Yichun Zhang (agentzh)" <agentzh@xxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Thu, 6 Aug 2015 21:58:37 +0800

Hello!

On Sun, Aug 2, 2015 at 8:21 AM, Qingjun Wei wrote:

I would like to be able to track memory usage on function basis.

I am not very familiar with the LuaJIT design. By just browsing through the
code I am wondering if it is possible to try the following?

1. Assign an integer ID to each function
2. Add another field into GCobj struct for function ID
3. During (re)allocation process increment the function memory usage by
specific amount.
4. During GC process decrement the memory from the function identified by
function ID field.


Hmm, actually I've thinking about something more general and more
useful: keeping the track of the LuaJIT bytecode initiating the GCobj
allocations in each GCobj instance. With bytecode IDs in each GCobj,
it's easy to calculate the distribution across Lua functions. This can
be immensely helpful for analyzing the source of excessive dead GC
objects that have not yet been GC'd in a live or dead LuaJIT VM
snapshot (by means of tools like systemtap/dtrace or gdb/lldb) [1].

Of course all such things employ additional overhead which may not be
trivial at all.

As far as I can see, the most tricky part is to map the bytecode (or
the belonging Lua function) IDs down to the GC object allocators, even
through the JIT compiler. Since my knowledge of LuaJIT is still quite
limited, other guys can correct me if I'm wrong :)

Just my 2 cents.

Best regards,
-agentzh

[1] For live GC object analysis, we can simply traverse them from
those GC roots, just like the LuaJIT GC's "mark" phase.

Other related posts: