Browse code

core: new core parameter latency_cfg_log

- if set to a log level less or equal than debug parameter, a log
message with the duration of executing request route or reply route is
printed to syslog
- default value is L_DBG

Daniel-Constantin Mierla authored on 25/04/2016 14:57:19
Showing 5 changed files
... ...
@@ -440,6 +440,7 @@ SERVER_ID     "server_id"
440 440
 MAX_RECURSIVE_LEVEL		"max_recursive_level"
441 441
 MAX_BRANCHES_PARAM		"max_branches"|"max_branches"
442 442
 
443
+LATENCY_CFG_LOG			latency_cfg_log
443 444
 LATENCY_LOG				latency_log
444 445
 LATENCY_LIMIT_DB		latency_limit_db
445 446
 LATENCY_LIMIT_ACTION	latency_limit_action
... ...
@@ -910,6 +911,7 @@ IMPORTFILE      "import_file"
910 910
 <INITIAL>{MAX_RECURSIVE_LEVEL}  { count(); yylval.strval=yytext; return MAX_RECURSIVE_LEVEL;}
911 911
 <INITIAL>{MAX_BRANCHES_PARAM}  { count(); yylval.strval=yytext; return MAX_BRANCHES_PARAM;}
912 912
 <INITIAL>{LATENCY_LOG}  { count(); yylval.strval=yytext; return LATENCY_LOG;}
913
+<INITIAL>{LATENCY_CFG_LOG}  { count(); yylval.strval=yytext; return LATENCY_CFG_LOG;}
913 914
 <INITIAL>{MSG_TIME}  { count(); yylval.strval=yytext; return MSG_TIME;}
914 915
 <INITIAL>{ONSEND_RT_REPLY}	{ count(); yylval.strval=yytext; return ONSEND_RT_REPLY; }
915 916
 <INITIAL>{LATENCY_LIMIT_DB}  { count(); yylval.strval=yytext; return LATENCY_LIMIT_DB;}
... ...
@@ -476,6 +476,7 @@ extern char *default_routename;
476 476
 %token SERVER_ID
477 477
 %token MAX_RECURSIVE_LEVEL
478 478
 %token MAX_BRANCHES_PARAM
479
+%token LATENCY_CFG_LOG
479 480
 %token LATENCY_LOG
480 481
 %token LATENCY_LIMIT_DB
481 482
 %token LATENCY_LIMIT_ACTION
... ...
@@ -1521,6 +1522,8 @@ assign_stm:
1521 1521
     | MAX_BRANCHES_PARAM EQUAL NUMBER { sr_dst_max_branches = $3; }
1522 1522
     | LATENCY_LOG EQUAL NUMBER { default_core_cfg.latency_log=$3; }
1523 1523
 	| LATENCY_LOG EQUAL error  { yyerror("number  expected"); }
1524
+    | LATENCY_CFG_LOG EQUAL NUMBER { default_core_cfg.latency_cfg_log=$3; }
1525
+	| LATENCY_CFG_LOG EQUAL error  { yyerror("number  expected"); }
1524 1526
     | LATENCY_LIMIT_DB EQUAL NUMBER { default_core_cfg.latency_limit_db=$3; }
1525 1527
 	| LATENCY_LIMIT_DB EQUAL error  { yyerror("number  expected"); }
1526 1528
     | LATENCY_LIMIT_ACTION EQUAL NUMBER { default_core_cfg.latency_limit_action=$3; }
... ...
@@ -1531,7 +1534,7 @@ assign_stm:
1531 1531
 	| ONSEND_RT_REPLY EQUAL error { yyerror("int value expected"); }
1532 1532
 	| UDP_MTU EQUAL NUMBER { default_core_cfg.udp_mtu=$3; }
1533 1533
 	| UDP_MTU EQUAL error { yyerror("number expected"); }
1534
-	| FORCE_RPORT EQUAL NUMBER 
1534
+	| FORCE_RPORT EQUAL NUMBER
1535 1535
 		{ default_core_cfg.force_rport=$3; fix_global_req_flags(0, 0); }
1536 1536
 	| FORCE_RPORT EQUAL error { yyerror("boolean value expected"); }
1537 1537
 	| UDP_MTU_TRY_PROTO EQUAL proto
