aboutsummaryrefslogtreecommitdiffstats
path: root/util-src
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2012-07-08 18:47:05 +0100
committerMatthew Wild <mwild1@gmail.com>2012-07-08 18:47:05 +0100
commit518414dbf7c6d45ca115b080b0fe19f6fdf93cc7 (patch)
tree6e8b01fd5fb4b815d1c395ad0f94a01d2ad1b451 /util-src
parentd7bbafcd372997dbec05e0dec67c1da41968050f (diff)
downloadprosody-518414dbf7c6d45ca115b080b0fe19f6fdf93cc7.tar.gz
prosody-518414dbf7c6d45ca115b080b0fe19f6fdf93cc7.zip
util.pposix: Add meminfo() binding to memory allocation stats provided by mallinfo() [compilation tested on Ubuntu...]
Diffstat (limited to 'util-src')
-rw-r--r--util-src/pposix.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/util-src/pposix.c b/util-src/pposix.c
index a5a89d55..8dfd6c75 100644
--- a/util-src/pposix.c
+++ b/util-src/pposix.c
@@ -34,6 +34,11 @@
#include "lua.h"
#include "lauxlib.h"
+#if (defined(_SVID_SOURCE) && !defined(WITHOUT_MALLINFO))
+ #include <malloc.h>
+ #define WITH_MALLINFO
+#endif
+
/* Daemonization support */
static int lc_daemonize(lua_State *L)
@@ -612,6 +617,25 @@ int lc_setenv(lua_State* L)
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 @@ int luaopen_util_pposix(lua_State *L)
{ "setenv", lc_setenv },
+#ifdef WITH_MALLINFO
+ { "meminfo", lc_meminfo },
+#endif
+
{ NULL, NULL }
};