# HG changeset patch # User Matthew Wild # Date 1341769625 -3600 # Node ID 2975c7008ccdaacb929e1da5333c2b0db9551cae # Parent 72a2eec4204abe85d9bf37374fc5f3696886456a util.pposix: Add meminfo() binding to memory allocation stats provided by mallinfo() [compilation tested on Ubuntu...] diff -r 72a2eec4204a -r 2975c7008ccd util-src/pposix.c --- a/util-src/pposix.c Sat Jul 07 03:42:31 2012 +0200 +++ b/util-src/pposix.c Sun Jul 08 18:47:05 2012 +0100 @@ -34,6 +34,11 @@ #include "lua.h" #include "lauxlib.h" +#if (defined(_SVID_SOURCE) && !defined(WITHOUT_MALLINFO)) + #include + #define WITH_MALLINFO +#endif + /* Daemonization support */ static int lc_daemonize(lua_State *L) @@ -612,6 +617,25 @@ return 1; } +#ifdef WITH_MALLINFO +int lc_meminfo(lua_State* L) +{ + struct mallinfo info = mallinfo(); + lua_newtable(L); + lua_pushinteger(L, info.arena); + lua_setfield(L, -2, "allocated"); + lua_pushinteger(L, info.hblkhd); + lua_setfield(L, -2, "allocated_mmap"); + lua_pushinteger(L, info.uordblks); + lua_setfield(L, -2, "used"); + lua_pushinteger(L, info.fordblks); + lua_setfield(L, -2, "unused"); + lua_pushinteger(L, info.keepcost); + lua_setfield(L, -2, "returnable"); + return 1; +} +#endif + /* Register functions */ int luaopen_util_pposix(lua_State *L) @@ -645,6 +669,10 @@ { "setenv", lc_setenv }, +#ifdef WITH_MALLINFO + { "meminfo", lc_meminfo }, +#endif + { NULL, NULL } };