add cmemory.info() returns a table of c memory info

This commit is contained in:
Cloud Wu
2015-07-23 16:47:35 +08:00
parent 588c4a3508
commit 39f9a96b6c
4 changed files with 23 additions and 1 deletions

View File

@@ -2,6 +2,7 @@
#include <string.h>
#include <assert.h>
#include <stdlib.h>
#include <lua.h>
#include "malloc_hook.h"
#include "skynet.h"
@@ -224,3 +225,17 @@ skynet_lalloc(void *ud, void *ptr, size_t osize, size_t nsize) {
return skynet_realloc(ptr, nsize);
}
}
int
dump_mem_lua(lua_State *L) {
int i;
lua_newtable(L);
for(i=0; i<SLOT_SIZE; i++) {
mem_data* data = &mem_stats[i];
if(data->handle != 0 && data->allocated != 0) {
lua_pushinteger(L, data->allocated);
lua_rawseti(L, -2, (lua_Integer)data->handle);
}
}
return 1;
}