lua-users home
lua-l archive

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


Hello !

Can someone shed a light here ?

I'm trying to implement a kind of profiler/coverage output from Lua-5.4.6 and I've got almost there, I'm having difficult to get a function name from inside "freeobj" (see diff bellow).

Actually I'm getting an output like this:

====

#line | call_count | time_spent_count | time_spent | source_name

[1    2    0    0    @./leftry/reducers.lua]
[0    3    0    0    @./leftry/reducers.lua]
[0    1    0    0    @./leftry/initializers.lua]
[247    12    0    0    @./leftry/ast.lua]
[214    12    0    0    @./leftry/ast.lua]
[164    12    0    0    @./leftry/ast.lua]
[83    37    0    0    @./leftry/ast.lua]
[80    37    0    0    @./leftry/ast.lua]
[10    60    0    0    @./leftry/ast.lua]
[366    2    0    0    @./leftry/language/lua.lua]
[340    10    0    0    @./leftry/language/lua.lua]

====

And I want to also include the function name if possible, I only have a lua_State and a Proto to work with unless I'm missing something else.

====

diff -u lua-5.4.6/src/lgc.c lua-5.4.6-x/src/lgc.c
--- lua-5.4.6/src/lgc.c    2023-05-02 22:02:29.000000000 +0200
+++ lua-5.4.6-x/src/lgc.c    2023-06-06 21:48:01.473627976 +0200
@@ -766,10 +766,18 @@
   luaM_free(L, uv);
 }

-
 static void freeobj (lua_State *L, GCObject *o) {
   switch (o->tt) {
     case LUA_VPROTO:
+#ifdef LUA_PROFILE_CALLS
+      if(L->is_profile_calls_enabled) {
+        Proto *f = gco2p(o);
+        if(f->call_count || L->is_profile_calls_enabled > 2) {
+          const char *sourcename = getstr(f->source); //"<NULL>"; //funcnamefromcode(L, f, 0, &fname) +          fprintf(stderr, "[%d\t%zu\t%zu\t%zu\t%s]\n", f->linedefined, f->call_count, f->time_spent_count, f->time_spent, sourcename);
+        }
+      }
+#endif
       luaF_freeproto(L, gco2p(o));
       break;
     case LUA_VUPVAL:
====

Cheers !