Procházet zdrojové kódy

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 před 16 roky
rodič
revize
d740c34e41
6 změnil soubory, kde provedl 63 přidání a 13 odebrání
  1. 7 0
      NEWS
  2. 2 0
      cfg.lex
  3. 3 0
      cfg.y
  4. 5 1
      cfg_core.c
  5. 1 0
      cfg_core.h
  6. 45 12
      main.c

+ 7 - 0
NEWS

@@ -72,6 +72,13 @@ new config variables:
   - max_while_loops - maximum iterations allowed for a while  (can be changed
        at runtime). Default 100.
   - log_name - set the application name used when printing to syslog.
+  - mem_summary - memory debugging info logged on exit or on SIGUSR1.
+       The 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).
+       Default: 1.
+       Can be changed at runtime.
 
 new script commands:
   add_local_rport() - adds the rport parameter to the added via header

+ 2 - 0
cfg.lex

@@ -353,6 +353,7 @@ PHONE2TEL	phone2tel
 SYN_BRANCH syn_branch
 MEMLOG		"memlog"|"mem_log"
 MEMDBG		"memdbg"|"mem_dbg"
+MEMSUM		"mem_summary"
 SIP_WARNING sip_warning
 SERVER_SIGNATURE server_signature
 SERVER_HEADER server_header
@@ -688,6 +689,7 @@ EAT_ABLE	[\ \t\b\r]
 <INITIAL>{SYN_BRANCH}	{ count(); yylval.strval=yytext; return SYN_BRANCH; }
 <INITIAL>{MEMLOG}	{ count(); yylval.strval=yytext; return MEMLOG; }
 <INITIAL>{MEMDBG}	{ count(); yylval.strval=yytext; return MEMDBG; }
+<INITIAL>{MEMSUM}	{ count(); yylval.strval=yytext; return MEMSUM; }
 <INITIAL>{SIP_WARNING}	{ count(); yylval.strval=yytext; return SIP_WARNING; }
 <INITIAL>{USER}		{ count(); yylval.strval=yytext; return USER; }
 <INITIAL>{GROUP}	{ count(); yylval.strval=yytext; return GROUP; }

+ 3 - 0
cfg.y

@@ -408,6 +408,7 @@ extern char *finame;
 %token SYN_BRANCH
 %token MEMLOG
 %token MEMDBG
+%token MEMSUM
 %token SIP_WARNING
 %token SERVER_SIGNATURE
 %token SERVER_HEADER
@@ -863,6 +864,8 @@ assign_stm:
 	| MEMLOG EQUAL error { yyerror("int value expected"); }
 	| MEMDBG EQUAL intno { memdbg=$3; }
 	| MEMDBG EQUAL error { yyerror("int value expected"); }
+	| MEMSUM EQUAL intno { default_core_cfg.mem_summary=$3; }
+	| MEMSUM EQUAL error { yyerror("int value expected"); }
 	| SIP_WARNING EQUAL NUMBER { sip_warning=$3; }
 	| SIP_WARNING EQUAL error { yyerror("boolean value expected"); }
 	| USER EQUAL STRING     { user=$3; }

+ 5 - 1
cfg_core.c

@@ -92,7 +92,8 @@ struct cfg_group_core default_core_cfg = {
 	DEFAULT_MAX_WHILE_LOOPS, /* max_while_loops */
 	0, /* udp_mtu (disabled by default) */
 	0, /* udp_mtu_try_proto -> default disabled */
-	0  /* force_rport */ 
+	0,  /* force_rport */
+	1 /* mem_summary -flags: 0 off, 1 shm/pkg_status, 2 shm/pkg_sums */
 };
 
 void	*core_cfg = &default_core_cfg;
@@ -191,5 +192,8 @@ cfg_def_t core_cfg_def[] = {
 		"if send size > udp_mtu use proto (1 udp, 2 tcp, 3 tls, 4 sctp)"},
 	{"force_rport",     CFG_VAR_INT, 0, 1,  0, fix_global_req_flags,
 		"force rport for all the received messages" },
+	{"mem_summary",	CFG_VAR_INT|CFG_ATOMIC,	0, 3, 0, 0,
+		"memory debugging information displayed on exit (flags): "
+		" 0 - off, 1 - dump all used blocks, 2 - summary of used blocks" },
 	{0, 0, 0, 0, 0, 0}
 };

