Add rspamd_lua_get_memory_used() that combines LUA_GCCOUNT and
LUA_GCCOUNTB into a byte count. Used by the memstat control command;
also a convenient single entry point for any future per-worker Lua
heap diagnostics.
lua_gc(L, LUA_GCRESTART, 0);
}
+gsize rspamd_lua_get_memory_used(lua_State *L)
+{
+ int kb;
+ int rem;
+
+ if (L == NULL) {
+ return 0;
+ }
+
+ kb = lua_gc(L, LUA_GCCOUNT, 0);
+ rem = lua_gc(L, LUA_GCCOUNTB, 0);
+
+ if (kb < 0) {
+ kb = 0;
+ }
+ if (rem < 0) {
+ rem = 0;
+ }
+
+ return (gsize) kb * 1024 + (gsize) rem;
+}
+
void rspamd_plugins_table_push_elt(lua_State *L, const char *field_name,
const char *new_elt)
void rspamd_lua_start_gc(struct rspamd_config *cfg);
+/**
+ * Returns the total amount of memory currently used by the Lua heap, in bytes.
+ * Combines LUA_GCCOUNT (kilobytes) and LUA_GCCOUNTB (bytes remainder).
+ */
+gsize rspamd_lua_get_memory_used(lua_State *L);
+
/**
* Sets field in a global variable
* @param L