[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: GC [was Re: Lua 5.1 (work4) now available]
- From: Roberto Ierusalimschy <roberto@...>
- Date: Tue, 11 Jan 2005 17:10:07 -0200
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