diff options
| -rw-r--r-- | lgc.c | 8 | ||||
| -rw-r--r-- | lmem.c | 24 |
2 files changed, 24 insertions, 8 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lgc.c,v 2.74 2010/03/26 20:58:11 roberto Exp roberto $ | 2 | ** $Id: lgc.c,v 2.75 2010/03/29 17:43:14 roberto Exp roberto $ |
| 3 | ** Garbage Collector | 3 | ** Garbage Collector |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -825,10 +825,7 @@ void luaC_runtilstate (lua_State *L, int statesmask) { | |||
| 825 | 825 | ||
| 826 | 826 | ||
| 827 | static void generationalcollection (lua_State *L) { | 827 | static void generationalcollection (lua_State *L) { |
| 828 | static int c = 0; | ||
| 829 | static int prev = 0; | ||
| 830 | global_State *g = G(L); | 828 | global_State *g = G(L); |
| 831 | int a = g->totalbytes; | ||
| 832 | lua_assert(g->gcstate == GCSpropagate); | 829 | lua_assert(g->gcstate == GCSpropagate); |
| 833 | if (g->lastmajormem == 0) { /* signal for another major collection? */ | 830 | if (g->lastmajormem == 0) { /* signal for another major collection? */ |
| 834 | luaC_fullgc(L, 0); /* perform a full regular collection */ | 831 | luaC_fullgc(L, 0); /* perform a full regular collection */ |
| @@ -841,9 +838,6 @@ int a = g->totalbytes; | |||
| 841 | g->lastmajormem = 0; /* signal for a major collection */ | 838 | g->lastmajormem = 0; /* signal for a major collection */ |
| 842 | } | 839 | } |
| 843 | g->GCthreshold = (g->totalbytes/100) * g->gcpause; | 840 | g->GCthreshold = (g->totalbytes/100) * g->gcpause; |
| 844 | /*printf("count: %d old: %d new: %d dif: %d lim: %d threshold: %d\n", | ||
| 845 | c++, a, g->totalbytes, g->totalbytes - prev, g->lastmajormem, g->GCthreshold);*/ | ||
| 846 | prev = g->totalbytes; | ||
| 847 | } | 841 | } |
| 848 | 842 | ||
| 849 | 843 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lmem.c,v 1.73 2006/09/14 18:42:28 roberto Exp roberto $ | 2 | ** $Id: lmem.c,v 1.74 2009/12/16 16:42:58 roberto Exp roberto $ |
| 3 | ** Interface to Memory Manager | 3 | ** Interface to Memory Manager |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -94,6 +94,28 @@ void *luaM_realloc_ (lua_State *L, void *block, size_t osize, size_t nsize) { | |||
| 94 | } | 94 | } |
| 95 | lua_assert((nsize == 0) == (newblock == NULL)); | 95 | lua_assert((nsize == 0) == (newblock == NULL)); |
| 96 | g->totalbytes = (g->totalbytes - realosize) + nsize; | 96 | g->totalbytes = (g->totalbytes - realosize) + nsize; |
| 97 | #if defined(TRACEMEM) | ||
| 98 | { /* auxiliar patch to monitor garbage collection. | ||
| 99 | ** To plot, gnuplot with following command: | ||
| 100 | ** plot TRACEMEM using 1:2 with lines, TRACEMEM using 1:3 with lines | ||
| 101 | */ | ||
| 102 | static unsigned long total = 0; /* our "time" */ | ||
| 103 | static lu_mem last = 0; /* last totalmem that generated an output */ | ||
| 104 | static FILE *f = NULL; /* output file */ | ||
| 105 | if (nsize <= osize) total += 1; /* "time" always grow */ | ||
| 106 | else total += (nsize - osize); | ||
| 107 | if ((int)g->totalbytes - (int)last > 1000 || | ||
| 108 | (int)g->totalbytes - (int)last < -1000) { | ||
| 109 | last = g->totalbytes; | ||
| 110 | if (f == NULL) f = fopen(TRACEMEM, "w"); | ||
| 111 | fprintf(f, "%lu %u %u %d\n", total, | ||
| 112 | g->totalbytes, | ||
| 113 | g->GCthreshold < MAX_LUMEM ? g->GCthreshold : 0, | ||
| 114 | g->gcstate); | ||
| 115 | } | ||
| 116 | } | ||
| 117 | #endif | ||
| 118 | |||
| 97 | return newblock; | 119 | return newblock; |
| 98 | } | 120 | } |
| 99 | 121 | ||
