add debug api to show current service c memory

This commit is contained in:
Cloud Wu
2015-12-17 22:13:51 +08:00
parent 9d6bde01a3
commit 20610723a1
4 changed files with 31 additions and 0 deletions

View File

@@ -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);
}