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 21
 ifeq ($(ARCH), Linux)
22 22
 
23 23
 CC=gcc
24
-CFLAGS=-O2 -Wcast-align #-Wmissing-prototypes  -Wall
24
+CFLAGS=-O2 -pg -Wcast-align #-Wmissing-prototypes  -Wall
25 25
 LEX=flex
26 26
 YACC=bison
27 27
 YACC_FLAGS=-d -b cfg
... ...
@@ -54,7 +62,7 @@ LIBS=-lfl
54 54
 endif
55 55
 
56 56
 
57
-MKDEP=gcc -M
57
+MKDEP=gcc -M $(DEFS)
58 58
 
59 59
 ALLDEP=Makefile
60 60
 
... ...
@@ -62,7 +70,7 @@ ALLDEP=Makefile
62 62
 
63 63
 
64 64
 %.o:%.c $(ALLDEP)
65
-	$(CC) $(CFLAGS) -c $< -o $@
65
+	$(CC) $(CFLAGS) $(DEFS) -c $< -o $@
66 66
 
67 67
 %.d: %.c
68 68
 	$(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 28
 
29 29
 static char id[]="@(#) $Id$";
30 30
 static char version[]="sip_router 0.6";
31
+static char flags[]="NOCR:"
32
+#ifdef NOCR
33
+"On"
34
+#else
35
+"Off"
36
+#endif
37
+", MACROEATER:"
38
+#ifdef MACROEATER
39
+"On"
40
+#else
41
+"Off"
42
+#endif
43
+;
44
+
31 45
 static char help_msg[]= "\
32 46
 Usage: sip_router -l address [-l address] [options]\n\
33 47
 Options:\n\
... ...
@@ -196,7 +213,17 @@ int main_loop()
196 196
 	return -1;
197 197
 
198 198
 }
199
-	
199
+
200
+/* added by jku; allows for regular exit on a specific signal;
201
+   good for profiling which only works if exited regularly and
202
+   not by default signal handlers
203
+*/	
204
+
205
+static void sig_usr(int signo)
206
+{
207
+	DPrint("INT received, program terminates\n");
208
+	exit(0);
209
+}
200 210
 	
201 211
 	
202 212
 	
... ...
@@ -209,6 +236,12 @@ int main(int argc, char** argv)
209 209
 	char *tmp;
210 210
 	struct utsname myname;
211 211
 
212
+	/* added by jku: add exit handler */
213
+        if (signal(SIGINT, sig_usr) == SIG_ERR ) {
214
+ 		DPrint("ERROR: no signal handler can be installed\n");
215
+                goto error;
216
+        }
217
+
212 218
 	/* process command line (get port no, cfg. file path etc) */
213 219
 	opterr=0;
214 220
 	while((c=getopt(argc,argv,"f:p:l:n:rRvdDEVh"))!=-1){
... ...
@@ -266,6 +299,7 @@ int main(int argc, char** argv)
266 266
 					break;
267 267
 			case 'V':
268 268
 					printf("version: %s\n", version);
269
+					printf("flags: %s\n", flags );
269 270
 					printf("%s\n",id);
270 271
 					exit(0);
271 272
 					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 34
 }
35 35
 
36 36
 
37
-
38 37
 /* returns pointer after the token (first whitespace char or CR/LF) */
39 38
 char* eat_token(char* buffer, unsigned int len)
40 39
 {
... ...
@@ -59,6 +75,9 @@ char* eat_token2(char* buffer, unsigned int len, char delim)
59 59
 	return p;
60 60
 }
61 61
 
62
+/* EoMACROEATER */
63
+#endif
64
+
62 65
 
63 66
 
64 67
 /* 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
-