Browse Source

Two configuration variables are introduced that can help
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

Miklos Tirpak 17 years ago
parent
commit
b4c9f986dd
4 changed files with 88 additions and 0 deletions
  1. 17 0
      cfg_core.c
  2. 6 0
      cfg_core.h
  3. 57 0
      pt.c
  4. 8 0
      pt.h

+ 17 - 0
cfg_core.c

@@ -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"
 
@@ -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;
@@ -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 - 0
cfg_core.h

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

+ 57 - 0
pt.c

@@ -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 */
@@ -506,3 +515,51 @@ end:
 	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 - 0
pt.h

@@ -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