Browse code

Added NOCR and MACROEATER compile-time speed-up options. NOCR replaces a 'for' cycle with 'memchr' and MACROEATER replaces 'eater' functions with macros. The -V command-line options shows now which of these options are enabled. A signal handler is added which calls exit(0) on INT signal ... good for profiling.

-Jiri

Jiri Kuthan authored on 06/10/2001 22:17:53
Showing 4 changed files
... ...
@@ -14,6 +14,14 @@ depends= $(sources:.c=.d)
14 14
 
15 15
 NAME=sip_router
16 16
 
17
+# compile-time options
18
+# NOCR disables seeking for CRs -- breaks standard but is fast
19
+# recommended: on (speed-up, no implementation really sends CR)
20
+# MACROEATER replaces frequently called parser helper functions
21
+# with macros
22
+# recommanded: on (speed-up)
23
+DEFS=-DNOCR -DMACROEATER
24
+
17 25
 # platform dependent settings
18 26
 
19 27
 ARCH = $(shell uname -s)
... ...
@@ -21,7 +29,7 @@ ARCH = $(shell uname -s)
21 29
 ifeq ($(ARCH), Linux)
22 30
 
23 31
 CC=gcc
24
-CFLAGS=-O2 -Wcast-align #-Wmissing-prototypes  -Wall
32
+CFLAGS=-O2 -pg -Wcast-align #-Wmissing-prototypes  -Wall
25 33
 LEX=flex
26 34
 YACC=bison
27 35
 YACC_FLAGS=-d -b cfg
... ...
@@ -54,7 +62,7 @@ LIBS=-lfl
54 62
 endif
55 63
 
56 64
 
57
-MKDEP=gcc -M
65
+MKDEP=gcc -M $(DEFS)
58 66
 
59 67
 ALLDEP=Makefile
60 68
 
... ...
@@ -62,7 +70,7 @@ ALLDEP=Makefile
62 70
 
63 71
 
64 72
 %.o:%.c $(ALLDEP)
65
-	$(CC) $(CFLAGS) -c $< -o $@
73
+	$(CC) $(CFLAGS) $(DEFS) -c $< -o $@
66 74
 
67 75
 %.d: %.c
68 76
 	$(MKDEP) $< >$@
... ...
@@ -20,6 +20,9 @@
20 20
 #include "udp_server.h"
21 21
 #include "globals.h"
22 22
 
23
+#include <signal.h>
24
+
25
+
23 26
 
24 27
 #ifdef DEBUG_DMALLOC
25 28
 #include <dmalloc.h>
... ...
@@ -28,6 +31,20 @@
28 31
 
29 32
 static char id[]="@(#) $Id$";
30 33
 static char version[]="sip_router 0.6";
34
+static char flags[]="NOCR:"
35
+#ifdef NOCR
36
+"On"
37
+#else
38
+"Off"
39
+#endif
40
+", MACROEATER:"
41
+#ifdef MACROEATER
42
+"On"
43
+#else
44
+"Off"
45
+#endif
46
+;
47
+
31 48
 static char help_msg[]= "\
32 49
 Usage: sip_router -l address [-l address] [options]\n\
33 50
 Options:\n\
... ...
@@ -196,7 +213,17 @@ int main_loop()
196 213
 	return -1;
197 214
 
198 215
 }
199
-	
216
+
217
+/* added by jku; allows for regular exit on a specific signal;
218
+   good for profiling which only works if exited regularly and
219
+   not by default signal handlers
220
+*/	
221
+
222
+static void sig_usr(int signo)
223
+{
224
+	DPrint("INT received, program terminates\n");
225
+	exit(0);
226
+}
200 227
 	
201 228
 	
202 229
 	
... ...
@@ -209,6 +236,12 @@ int main(int argc, char** argv)
209 236
 	char *tmp;
210 237
 	struct utsname myname;
211 238
 
239
+	/* added by jku: add exit handler */
240
+        if (signal(SIGINT, sig_usr) == SIG_ERR ) {
241
+ 		DPrint("ERROR: no signal handler can be installed\n");
242
+                goto error;
243
+        }
244
+
212 245
 	/* process command line (get port no, cfg. file path etc) */
213 246
 	opterr=0;