+ 1 - 0
cfg_core.h

@@ -89,6 +89,7 @@ struct cfg_group_core {
 	int udp_mtu; /**< maximum send size for udp, if > try another protocol*/
 	int udp_mtu_try_proto; /**< if packet> udp_mtu, try proto (e.g. TCP) */
 	int force_rport; /**< if set rport will always be forced*/
+	int mem_summary; /**< display memory status/summary info on exit */
 };
 
 extern struct cfg_group_core default_core_cfg;

+ 45 - 12
main.c

@@ -529,21 +529,29 @@ void cleanup(show_status)
 	destroy_routes();
 	destroy_atomic_ops();
 #ifdef PKG_MALLOC
-	if (show_status){
-		LOG(memlog, "Memory status (pkg):\n");
-		pkg_status();
-		LOG(memlog, "Memory still-in-use summary (pkg):\n");
-		pkg_sums();
+	if (show_status && memlog <= cfg_get(core, core_cfg, debug)){
+		if (cfg_get(core, core_cfg, mem_summary) & 1) {
+			LOG(memlog, "Memory status (pkg):\n");
+			pkg_status();
+		}
+		if (cfg_get(core, core_cfg, mem_summary) & 2) {
+			LOG(memlog, "Memory still-in-use summary (pkg):\n");
+			pkg_sums();
+		}
 	}
 #endif
 #ifdef SHM_MEM
 	if (pt) shm_free(pt);
 	pt=0;
-	if (show_status){
+	if (show_status && memlog <= cfg_get(core, core_cfg, debug)){
+		if (cfg_get(core, core_cfg, mem_summary) & 1) {
 			LOG(memlog, "Memory status (shm):\n");
 			shm_status();
+		}
+		if (cfg_get(core, core_cfg, mem_summary) & 2) {
 			LOG(memlog, "Memory still-in-use summary (shm):\n");
 			shm_sums();
+		}
 	}
 	/* zero all shmem alloc vars that we still use */
 	shm_mem_destroy();
@@ -664,12 +672,28 @@ void handle_sigs()
 			dump_all_statistic();
 #endif
 #ifdef PKG_MALLOC
-			LOG(memlog, "Memory status (pkg):\n");
-			pkg_status();
+		if (memlog <= cfg_get(core, core_cfg, debug)){
+			if (cfg_get(core, core_cfg, mem_summary) & 1) {
+				LOG(memlog, "Memory status (pkg):\n");
+				pkg_status();
+			}
+			if (cfg_get(core, core_cfg, mem_summary) & 2) {
+				LOG(memlog, "Memory still-in-use summary (pkg):\n");
+				pkg_sums();
+			}
+		}
 #endif
 #ifdef SHM_MEM
-			LOG(memlog, "Memory status (shm):\n");
-			shm_status();
+		if (memlog <= cfg_get(core, core_cfg, debug)){
+			if (cfg_get(core, core_cfg, mem_summary) & 1) {
+				LOG(memlog, "Memory status (shm):\n");
+				shm_status();
+			}
+			if (cfg_get(core, core_cfg, mem_summary) & 2) {
+				LOG(memlog, "Memory still-in-use summary (shm):\n");
+				shm_sums();
+			}
+		}
 #endif
 			break;
 
@@ -747,8 +771,17 @@ void sig_usr(int signo)
 					LOG(L_INFO, "INFO: signal %d received\n", signo);
 					/* print memory stats for non-main too */
 					#ifdef PKG_MALLOC
-					LOG(memlog, "Memory status (pkg):\n");
-					pkg_status();
+					if (memlog <= cfg_get(core, core_cfg, debug)){
+						if (cfg_get(core, core_cfg, mem_summary) & 1) {
+							LOG(memlog, "Memory status (pkg):\n");
+							pkg_status();
+						}
+						if (cfg_get(core, core_cfg, mem_summary) & 2) {
+							LOG(memlog, "Memory still-in-use summary (pkg):"
+									"\n");
+							pkg_sums();
+						}
+					}
 					#endif
 #endif
 					_exit(0);