Skip to content

Commit

Permalink
Two configuration variables are introduced that can help
Browse files Browse the repository at this point in the history
troubleshooting memory leaks: mem_dump_pkg, and mem_dump_shm
Useage:

sercmd cfg.set_now_int mem_dump_pkg <pid_number>
  Dumps the pkg memory status of the given processs

sercmd cfg.set_now_int mem_dump_shm 1
  Dumps the shm memory status
  • Loading branch information
Miklos Tirpak committed Apr 4, 2008
1 parent c6c9162 commit b4c9f98
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 0 deletions.
17 changes: 17 additions & 0 deletions cfg_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
#ifdef USE_DNS_CACHE
#include "dns_cache.h"
#endif
#if defined PKG_MALLOC || defined SHM_MEM
#include "pt.h"
#endif
#include "cfg/cfg.h"
#include "cfg_core.h"

Expand Down Expand Up @@ -78,6 +81,12 @@ struct cfg_group_core default_core_cfg = {
DEFAULT_DNS_MAX_MEM, /* dns_cache_max_mem */
0, /* dns_cache_del_nonexp -- delete only expired entries by default */
#endif
#ifdef PKG_MALLOC
0, /* mem_dump_pkg */
#endif
#ifdef SHM_MEM
0, /* mem_dump_shm */
#endif
};

void *core_cfg = &default_core_cfg;
Expand Down Expand Up @@ -156,6 +165,14 @@ cfg_def_t core_cfg_def[] = {
{"dns_cache_del_nonexp", CFG_VAR_INT, 0, 1, 0, 0,
"allow deletion of non-expired records from the cache when "
"there is no more space left for new ones"},
#endif
#ifdef PKG_MALLOC
{"mem_dump_pkg", CFG_VAR_INT, 0, 0, 0, mem_dump_pkg_cb,
"dump process memory status, parameter: pid_number"},
#endif
#ifdef SHM_MEM
{"mem_dump_shm", CFG_VAR_INT, 0, 0, mem_dump_shm_fixup, 0,
"dump shared memory status"},
#endif
{0, 0, 0, 0, 0, 0}
};
6 changes: 6 additions & 0 deletions cfg_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ struct cfg_group_core {
unsigned int dns_cache_max_mem;
int dns_cache_del_nonexp;
#endif
#ifdef PKG_MALLOC
int mem_dump_pkg;
#endif
#ifdef SHM_MEM
int mem_dump_shm;
#endif
};

extern struct cfg_group_core default_core_cfg;
Expand Down
57 changes: 57 additions & 0 deletions pt.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@
#include "sr_module.h"
#include "socket_info.h"
#include "rand/fastrand.h"
#ifdef PKG_MALLOC
#include "mem/mem.h"
#endif
#ifdef SHM_MEM
#include "mem/shm_mem.h"
#endif
#if defined PKG_MALLOC || defined SHM_MEM
#include "cfg_core.h"
#endif

#include <stdio.h>
#include <time.h> /* time(), used to initialize random numbers */
Expand Down Expand Up @@ -506,3 +515,51 @@ int fork_tcp_process(int child_id, char *desc, int r, int *reader_fd_1)
return ret;
}
#endif

#ifdef PKG_MALLOC
/* Dumps pkg memory status.
* Per-child process callback that is called
* when mem_dump_pkg cfg var is changed.
*/
void mem_dump_pkg_cb(str *name)
{
int old_memlog;

if (cfg_get(core, core_cfg, mem_dump_pkg) == my_pid()) {
/* set memlog to ALERT level to force
printing the log messages */
old_memlog = memlog;
memlog = L_ALERT;

LOG(memlog, "Memory status (pkg) of process %d:\n", my_pid());
pkg_status();

memlog = old_memlog;
}
}
#endif

#ifdef SHM_MEM
/* Dumps shm memory status.
* fixup function that is called
* when mem_dump_shm cfg var is set.
*/
int mem_dump_shm_fixup(void *handle, str *name, void **val)
{
int old_memlog;

if ((long)(void*)(*val)) {
/* set memlog to ALERT level to force
printing the log messages */
old_memlog = memlog;
memlog = L_ALERT;

LOG(memlog, "Memory status (shm)\n");
shm_status();

memlog = old_memlog;
*val = (void*)(long)0;
}
return 0;
}
#endif
8 changes: 8 additions & 0 deletions pt.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,12 @@ int fork_process(int child_id,char *desc,int make_sock);
int fork_tcp_process(int child_id,char *desc,int r,int *reader_fd_1);
#endif

#ifdef PKG_MALLOC
void mem_dump_pkg_cb(str *name);
#endif

#ifdef SHM_MEM
int mem_dump_shm_fixup(void *handle, str *name, void **val);
#endif

#endif

0 comments on commit b4c9f98

Please sign in to comment.