214 247
 	while((c=getopt(argc,argv,"f:p:l:n:rRvdDEVh"))!=-1){
... ...
@@ -266,6 +299,7 @@ int main(int argc, char** argv)
266 299
 					break;
267 300
 			case 'V':
268 301
 					printf("version: %s\n", version);
302
+					printf("flags: %s\n", flags );
269 303
 					printf("%s\n",id);
270 304
 					exit(0);
271 305
 					break;
... ...
@@ -13,18 +13,35 @@ char* eat_line(char* buffer, unsigned int len)
13 13
 	char* nl;
14 14
 	char c;
15 15
 
16
+	/* jku .. replace for search with a library function; not conformant
17
+ 		  as I do not care about CR
18
+	*/
19
+#ifdef NOCR
20
+	nl=(char *)memchr( buffer, '\n', len );
21
+	if ( nl ) { 
22
+		c=* nl;
23
+		if ( nl + 1 < buffer+len)  nl++;
24
+		if (( nl+1<buffer+len) && * nl=='\r')  nl++;
25
+	} else  nl=buffer+len;
26
+#else
16 27
 	for(nl=buffer;(nl<buffer+len)&& (*nl!='\r')&&(*nl!='\n') ;nl++);
17 28
 	c=*nl;
18 29
 	if (nl+1<buffer+len)  nl++;
19 30
 	if ((nl+1<buffer+len) &&
20 31
 			((c=='\r' && *nl=='\n')|| (c=='\n' && *nl=='\r'))) 
21 32
 		nl++;
33
+#endif
34
+	
35
+	/* end of jku */
22 36
 	return nl;
23 37
 }
24 38
 
25 39
 
26 40
 
27 41
 /* returns pointer to first non  white char or after the end  of the buffer */
42
+
43
+#ifndef MACROEATER
44
+
28 45
 char* eat_space(char* buffer, unsigned int len)
29 46
 {
30 47
 	char* p;
... ...
@@ -34,7 +51,6 @@ char* eat_space(char* buffer, unsigned int len)
34 51
 }
35 52
 
36 53
 
37
-
38 54
 /* returns pointer after the token (first whitespace char or CR/LF) */
39 55
 char* eat_token(char* buffer, unsigned int len)
40 56
 {
... ...
@@ -59,6 +75,9 @@ char* eat_token2(char* buffer, unsigned int len, char delim)
59 75
 	return p;
60 76
 }
61 77
 
78
+/* EoMACROEATER */
79
+#endif
80
+
62 81
 
63 82
 
64 83
 /* returns true if line started  at buffer contains only white space */
... ...
@@ -6,10 +6,44 @@
6 6
 #define parser_f_h
7 7
 
8 8
 char* eat_line(char* buffer, unsigned int len);
9
+int is_empty(char* buffer, unsigned int len);
10
+
11
+#ifdef MACROEATER
12
+
13
+/* turn the most frequently called functions into macros */
14
+
15
+
16
+#define eat_space(buffer,len)                                          \
17
+  ( {   char *p;                                                     	\
18
+        for(p=(buffer);(p<(buffer)+(len))&& (*p==' ' || *p=='\t') ;p++);\
19
+        p;                                                              \
20
+  } )
21
+
22
+#define eat_token(buffer,len)						\
23
+  ( { char *p;								\
24
+      for (p=(buffer);(p<(buffer)+(len))&&				\
25
+                        (*p!=' ')&&(*p!='\t')&&(*p!='\n')&&(*p!='\r');	\
26
+                p++);							\
27
+      p;								\
28
+  } )
29
+
30
+#define eat_token2(buffer,len,delim)					\
31
+  ( { char *p;								\
32
+      for (p=(buffer);(p<(buffer)+(len))&&				\
33
+                        (*p!=(delim))&&(*p!='\n')&&(*p!='\r');		\
34
+                p++);							\
35
+      p;								\
36
+  } )
37
+
38
+
39
+#else
40
+
41
+
9 42
 char* eat_space(char* buffer, unsigned int len);
10 43
 char* eat_token(char* buffer, unsigned int len);
11 44
 char* eat_token2(char* buffer, unsigned int len, char delim);
12
-int is_empty(char* buffer, unsigned int len);
45
+
46
+/* EoMACROEATER */
47
+#endif
13 48
 
14 49
 #endif
15
-