Browse code

core: added mem_summary config option

- added mem_summary which controls the memory debugging info
logged on exit or on SIGUSR1. Its value is a combination of
flags: 0 - off, 1 - dump all used memory blocks and some
statistics (lots of output), 2 - dump a summary of the used
memory blocks (works only if compiled with DBG_QM_MALLOC or
DBG_F_MALLOC).
The default value is 1 (same behaviour as older versions).

- fix: don't call the memory status/summary functions if
memlog > debug level (since nothing will be logged anyway).

Andrei Pelinescu-Onciul authored on 29/09/2009 11:32:48
Showing 6 changed files
... ...
@@ -72,6 +72,13 @@ new config variables:
72 72
   - max_while_loops - maximum iterations allowed for a while  (can be changed
73 73
        at runtime). Default 100.
74 74
   - log_name - set the application name used when printing to syslog.
75
+  - mem_summary - memory debugging info logged on exit or on SIGUSR1.
76
+       The value is a combination of flags: 0 - off,
77
+       1 - dump all used memory blocks and some statistics (lots of output),
78
+       2 - dump a summary of the used memory blocks (works only if
79
+           compiled with DBG_QM_MALLOC or DBG_F_MALLOC).
80
+       Default: 1.
81
+       Can be changed at runtime.
75 82
 
76 83
 new script commands:
77 84
   add_local_rport() - adds the rport parameter to the added via header
... ...
@@ -353,6 +353,7 @@ PHONE2TEL	phone2tel
353 353
 SYN_BRANCH syn_branch
354 354
 MEMLOG		"memlog"|"mem_log"
355 355
 MEMDBG		"memdbg"|"mem_dbg"
356
+MEMSUM		"mem_summary"
356 357
 SIP_WARNING sip_warning
357 358
 SERVER_SIGNATURE server_signature
358 359
 SERVER_HEADER server_header
... ...
@@ -688,6 +689,7 @@ EAT_ABLE	[\ \t\b\r]
688 688
 <INITIAL>{SYN_BRANCH}	{ count(); yylval.strval=yytext; return SYN_BRANCH; }
689 689
 <INITIAL>{MEMLOG}	{ count(); yylval.strval=yytext; return MEMLOG; }
690 690
 <INITIAL>{MEMDBG}	{ count(); yylval.strval=yytext; return MEMDBG; }
691
+<INITIAL>{MEMSUM}	{ count(); yylval.strval=yytext; return MEMSUM; }
691 692
 <INITIAL>{SIP_WARNING}	{ count(); yylval.strval=yytext; return SIP_WARNING; }
692 693
 <INITIAL>{USER}		{ count(); yylval.strval=yytext; return USER; }
693 694
 <INITIAL>{GROUP}	{ count(); yylval.strval=yytext; return GROUP; }
... ...
@@ -408,6 +408,7 @@ extern char *finame;
408 408
 %token SYN_BRANCH
409 409
 %token MEMLOG
410 410
 %token MEMDBG
411
+%token MEMSUM
411 412
 %token SIP_WARNING
412 413
 %token SERVER_SIGNATURE
413 414
 %token SERVER_HEADER
... ...
@@ -863,6 +864,8 @@ assign_stm:
863 863
 	| MEMLOG EQUAL error { yyerror("int value expected"); }
864 864
 	| MEMDBG EQUAL intno { memdbg=$3; }
865 865
 	| MEMDBG EQUAL error { yyerror("int value expected"); }
866
+	| MEMSUM EQUAL intno { default_core_cfg.mem_summary=$3; }
867
+	| MEMSUM EQUAL error { yyerror("int value expected"); }
866 868
 	| SIP_WARNING EQUAL NUMBER { sip_warning=$3; }
867 869
 	| SIP_WARNING EQUAL error { yyerror("boolean value expected"); }
868 870
 	| USER EQUAL STRING     { user=$3; }
... ...
@@ -92,7 +92,8 @@ struct cfg_group_core default_core_cfg = {
92 92
 	DEFAULT_MAX_WHILE_LOOPS, /* max_while_loops */
93 93
 	0, /* udp_mtu (disabled by default) */
94 94
 	0, /* udp_mtu_try_proto -> default disabled */
95
-	0  /* force_rport */ 
95
+	0,  /* force_rport */
96
+	1 /* mem_summary -flags: 0 off, 1 shm/pkg_status, 2 shm/pkg_sums */
96 97
 };
97 98
 
98 99
 void	*core_cfg = &default_core_cfg;
... ...
@@ -191,5 +192,8 @@ cfg_def_t core_cfg_def[] = {
191 191
 		"if send size > udp_mtu use proto (1 udp, 2 tcp, 3 tls, 4 sctp)"},
192 192
 	{"force_rport",     CFG_VAR_INT, 0, 1,  0, fix_global_req_flags,
193 193
 		"force rport for all the received messages" },
