浏览代码

auxiliar patch to monitor garbage collection

Roberto Ierusalimschy 20 年之前
父节点
当前提交
8e346d875a
共有 1 个文件被更改,包括 17 次插入1 次删除
  1. 17 1
      lmem.c

+ 17 - 1
lmem.c

@@ -1,5 +1,5 @@
 /*
 /*
-** $Id: lmem.c,v 1.66 2004/11/19 15:52:40 roberto Exp roberto $
+** $Id: lmem.c,v 1.67 2004/12/01 15:46:18 roberto Exp roberto $
 ** Interface to Memory Manager
 ** Interface to Memory Manager
 ** See Copyright Notice in lua.h
 ** See Copyright Notice in lua.h
 */
 */
@@ -81,6 +81,22 @@ void *luaM_realloc_ (lua_State *L, void *block, size_t osize, size_t nsize) {
     luaD_throw(L, LUA_ERRMEM);
     luaD_throw(L, LUA_ERRMEM);
   lua_assert((nsize == 0) == (block == NULL));
   lua_assert((nsize == 0) == (block == NULL));
   g->totalbytes = (g->totalbytes - osize) + nsize;
   g->totalbytes = (g->totalbytes - osize) + nsize;
+#if 0
+  { /* auxiliar patch to monitor garbage collection */
+    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("trace", "w");
+      fprintf(f, "%lu %u %u %u %d\n", total, g->totalbytes, g->GCthreshold,
+                                      g->estimate, g->gcstate);
+    }
+  }
+#endif
   return block;
   return block;
 }
 }