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 911
 <INITIAL>{MAX_RECURSIVE_LEVEL}  { count(); yylval.strval=yytext; return MAX_RECURSIVE_LEVEL;}
911 912
 <INITIAL>{MAX_BRANCHES_PARAM}  { count(); yylval.strval=yytext; return MAX_BRANCHES_PARAM;}
912 913
 <INITIAL>{LATENCY_LOG}  { count(); yylval.strval=yytext; return LATENCY_LOG;}
914
+<INITIAL>{LATENCY_CFG_LOG}  { count(); yylval.strval=yytext; return LATENCY_CFG_LOG;}
913 915
 <INITIAL>{MSG_TIME}  { count(); yylval.strval=yytext; return MSG_TIME;}
914 916
 <INITIAL>{ONSEND_RT_REPLY}	{ count(); yylval.strval=yytext; return ONSEND_RT_REPLY; }
915 917
 <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 1522
     | MAX_BRANCHES_PARAM EQUAL NUMBER { sr_dst_max_branches = $3; }
1522 1523
     | LATENCY_LOG EQUAL NUMBER { default_core_cfg.latency_log=$3; }
1523 1524
 	| LATENCY_LOG EQUAL error  { yyerror("number  expected"); }
1525
+    | LATENCY_CFG_LOG EQUAL NUMBER { default_core_cfg.latency_cfg_log=$3; }
1526
+	| LATENCY_CFG_LOG EQUAL error  { yyerror("number  expected"); }
1524 1527
     | LATENCY_LIMIT_DB EQUAL NUMBER { default_core_cfg.latency_limit_db=$3; }
1525 1528
 	| LATENCY_LIMIT_DB EQUAL error  { yyerror("number  expected"); }
1526 1529
     | LATENCY_LIMIT_ACTION EQUAL NUMBER { default_core_cfg.latency_limit_action=$3; }
... ...
@@ -1531,7 +1534,7 @@ assign_stm:
1531 1534
 	| ONSEND_RT_REPLY EQUAL error { yyerror("int value expected"); }
1532 1535
 	| UDP_MTU EQUAL NUMBER { default_core_cfg.udp_mtu=$3; }
1533 1536
 	| UDP_MTU EQUAL error { yyerror("number expected"); }
1534
-	| FORCE_RPORT EQUAL NUMBER 
1537
+	| FORCE_RPORT EQUAL NUMBER
1535 1538
 		{ default_core_cfg.force_rport=$3; fix_global_req_flags(0, 0); }
1536 1539
 	| FORCE_RPORT EQUAL error { yyerror("boolean value expected"); }
1537 1540
 	| 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 129
 									void** v)
129 130
 {
130 131
 	int val;
131
-	
132
+
132 133
 	val = (int)(long)(*v);
133 134
 #ifndef USE_RAW_SOCKS
134 135
 	if (val > 0) {
... ...
@@ -314,6 +315,8 @@ cfg_def_t core_cfg_def[] = {
314 315
 		"join free memory fragments"},
315 316
 	{"corelog",		CFG_VAR_INT|CFG_ATOMIC,	0, 0, 0, 0,
316 317
 		"log level for non-critical core error messages"},
318
+	{"latency_cfg_log",		CFG_VAR_INT|CFG_ATOMIC,	0, 0, 0, 0,
319
+		"log level for printing latency of routing blocks"},
317 320
 	{"latency_log",		CFG_VAR_INT|CFG_ATOMIC,	0, 0, 0, 0,
318 321
 		"log level for latency limits alert messages"},
319 322
 	{"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 225
 
223 226
 	/*	skip: */
224 227
 		LM_DBG("preparing to run routing scripts...\n");
225
-#ifdef  STATS
226
-		gettimeofday( & tvb, &tz );
227
-#endif
228
+		if(is_printable(cfg_get(core, core_cfg, latency_cfg_log))
229
+				|| stats_on==1) {
230
+			gettimeofday( & tvb, &tz );
231
+		}
228 232
 		/* execute pre-script callbacks, if any; -jiri */
229 233
 		/* if some of the callbacks said not to continue with
230 234
 		 * script processing, don't do so
... ...
@@ -256,14 +260,18 @@ int receive_msg(char* buf, unsigned int len, struct receive_info* rcv_info)
256 260
 			}
257 261
 		}
258 262
 
263
+		if(is_printable(cfg_get(core, core_cfg, latency_cfg_log))
264
+				|| stats_on==1) {
265
+			gettimeofday( & tve, &tz );
266
+			diff = (tve.tv_sec-tvb.tv_sec)*1000000+(tve.tv_usec-tvb.tv_usec);
267
+			LOG(cfg_get(core, core_cfg, latency_cfg_log),
268
+					"request-route executed in: %d usec\n", diff);
259 269
 #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 );
270
+			stats->processed_requests++;
271
+			stats->acc_req_time += diff;
272
+			STATS_RX_REQUEST( msg->first_line.u.request.method_value );
266 273
 #endif
274
+		}
267 275
 
268 276
 		/* execute post request-script callbacks */
269 277
 		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 284
 			goto error02;
277 285
 		}
278 286
 
287
+		if(is_printable(cfg_get(core, core_cfg, latency_cfg_log))
288
+				|| stats_on==1) {
289
+			gettimeofday( & tvb, &tz );
290
+		}
279 291
 #ifdef STATS
280
-		gettimeofday( & tvb, &tz );
281 292
 		STATS_RX_RESPONSE ( msg->first_line.u.reply.statuscode / 100 );
282 293
 #endif
283 294
 
... ...
@@ -322,13 +333,17 @@ int receive_msg(char* buf, unsigned int len, struct receive_info* rcv_info)
322 333
 		/* send the msg */
323 334
 		forward_reply(msg);
324 335
 	skip_send_reply:
336
+		if(is_printable(cfg_get(core, core_cfg, latency_cfg_log))
337
+				|| stats_on==1) {
338
+			gettimeofday( & tve, &tz );
339
+			diff = (tve.tv_sec-tvb.tv_sec)*1000000+(tve.tv_usec-tvb.tv_usec);
340
+			LOG(cfg_get(core, core_cfg, latency_cfg_log),
341
+					"reply-route executed in: %d usec\n", diff);
325 342
 #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);
343
+			stats->processed_responses++;
344
+			stats->acc_res_time+=diff;
331 345
 #endif
346
+		}
332 347
 
333 348
 		/* execute post reply-script callbacks */
334 349
 		exec_post_script_cb(msg, ONREPLY_CB_TYPE);