... ...
@@ -116,6 +116,7 @@ struct cfg_group_core default_core_cfg = {
116 116
 	0, /*!< mem_safety - 0 disabled */
117 117
 	0, /*!< mem_join - 0 disabled */
118 118
 	L_ERR, /*!< corelog */
119
+	L_DBG, /*!< latency cfg log */
119 120
 	L_ERR, /*!< latency log */
120 121
 	0, /*!< latency limit db */
121 122
 	0 /*!< latency limit action */
... ...
@@ -128,7 +129,7 @@ static int check_raw_sock_support(void* cfg_h, str* gname, str* name,
128 128
 									void** v)
129 129
 {
130 130
 	int val;
131
-	
131
+
132 132
 	val = (int)(long)(*v);
133 133
 #ifndef USE_RAW_SOCKS
134 134
 	if (val > 0) {
... ...
@@ -314,6 +315,8 @@ cfg_def_t core_cfg_def[] = {
314 314
 		"join free memory fragments"},
315 315
 	{"corelog",		CFG_VAR_INT|CFG_ATOMIC,	0, 0, 0, 0,
316 316
 		"log level for non-critical core error messages"},
317
+	{"latency_cfg_log",		CFG_VAR_INT|CFG_ATOMIC,	0, 0, 0, 0,
318
+		"log level for printing latency of routing blocks"},
317 319
 	{"latency_log",		CFG_VAR_INT|CFG_ATOMIC,	0, 0, 0, 0,
318 320
 		"log level for latency limits alert messages"},
319 321
 	{"latency_limit_db",		CFG_VAR_INT|CFG_ATOMIC,	0, 0, 0, 0,
... ...
@@ -104,6 +104,7 @@ struct cfg_group_core {
104 104
 	int mem_safety; /*!< memory safety control option */
105 105
 	int mem_join; /*!< memory free fragments join option */
106 106
 	int corelog; /*!< log level for non-critcal core error messages */
107
+	int latency_cfg_log; /*!< log level for printing latency of routing blocks */
107 108
 	int latency_log; /*!< log level for latency limits messages */
108 109
 	int latency_limit_db; /*!< alert limit of running db commands */
109 110
 	int latency_limit_action; /*!< alert limit of running cfg actions */
... ...
@@ -121,10 +121,13 @@ int receive_msg(char* buf, unsigned int len, struct receive_info* rcv_info)
121 121
 	int ret;
122 122
 #ifdef STATS
123 123
 	int skipped = 1;
124
+	int stats_on = 1;
125
+#else
126
+	int stats_on = 0;
127
+#endif
124 128
 	struct timeval tvb, tve;
125 129
 	struct timezone tz;
126
-	unsigned int diff;
127
-#endif
130
+	unsigned int diff = 0;
128 131
 	str inb;
129 132
 	sr_net_info_t netinfo;
130 133
 	sr_kemi_eng_t *keng = NULL;
... ...
@@ -222,9 +225,10 @@ int receive_msg(char* buf, unsigned int len, struct receive_info* rcv_info)
222 222
 
223 223
 	/*	skip: */
224 224
 		LM_DBG("preparing to run routing scripts...\n");
225
-#ifdef  STATS
226
-		gettimeofday( & tvb, &tz );
227
-#endif
225
+		if(is_printable(cfg_get(core, core_cfg, latency_cfg_log))
226
+				|| stats_on==1) {
227
+			gettimeofday( & tvb, &tz );
228
+		}
228 229
 		/* execute pre-script callbacks, if any; -jiri */
229 230
 		/* if some of the callbacks said not to continue with
230 231
 		 * script processing, don't do so
... ...
@@ -256,14 +260,18 @@ int receive_msg(char* buf, unsigned int len, struct receive_info* rcv_info)
256 256
 			}
257 257
 		}
258 258
 
259
+		if(is_printable(cfg_get(core, core_cfg, latency_cfg_log))
260
+				|| stats_on==1) {
261
+			gettimeofday( & tve, &tz );
262
+			diff = (tve.tv_sec-tvb.tv_sec)*1000000+(tve.tv_usec-tvb.tv_usec);
263
+			LOG(cfg_get(core, core_cfg, latency_cfg_log),
264
+					"request-route executed in: %d usec\n", diff);
259 265
 #ifdef STATS
260
-		gettimeofday( & tve, &tz );
261
-		diff = (tve.tv_sec-tvb.tv_sec)*1000000+(tve.tv_usec-tvb.tv_usec);
262
-		stats->processed_requests++;
263
-		stats->acc_req_time += diff;
264
-		LM_DBG("successfully ran routing scripts...(%d usec)\n", diff);
265
-		STATS_RX_REQUEST( msg->first_line.u.request.method_value );
266
+			stats->processed_requests++;
267
+			stats->acc_req_time += diff;
268
+			STATS_RX_REQUEST( msg->first_line.u.request.method_value );
266 269
 #endif
270
+		}
267 271
 
268 272
 		/* execute post request-script callbacks */
269 273
 		exec_post_script_cb(msg, REQUEST_CB_TYPE);
... ...
@@ -276,8 +284,11 @@ int receive_msg(char* buf, unsigned int len, struct receive_info* rcv_info)
276 276
 			goto error02;
277 277
 		}
278 278
 
279
+		if(is_printable(cfg_get(core, core_cfg, latency_cfg_log))
280
+				|| stats_on==1) {
281
+			gettimeofday( & tvb, &tz );
282
+		}
279 283
 #ifdef STATS
280
-		gettimeofday( & tvb, &tz );
281 284
 		STATS_RX_RESPONSE ( msg->first_line.u.reply.statuscode / 100 );
282 285
 #endif
283 286
 
... ...
@@ -322,13 +333,17 @@ int receive_msg(char* buf, unsigned int len, struct receive_info* rcv_info)
322 322
 		/* send the msg */
323 323
 		forward_reply(msg);
324 324
 	skip_send_reply:
325
+		if(is_printable(cfg_get(core, core_cfg, latency_cfg_log))
326
+				|| stats_on==1) {
327
+			gettimeofday( & tve, &tz );
328
+			diff = (tve.tv_sec-tvb.tv_sec)*1000000+(tve.tv_usec-tvb.tv_usec);
329
+			LOG(cfg_get(core, core_cfg, latency_cfg_log),
330
+					"reply-route executed in: %d usec\n", diff);
325 331
 #ifdef STATS
326
-		gettimeofday( & tve, &tz );
327
-		diff = (tve.tv_sec-tvb.tv_sec)*1000000+(tve.tv_usec-tvb.tv_usec);
328
-		stats->processed_responses++;
329
-		stats->acc_res_time+=diff;
330
-		LM_DBG("successfully ran reply processing...(%d usec)\n", diff);
332
+			stats->processed_responses++;
333
+			stats->acc_res_time+=diff;
331 334
 #endif
335
+		}
332 336
 
333 337
 		/* execute post reply-script callbacks */
334 338
 		exec_post_script_cb(msg, ONREPLY_CB_TYPE);