Browse code

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 authored on 04/04/2008 08:40:53
Showing 4 changed files
... ...
@@ -38,6 +38,9 @@
38 38
 #ifdef USE_DNS_CACHE
39 39
 #include "dns_cache.h"
40 40
 #endif
41
+#if defined PKG_MALLOC || defined SHM_MEM
42
+#include "pt.h"
43
+#endif
41 44
 #include "cfg/cfg.h"
42 45
 #include "cfg_core.h"
43 46
 
... ...
@@ -78,6 +81,12 @@ struct cfg_group_core default_core_cfg = {
78 78
 	DEFAULT_DNS_MAX_MEM, /* dns_cache_max_mem */
79 79
 	0, /* dns_cache_del_nonexp -- delete only expired entries by default */
80 80
 #endif
81
+#ifdef PKG_MALLOC
82
+	0, /* mem_dump_pkg */
83
+#endif
84
+#ifdef SHM_MEM
85
+	0, /* mem_dump_shm */
86
+#endif
81 87
 };
82 88
 
83 89
 void	*core_cfg = &default_core_cfg;
... ...
@@ -157,5 +166,13 @@ cfg_def_t core_cfg_def[] = {
157 157
 		"allow deletion of non-expired records from the cache when "
158 158
 		"there is no more space left for new ones"},
159 159
 #endif
160
+#ifdef PKG_MALLOC
161
+	{"mem_dump_pkg",	CFG_VAR_INT,	0, 0, 0, mem_dump_pkg_cb,
162
+		"dump process memory status, parameter: pid_number"},
163
+#endif
164
+#ifdef SHM_MEM
165
+	{"mem_dump_shm",	CFG_VAR_INT,	0, 0, mem_dump_shm_fixup, 0,
166
+		"dump shared memory status"},
167
+#endif
160 168
 	{0, 0, 0, 0, 0, 0}
161 169
 };
... ...
@@ -78,6 +78,12 @@ struct cfg_group_core {
78 78
 	unsigned int dns_cache_max_mem;
79 79
 	int dns_cache_del_nonexp;
80 80
 #endif
81
+#ifdef PKG_MALLOC
82
+	int mem_dump_pkg;
83
+#endif
84
+#ifdef SHM_MEM
85
+	int mem_dump_shm;
86
+#endif
81 87
 };
82 88
 
83 89
 extern struct cfg_group_core default_core_cfg;
... ...
@@ -44,6 +44,15 @@
44 44
 #include "sr_module.h"
45 45
 #include "socket_info.h"
46 46
 #include "rand/fastrand.h"
47
+#ifdef PKG_MALLOC
48
+#include "mem/mem.h"
49
+#endif
50
+#ifdef SHM_MEM
51
+#include "mem/shm_mem.h"
52
+#endif
53
+#if defined PKG_MALLOC || defined SHM_MEM
54
+#include "cfg_core.h"
55
+#endif
47 56
 
48 57
 #include <stdio.h>
49 58
 #include <time.h> /* time(), used to initialize random numbers */
... ...
@@ -506,3 +515,51 @@ end:
506 506
 	return ret;
507 507
 }
508 508
 #endif
509
+
510
+#ifdef PKG_MALLOC
511
+/* Dumps pkg memory status.
512
+ * Per-child process callback that is called
513
+ * when mem_dump_pkg cfg var is changed.
514
+ */
515
+void mem_dump_pkg_cb(str *name)
516
+{
517
+	int	old_memlog;
518
+
519
+	if (cfg_get(core, core_cfg, mem_dump_pkg) == my_pid()) {
520
+		/* set memlog to ALERT level to force
521
+		printing the log messages */
522
+		old_memlog = memlog;
523
+		memlog = L_ALERT;
524
+
525
+		LOG(memlog, "Memory status (pkg) of process %d:\n", my_pid());
526
+		pkg_status();
527
+
528
+		memlog = old_memlog;
529
+	}
530
+}
531
+#endif
532
+
533
+#ifdef SHM_MEM
534
+/* Dumps shm memory status.
535
+ * fixup function that is called
536
+ * when mem_dump_shm cfg var is set.
537
+ */
538
+int mem_dump_shm_fixup(void *handle, str *name, void **val)
539
+{
540
+	int	old_memlog;
541
+
542
+	if ((long)(void*)(*val)) {
543
+		/* set memlog to ALERT level to force
544
+		printing the log messages */
545
+		old_memlog = memlog;
546
+		memlog = L_ALERT;
547
+
548
+		LOG(memlog, "Memory status (shm)\n");
549
+		shm_status();
550
+
551
+		memlog = old_memlog;
552
+		*val = (void*)(long)0;
553
+	}
554
+	return 0;
555
+}
556
+#endif
... ...
@@ -100,4 +100,12 @@ int fork_process(int child_id,char *desc,int make_sock);
100 100
 int fork_tcp_process(int child_id,char *desc,int r,int *reader_fd_1);
101 101
 #endif
102 102
 
103
+#ifdef PKG_MALLOC
104
+void mem_dump_pkg_cb(str *name);
105
+#endif
106
+
107
+#ifdef SHM_MEM
108
+int mem_dump_shm_fixup(void *handle, str *name, void **val);
109
+#endif
110
+
103 111
 #endif