Browse code

core: stats events cbs are called only if USE_CORE_STATS is defined

Use macros instead of triggering directly various SREV_CORE_STATS
callbacks. This way if compiled without core stats support
(USE_CORE_STATS), there will be no performance impact (the macros
will be empty). All the macros are defined in core_stats.h.

Andrei Pelinescu-Onciul authored on 01/02/2010 17:20:10
Showing 5 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,99 @@
1
+/* 
2
+ * $Id$
3
+ * 
4
+ * Copyright (C) 2010 iptelorg GmbH
5
+ *
6
+ * Permission to use, copy, modify, and distribute this software for any
7
+ * purpose with or without fee is hereby granted, provided that the above
8
+ * copyright notice and this permission notice appear in all copies.
9
+ *
10
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17
+ */
18
+/**  macros used for various core statistics.
19
+ *  (if USE_CORE_STATS is not defined they won't do anything)
20
+ * @file core_stats.h
21
+ * @ingroup core
22
+ */
23
+/*
24
+ * History:
25
+ * --------
26
+ *  2010-02-01  initial version (andrei)
27
+*/
28
+
29
+#ifndef __core_stats_h
30
+#define __core_stats_h
31
+
32
+/* define USE_CORE_STATS to enable statistics events 
33
+   (SREV_CORE_STATS callbacks) */
34
+/*#define USE_CORE_STATS */
35
+
36
+#ifndef USE_CORE_STATS
37
+
38
+#define STATS_REQ_FWD_DROP()
39
+#define STATS_REQ_FWD_OK()
40
+#define STATS_RPL_FWD_DROP()
41
+#define STATS_RPL_FWD_OK()
42
+#define STATS_BAD_MSG()
43
+#define STATS_BAD_RPL()
44
+#define STATS_BAD_URI()
45
+#define STATS_BAD_MSG_HDR()
46
+
47
+#else /* USE_CORE_STATS */
48
+
49
+#include "events.h"
50
+
51
+/** called each time a received request is dropped.
52
+ * The request might be dropped explicitly (e.g. pre script callback)
53
+ * or there might be an error while trying to forward it (e.g. send).
54
+ */
55
+#define STATS_REQ_FWD_DROP() sr_event_exec(SREV_CORE_STATS, (void*)3)
56
+
57
+
58
+/** called each time forwarding a request succeeds (send).*/
59
+#define STATS_REQ_FWD_OK() sr_event_exec(SREV_CORE_STATS, (void*)1)
60
+
61
+
62
+/** called each time forwarding a reply fails.
63
+ * The reply forwarding might fail due to send errors,
64
+ * pre script callbacks (module denying forwarding) or explicit script
65
+ * drop (drop or module function returning 0).
66
+ */
67
+#define STATS_RPL_FWD_DROP() sr_event_exec(SREV_CORE_STATS, (void*)4)
68
+
69
+
70
+/* called each time forwarding a reply succeeds. */
71
+#define STATS_RPL_FWD_OK() sr_event_exec(SREV_CORE_STATS, (void*)2)
72
+
73
+
74
+/** called each time a received request is too bad to process.
75
+  * For now it's called in case the message does not have any via.
76
+  */
77
+#define STATS_BAD_MSG() sr_event_exec(SREV_CORE_STATS, (void*)5)
78
+
79
+
80
+/** called each time a received reply is too bad to process.
81
+  * For now it's called in case the message does not have any via.
82
+  */
83
+#define STATS_BAD_RPL() sr_event_exec(SREV_CORE_STATS, (void*)6)
84
+
85
+
86
+/** called each time uri parsing fails. */
87
+#define STATS_BAD_URI() sr_event_exec(SREV_CORE_STATS, (void*)7)
88
+
89
+
90
+/** called each time parsing some header fails. */
91
+#define STATS_BAD_MSG_HDR() sr_event_exec(SREV_CORE_STATS, (void*)8)
92
+
93
+
94
+
95
+#endif /* USE_CORE_STATS */
96
+
97
+#endif /*__core_stats_h*/
98
+
99
+/* vi: set ts=4 sw=4 tw=79:ai:cindent: */
... ...
@@ -94,6 +94,7 @@
94 94
 #include "dst_blacklist.h"
95 95
 #endif
96 96
 #include "compiler_opt.h"
97
+#include "core_stats.h"
97 98
 
98 99
 #ifdef DEBUG_DMALLOC
99 100
 #include <dmalloc.h>
... ...
@@ -582,10 +583,12 @@ end:
582 583
 #endif
583 584
 	if (buf) pkg_free(buf);
584 585
 	/* received_buf & line_buf will be freed in receive_msg by free_lump_list*/
586
+#if defined STATS_REQ_FWD_OK || defined STATS_REQ_FWD_DROP
585 587
 	if(ret==0)
586
-		sr_event_exec(SREV_CORE_STATS, (void*)1);
588
+		STATS_REQ_FWD_OK();
587 589
 	else
588
-		sr_event_exec(SREV_CORE_STATS, (void*)3);
590
+		STATS_REQ_FWD_DROP();
591
+#endif /* STATS_REQ_FWD_* */
589 592
 	return ret;
590 593
 }
591 594
 
... ...
@@ -740,7 +743,7 @@ int forward_reply(struct sip_msg* msg)
740 743
 #endif
741 744
 	if (msg_send(&dst, new_buf, new_len)<0)
742 745
 	{
743
-		sr_event_exec(SREV_CORE_STATS, (void*)4);
746
+		STATS_RPL_FWD_DROP();
744 747
 		goto error;
745 748
 	}
