lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


thank you for your reply.
I read your blog and code carefully. It made me learn a lot.

Yes, using signal functions is very dangerous, but read the source
code, lua_sethook is safe to be called in signals. so I used it.

/*
** This function can be called asynchronously (e.g. during a signal).
** Fields 'oldpc', 'basehookcount', and 'hookcount' (set by
** 'resethookcount') are for debug only, and it is no problem if they
** get arbitrary values (causes at most one wrong hook call). 'hookmask'
** is an atomic value. We assume that pointers are atomic too (e.g., gcc
** ensures that for all platforms where it runs). Moreover, 'hook' is
** always checked before being called (see 'luaD_hook').
*/
LUA_API void lua_sethook (lua_State *L, lua_Hook func, int mask, int count) {

My goal is to only analyze lua code hotspots.
And the reason why I did not use lua debug sampling is because 90% of
the code in our program is lua, and lua also calls many bound C++
functions.
The problem with lua debug is slow and inaccurate, because the
execution time of each instruction is different. It may take more time
to run 1 instructions than 100 instruction, such as calling a bound
C++ function to write a file.
So I use signals to sample and get the real hotspots.When the signal
is called back, it is found that if lua vm is not executed, then this
sampling is directly ignored.

Currently this profiling tool is running well, of course, as you see,
the code below is bad, and may be only work at my machine.

unsigned short nny = *(unsigned short *)((char*)L+196);
unsigned short nCcalls = *(unsigned short *)((char*)L+198);

so may be it would be better if there is a C API here. to check lua VM
is running.


Regards