mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-22 02:53:09 +00:00
add debug api to show current service c memory
This commit is contained in:
@@ -41,6 +41,12 @@ lexpandshrtbl(lua_State *L) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
lcurrent(lua_State *L) {
|
||||
lua_pushinteger(L, malloc_current_memory());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
luaopen_memory(lua_State *L) {
|
||||
luaL_checkversion(L);
|
||||
@@ -53,6 +59,7 @@ luaopen_memory(lua_State *L) {
|
||||
{ "info", dump_mem_lua },
|
||||
{ "ssinfo", luaS_shrinfo },
|
||||
{ "ssexpand", lexpandshrtbl },
|
||||
{ "current", lcurrent },
|
||||
{ NULL, NULL },
|
||||
};
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#include <lua.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "malloc_hook.h"
|
||||
#include "skynet.h"
|
||||
@@ -248,3 +249,24 @@ dump_mem_lua(lua_State *L) {
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
size_t
|
||||
malloc_current_memory(void) {
|
||||
uint32_t handle = skynet_current_handle();
|
||||
int i;
|
||||
for(i=0; i<SLOT_SIZE; i++) {
|
||||
mem_data* data = &mem_stats[i];
|
||||
if(data->handle == (uint32_t)handle && data->allocated != 0) {
|
||||
return (size_t) data->allocated;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
skynet_debug_memory(const char *info) {
|
||||
// for debug use
|
||||
uint32_t handle = skynet_current_handle();
|
||||
size_t mem = malloc_current_memory();
|
||||
fprintf(stderr, "[:%08x] %s %p\n", handle, info, (void *)mem);
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ 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);
|
||||
extern size_t malloc_current_memory(void);
|
||||
|
||||
#endif /* SKYNET_MALLOC_HOOK_H */
|
||||
|
||||
|
||||
@@ -39,5 +39,6 @@ void skynet_callback(struct skynet_context * context, void *ud, skynet_cb cb);
|
||||
|
||||
uint32_t skynet_current_handle(void);
|
||||
uint64_t skynet_now(void);
|
||||
void skynet_debug_memory(const char *info); // for debug use, output current service memory to stderr
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user