lua-users home
lua-l archive

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


As you took long to reply, I came up with my own method. I
changed lmem.c to trace the important variables at each memory
operation. Instead of a counter, I use "total memory use" as the x
axys. And I added a small trick to avoid too many points:

***************
*** 74,79 ****
--- 74,82 ----
  ** generic allocation routine.
  */
  void *luaM_realloc_ (lua_State *L, void *block, size_t osize, size_t nsize) {
+ static unsigned long total = 0;  /* our "time" */
+ static lu_mem last = 0;  /* last totalmem that generated an output */
+ static FILE *f = NULL;  /* output file */
    global_State *g = G(L);
    lua_assert((osize == 0) == (block == NULL));
    block = (*g->realloc)(g->ud, block, osize, nsize);
***************
*** 81,86 ****
--- 84,96 ----
      luaD_throw(L, LUA_ERRMEM);
    lua_assert((nsize == 0) == (block == NULL));
    g->totalbytes = (g->totalbytes - osize) + nsize;
+ if (nsize <= osize) total += 1;  /* "time" always grow */
+ else total += (nsize - osize);
+ if ((int)g->totalbytes - (int)last > 1000 || (int)g->totalbytes - (int)last < -1000) {
+ last = g->totalbytes;
+ if (f == NULL) f = fopen("trace", "w");
+ fprintf(f, "%lu %u %u %d\n", total, g->totalbytes, g->GCthreshold, g->gcstate);
+ }
    return block;
  }

-- Roberto