mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-23 11:33:09 +00:00
add cmemory.info() returns a table of c memory info
This commit is contained in:
@@ -42,6 +42,7 @@ luaopen_memory(lua_State *L) {
|
||||
{ "block", lblock },
|
||||
{ "dumpinfo", ldumpinfo },
|
||||
{ "dump", ldump },
|
||||
{ "info", dump_mem_lua },
|
||||
{ NULL, NULL },
|
||||
};
|
||||
|
||||
|
||||
@@ -2,7 +2,11 @@ local skynet = require "skynet"
|
||||
local memory = require "memory"
|
||||
|
||||
memory.dumpinfo()
|
||||
memory.dump()
|
||||
--memory.dump()
|
||||
local info = memory.info()
|
||||
for k,v in pairs(info) do
|
||||
print(string.format(":%08x %gK",k,v/1024))
|
||||
end
|
||||
|
||||
print("Total memory:", memory.total())
|
||||
print("Total block:", memory.block())
|
||||
|
||||
@@ -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