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