746 749
 #ifdef STATS
... ...
@@ -751,7 +754,7 @@ int forward_reply(struct sip_msg* msg)
751 754
 			msg->via2->host.len, msg->via2->host.s,
752 755
 			(unsigned short) msg->via2->port);
753 756
 
754
-	sr_event_exec(SREV_CORE_STATS, (void*)2);
757
+	STATS_RPL_FWD_OK();
755 758
 	pkg_free(new_buf);
756 759
 skip:
757 760
 	return 0;
... ...
@@ -54,7 +54,7 @@
54 54
 #include "../data_lump_rpl.h"
55 55
 #include "../mem/mem.h"
56 56
 #include "../error.h"
57
-#include "../events.h"
57
+#include "../core_stats.h"
58 58
 #include "../globals.h"
59 59
 #include "parse_hname2.h"
60 60
 #include "parse_uri.h"
... ...
@@ -279,7 +279,7 @@ char* get_hdr_field(char* buf, char* end, struct hdr_field* hdr)
279 279
 	return tmp;
280 280
 error:
281 281
 	DBG("get_hdr_field: error exit\n");
282
-	sr_event_exec(SREV_CORE_STATS, (void*)8);
282
+	STATS_BAD_MSG_HDR();
283 283
 	hdr->type=HDR_ERROR_T;
284 284
 	hdr->len=tmp-hdr->name.s;
285 285
 	return tmp;
... ...
@@ -50,7 +50,7 @@
50 50
 #include "../ut.h"   /* q_memchr */
51 51
 /* #endif */
52 52
 #include "../error.h"
53
-#include "../events.h"
53
+#include "../core_stats.h"
54 54
 
55 55
 /* buf= pointer to begining of uri (sip:x@foo.bar:5060;a=b?h=i)
56 56
  * len= len of uri
... ...
@@ -1224,7 +1224,7 @@ error_bug:
1224 1224
 error_exit:
1225 1225
 	ser_error=E_BAD_URI;
1226 1226
 	uri->type=ERROR_URI_T;
1227
-	sr_event_exec(SREV_CORE_STATS, (void*)7);
1227
+	STATS_BAD_URI();
1228 1228
 	return E_BAD_URI;
1229 1229
 }
1230 1230
 
... ...
@@ -64,6 +64,7 @@
64 64
 #include "tcp_server.h" /* for tcpconn_add_alias */
65 65
 #include "tcp_options.h" /* for access to tcp_accept_aliases*/
66 66
 #include "cfg/cfg.h"
67
+#include "core_stats.h"
67 68
 
68 69
 #ifdef DEBUG_DMALLOC
69 70
 #include <mem/dmalloc.h>
... ...
@@ -149,7 +150,7 @@ int receive_msg(char* buf, unsigned int len, struct receive_info* rcv_info)
149 150
 		if ((msg->via1==0) || (msg->via1->error!=PARSE_OK)){
150 151
 			/* no via, send back error ? */
151 152
 			LOG(L_ERR, "ERROR: receive_msg: no via found in request\n");
152
-			sr_event_exec(SREV_CORE_STATS, (void*)5);
153
+			STATS_BAD_MSG();
153 154
 			goto error02;
154 155
 		}
155 156
 		/* check if necessary to add receive?->moved to forward_req */
... ...
@@ -184,7 +185,7 @@ int receive_msg(char* buf, unsigned int len, struct receive_info* rcv_info)
184 185
 		*/
185 186
 		if (exec_pre_script_cb(msg, REQUEST_CB_TYPE)==0 )
186 187
 		{
187
-			sr_event_exec(SREV_CORE_STATS, (void*)3);
188
+			STATS_REQ_FWD_DROP();
188 189
 			goto end; /* drop the request */
189 190
 		}
190 191
 
... ...
@@ -212,7 +213,7 @@ int receive_msg(char* buf, unsigned int len, struct receive_info* rcv_info)
212 213
 		if ((msg->via1==0) || (msg->via1->error!=PARSE_OK)){
213 214
 			/* no via, send back error ? */
214 215
 			LOG(L_ERR, "ERROR: receive_msg: no via found in reply\n");
215
-			sr_event_exec(SREV_CORE_STATS, (void*)6);
216
+			STATS_BAD_RPL();
216 217
 			goto error02;
217 218
 		}
218 219
 
... ...
@@ -230,8 +231,8 @@ int receive_msg(char* buf, unsigned int len, struct receive_info* rcv_info)
230 231
 		*/
231 232
 		if (exec_pre_script_cb(msg, ONREPLY_CB_TYPE)==0 )
232 233
 		{
233
-			sr_event_exec(SREV_CORE_STATS, (void*)4);
234
-			goto end; /* drop the request */
234
+			STATS_RPL_FWD_DROP();
235
+			goto end; /* drop the reply */
235 236
 		}
236 237
 
237 238
 		/* exec the onreply routing script */
... ...
@@ -246,7 +247,7 @@ int receive_msg(char* buf, unsigned int len, struct receive_info* rcv_info)
246 247
 			}else
247 248
 #endif /* NO_ONREPLY_ROUTE_ERROR */
248 249
 			if (unlikely(ret==0 || (ctx.run_flags&DROP_R_F))){
249
-				sr_event_exec(SREV_CORE_STATS, (void*)4);
250
+				STATS_RPL_FWD_DROP();
250 251
 				goto skip_send_reply; /* drop the message, no error */
251 252
 			}
252 253
 		}