Browse code

- added ser profiling patch from Hendrik Scholz <hendrik.scholz@freenet-ag.de>, adapted to the new fork functions (for more info see http://lists.iptel.org/pipermail/serdev/2006-July/007627.html)

Andrei Pelinescu-Onciul authored on 20/09/2006 10:28:42
Showing 3 changed files
... ...
@@ -50,6 +50,7 @@
50 50
 #              sparc <= v8 support (andrei)
51 51
 #  2006-03-31  armv6 & mips64 support added
52 52
 #              mips and arm set to NOSMP by default (andrei)
53
+#  2006-07-10  added -DPROFILING (hscholz)
53 54
 
54 55
 
55 56
 # check if already included/exported
... ...
@@ -347,6 +348,9 @@ endif
347 347
 # -DUSE_DST_BLACKLIST
348 348
 #		blacklist bad destination (timeout, failed to connect, error sending
349 349
 #        a.s.o)
350
+# -DPROFILING
351
+#		if enabled profiling will be enabled for child processes
352
+#		Don't forget to set PROFILE (see below)
350 353
 
351 354
 # Sometimes is needes correct non-quoted $OS. HACK: gcc translates known OS to number ('linux'), so there is added underscore
352 355
 
... ...
@@ -376,9 +380,11 @@ DEFS+= $(extra_defs) \
376 376
 	 #-DNOSMP \
377 377
 	 #-DUSE_SHM_MEM \
378 378
 	 #-DSTATS \
379
-	 #-DNO_LOG
379
+	 #-DNO_LOG \
380
+	 #-DPROFILING
380 381
 
381
-#PROFILE=  -pg #set this if you want profiling
382
+#PROFILE=  -pg	# set this if you want profiling
383
+				# you may also want to set -DPROFILING
382 384
 
383 385
 # WARNING: do not add mode=debug or mode=release anymore in the Makefile,
384 386
 # use make mode=debug all instead. Anyway no by default ser is  compiled w/ 
... ...
@@ -32,6 +32,7 @@
32 32
  * History:
33 33
  * --------
34 34
  *  2006-06-14	added process table in shared mem (dragos)
35
+ *  2006-09-20	added profile support (-DPROFILING) (hscholz)
35 36
  */
36 37
 
37 38
 
... ...
@@ -39,7 +40,13 @@
39 39
 #include "tcp_init.h"
40 40
 #include "sr_module.h"
41 41
 
42
-#include "stdio.h"
42
+#include <stdio.h>
43
+#ifdef PROFILING
44
+#include <sys/gmon.h>
45
+
46
+	extern void _start(void);
47
+	extern void etext(void);
48
+#endif
43 49
 
44 50
 
45 51
 static int estimated_proc_no=0;
... ...
@@ -96,7 +103,7 @@ int get_max_procs()
96 96
 
97 97
 
98 98
 /* return processes pid */
99
-inline int my_pid()
99
+int my_pid()
100 100
 {
101 101
 	return pt ? pt[process_no].pid : getpid();
102 102
 }
... ...
@@ -109,7 +116,7 @@ inline int my_pid()
109 109
  * @param make_sock - if to create a unix socket pair for it
110 110
  * @returns the pid of the new process
111 111
  */
112
-inline int fork_process(int child_id, char *desc, int make_sock)
112
+int fork_process(int child_id, char *desc, int make_sock)
113 113
 {
114 114
 	int pid,old_process_no;
115 115
 #ifdef USE_TCP
... ...
@@ -143,6 +150,9 @@ inline int fork_process(int child_id, char *desc, int make_sock)
143 143
 	}
144 144
 	if (pid==0){
145 145
 		/* child */
146
+#ifdef PROFILING
147
+		monstartup((u_long) &_start, (u_long) &etext);
148
+#endif
146 149
 		/* wait for parent to get out of critical zone.
147 150
 		 * this is actually relevant as the parent updates
148 151
 		 * the pt & process_count. */
... ...
@@ -189,7 +199,7 @@ inline int fork_process(int child_id, char *desc, int make_sock)
189 189
  * @returns the pid of the new process
190 190
  */
191 191
 #ifdef USE_TCP
192
-inline int fork_tcp_process(int child_id,char *desc,int r,int *reader_fd_1)
192
+int fork_tcp_process(int child_id,char *desc,int r,int *reader_fd_1)
193 193
 {
194 194
 	int pid,old_process_no;
195 195
 	int sockfd[2];
... ...
@@ -230,6 +240,9 @@ inline int fork_tcp_process(int child_id,char *desc,int r,int *reader_fd_1)
230 230
 		return pid;
231 231
 	}
232 232
 	if (pid==0){
233
+#ifdef PROFILING
234
+		monstartup((u_long) &_start, (u_long) &etext);
235
+#endif
233 236
 		/* wait for parent to get out of critical zone */
234 237
 		lock_get(process_lock);
235 238
 			close(sockfd[0]);
... ...
@@ -66,12 +66,12 @@ extern int process_no;
66 66
 
67 67
 extern struct tcp_child* tcp_children;
68 68
 
69
-inline int init_pt();
69
+int init_pt();
70 70
 int get_max_procs();
71 71
 int register_procs(int no);
72 72
 
73 73
 /* return processes pid */
74
-inline int my_pid();
74
+int my_pid();
75 75
 
76 76
 /**
77 77
  * Forks a new process.
... ...
@@ -79,7 +79,7 @@ inline int my_pid();
79 79
  * @param make_sock - if to create a unix socket pair for it
80 80
  * @returns the pid of the new process
81 81
  */
82
-inline int fork_process(int child_id,char *desc,int make_sock);
82
+int fork_process(int child_id,char *desc,int make_sock);
83 83
 
84 84
 /**
85 85
  * Forks a new TCP process.
... ...
@@ -89,7 +89,7 @@ inline int fork_process(int child_id,char *desc,int make_sock);
89 89
  * @returns the pid of the new process
90 90
  */
91 91
 #ifdef USE_TCP
92
-inline int fork_tcp_process(int child_id,char *desc,int r,int *reader_fd_1);
92
+int fork_tcp_process(int child_id,char *desc,int r,int *reader_fd_1);
93 93
 #endif
94 94
 
95 95
 #endif