mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-25 04:33:05 +00:00
add cmemory.info() returns a table of c memory info
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define SKYNET_MALLOC_HOOK_H
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <lua.h>
|
||||
|
||||
extern size_t malloc_used_memory(void);
|
||||
extern size_t malloc_memory_block(void);
|
||||
@@ -9,6 +10,7 @@ extern void memory_info_dump(void);
|
||||
extern size_t mallctl_int64(const char* name, size_t* newval);
|
||||
extern int mallctl_opt(const char* name, int* newval);
|
||||
extern void dump_c_mem(void);
|
||||
extern int dump_mem_lua(lua_State *L);
|
||||
|
||||
#endif /* SKYNET_MALLOC_HOOK_H */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user