added proper code to trace garbage collection
This commit is contained in:
8
lgc.c
8
lgc.c
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lgc.c,v 2.74 2010/03/26 20:58:11 roberto Exp roberto $
|
||||
** $Id: lgc.c,v 2.75 2010/03/29 17:43:14 roberto Exp roberto $
|
||||
** Garbage Collector
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@@ -825,10 +825,7 @@ void luaC_runtilstate (lua_State *L, int statesmask) {
|
||||
|
||||
|
||||
static void generationalcollection (lua_State *L) {
|
||||
static int c = 0;
|
||||
static int prev = 0;
|
||||
global_State *g = G(L);
|
||||
int a = g->totalbytes;
|
||||
lua_assert(g->gcstate == GCSpropagate);
|
||||
if (g->lastmajormem == 0) { /* signal for another major collection? */
|
||||
luaC_fullgc(L, 0); /* perform a full regular collection */
|
||||
@@ -841,9 +838,6 @@ int a = g->totalbytes;
|
||||
g->lastmajormem = 0; /* signal for a major collection */
|
||||
}
|
||||
g->GCthreshold = (g->totalbytes/100) * g->gcpause;
|
||||
/*printf("count: %d old: %d new: %d dif: %d lim: %d threshold: %d\n",
|
||||
c++, a, g->totalbytes, g->totalbytes - prev, g->lastmajormem, g->GCthreshold);*/
|
||||
prev = g->totalbytes;
|
||||
}
|
||||
|
||||
|
||||
|
||||
24
lmem.c
24
lmem.c
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lmem.c,v 1.73 2006/09/14 18:42:28 roberto Exp roberto $
|
||||
** $Id: lmem.c,v 1.74 2009/12/16 16:42:58 roberto Exp roberto $
|
||||
** Interface to Memory Manager
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@@ -94,6 +94,28 @@ void *luaM_realloc_ (lua_State *L, void *block, size_t osize, size_t nsize) {
|
||||
}
|
||||
lua_assert((nsize == 0) == (newblock == NULL));
|
||||
g->totalbytes = (g->totalbytes - realosize) + nsize;
|
||||
#if defined(TRACEMEM)
|
||||
{ /* auxiliar patch to monitor garbage collection.
|
||||
** To plot, gnuplot with following command:
|
||||
** plot TRACEMEM using 1:2 with lines, TRACEMEM using 1:3 with lines
|
||||
*/
|
||||
static unsigned long total = 0; /* our "time" */
|
||||
static lu_mem last = 0; /* last totalmem that generated an output */
|
||||
static FILE *f = NULL; /* output file */
|
||||
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(TRACEMEM, "w");
|
||||
fprintf(f, "%lu %u %u %d\n", total,
|
||||
g->totalbytes,
|
||||
g->GCthreshold < MAX_LUMEM ? g->GCthreshold : 0,
|
||||
g->gcstate);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return newblock;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user