heap allocation time?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

heap allocation time?

Valerio
Hello
is it possible somehow to measure how much time the LuaVM spends to allocate heap memory during the execution of a program? 
Is there some debug flag that shows this information? 

Thanks
--
Valerio

Reply | Threaded
Open this post in threaded view
|

Re: heap allocation time?

Daurnimator
On 1 March 2017 at 08:56, Valerio Schiavoni <[hidden email]> wrote:
> Hello
> is it possible somehow to measure how much time the LuaVM spends to allocate
> heap memory during the execution of a program?
> Is there some debug flag that shows this information?
>
> Thanks
> --
> Valerio
>

You could do so by writing own allocator that takes a timing measurements.
You can either use lua_setallocf() if you're wrapping the existing
allocator, or otherwise pass your own allocator to lua_newstate().

Reply | Threaded
Open this post in threaded view
|

Re: heap allocation time?

Tim Hill

> On Feb 28, 2017, at 7:54 PM, Daurnimator <[hidden email]> wrote:
>
> On 1 March 2017 at 08:56, Valerio Schiavoni <[hidden email]> wrote:
>> Hello
>> is it possible somehow to measure how much time the LuaVM spends to allocate
>> heap memory during the execution of a program?
>> Is there some debug flag that shows this information?
>>
>> Thanks
>> --
>> Valerio
>>
>
> You could do so by writing own allocator that takes a timing measurements.
> You can either use lua_setallocf() if you're wrapping the existing
> allocator, or otherwise pass your own allocator to lua_newstate().
>

I would, however, be very careful with such an approach. A custom allocator is basically a wrapper around realloc(), which of course is (typically) a fast function. If you are not careful the overhead of any instrumentation calls (e.g. getting an OS timestamp counter before/after) will exceed the time taken to make the realloc().

—Tim