194
+	{"mem_summary",	CFG_VAR_INT|CFG_ATOMIC,	0, 3, 0, 0,
195
+		"memory debugging information displayed on exit (flags): "
196
+		" 0 - off, 1 - dump all used blocks, 2 - summary of used blocks" },
194 197
 	{0, 0, 0, 0, 0, 0}
195 198
 };
... ...
@@ -89,6 +89,7 @@ struct cfg_group_core {
89 89
 	int udp_mtu; /**< maximum send size for udp, if > try another protocol*/
90 90
 	int udp_mtu_try_proto; /**< if packet> udp_mtu, try proto (e.g. TCP) */
91 91
 	int force_rport; /**< if set rport will always be forced*/
92
+	int mem_summary; /**< display memory status/summary info on exit */
92 93
 };
93 94
 
94 95
 extern struct cfg_group_core default_core_cfg;
... ...
@@ -529,21 +529,29 @@ void cleanup(show_status)
529 529
 	destroy_routes();
530 530
 	destroy_atomic_ops();
531 531
 #ifdef PKG_MALLOC
532
-	if (show_status){
533
-		LOG(memlog, "Memory status (pkg):\n");
534
-		pkg_status();
535
-		LOG(memlog, "Memory still-in-use summary (pkg):\n");
536
-		pkg_sums();
532
+	if (show_status && memlog <= cfg_get(core, core_cfg, debug)){
533
+		if (cfg_get(core, core_cfg, mem_summary) & 1) {
534
+			LOG(memlog, "Memory status (pkg):\n");
535
+			pkg_status();
536
+		}
537
+		if (cfg_get(core, core_cfg, mem_summary) & 2) {
538
+			LOG(memlog, "Memory still-in-use summary (pkg):\n");
539
+			pkg_sums();
540
+		}
537 541
 	}
538 542
 #endif
539 543
 #ifdef SHM_MEM
540 544
 	if (pt) shm_free(pt);
541 545
 	pt=0;
542
-	if (show_status){
546
+	if (show_status && memlog <= cfg_get(core, core_cfg, debug)){
547
+		if (cfg_get(core, core_cfg, mem_summary) & 1) {
543 548
 			LOG(memlog, "Memory status (shm):\n");
544 549
 			shm_status();
550
+		}
551
+		if (cfg_get(core, core_cfg, mem_summary) & 2) {
545 552
 			LOG(memlog, "Memory still-in-use summary (shm):\n");
546 553
 			shm_sums();
554
+		}
547 555
 	}
548 556
 	/* zero all shmem alloc vars that we still use */
549 557
 	shm_mem_destroy();
... ...
@@ -664,12 +672,28 @@ void handle_sigs()
664 664
 			dump_all_statistic();
665 665
 #endif
666 666
 #ifdef PKG_MALLOC
667
-			LOG(memlog, "Memory status (pkg):\n");
668
-			pkg_status();
667
+		if (memlog <= cfg_get(core, core_cfg, debug)){
668
+			if (cfg_get(core, core_cfg, mem_summary) & 1) {
669
+				LOG(memlog, "Memory status (pkg):\n");
670
+				pkg_status();
671
+			}
672
+			if (cfg_get(core, core_cfg, mem_summary) & 2) {
673
+				LOG(memlog, "Memory still-in-use summary (pkg):\n");
674
+				pkg_sums();
675
+			}
676
+		}
669 677
 #endif
670 678
 #ifdef SHM_MEM
671
-			LOG(memlog, "Memory status (shm):\n");
672
-			shm_status();
679
+		if (memlog <= cfg_get(core, core_cfg, debug)){
680
+			if (cfg_get(core, core_cfg, mem_summary) & 1) {
681
+				LOG(memlog, "Memory status (shm):\n");
682
+				shm_status();
683
+			}
684
+			if (cfg_get(core, core_cfg, mem_summary) & 2) {
685
+				LOG(memlog, "Memory still-in-use summary (shm):\n");
686
+				shm_sums();
687
+			}
688
+		}
673 689
 #endif
674 690
 			break;
675 691
 
... ...
@@ -747,8 +771,17 @@ void sig_usr(int signo)
747 747
 					LOG(L_INFO, "INFO: signal %d received\n", signo);
748 748
 					/* print memory stats for non-main too */
749 749
 					#ifdef PKG_MALLOC
750
-					LOG(memlog, "Memory status (pkg):\n");
751
-					pkg_status();
750
+					if (memlog <= cfg_get(core, core_cfg, debug)){
751
+						if (cfg_get(core, core_cfg, mem_summary) & 1) {
752
+							LOG(memlog, "Memory status (pkg):\n");
753
+							pkg_status();
754
+						}
755
+						if (cfg_get(core, core_cfg, mem_summary) & 2) {
756
+							LOG(memlog, "Memory still-in-use summary (pkg):"
757
+									"\n");
758
+							pkg_sums();
759
+						}
760
+					}
752 761
 					#endif
753 762
 #endif
754 763
 					_exit(0);