comparison extensions/test_app/test_app.c @ 1199:2c62bba0ef4b

Add some hooks in test_app in becnhmark mode
author Sebastien Decugis <sdecugis@freediameter.net>
date Fri, 14 Jun 2013 10:13:22 +0800
parents 8c4dd4b693c6
children c2fbaf2985f4
comparison
equal deleted inserted replaced
1198:8c4dd4b693c6 1199:2c62bba0ef4b
41 41
42 /* Initialize the configuration */ 42 /* Initialize the configuration */
43 struct ta_conf * ta_conf = NULL; 43 struct ta_conf * ta_conf = NULL;
44 static struct ta_conf _conf; 44 static struct ta_conf _conf;
45 static pthread_t ta_stats_th = (pthread_t)NULL; 45 static pthread_t ta_stats_th = (pthread_t)NULL;
46 static struct fd_hook_hdl * hookhdl = NULL;
47 46
48 static int ta_conf_init(void) 47 static int ta_conf_init(void)
49 { 48 {
50 ta_conf = &_conf; 49 ta_conf = &_conf;
51 memset(ta_conf, 0, sizeof(struct ta_conf)); 50 memset(ta_conf, 0, sizeof(struct ta_conf));
134 } 133 }
135 134
136 return NULL; /* never called */ 135 return NULL; /* never called */
137 } 136 }
138 137
139 static void ta_hook_cb(enum fd_hook_type type, struct msg * msg, struct peer_hdr * peer, void * other, struct fd_hook_permsgdata *pmd, void * regdata) { 138 static struct fd_hook_hdl * hookhdl[2] = { NULL, NULL };
140 139 static void ta_hook_cb_silent(enum fd_hook_type type, struct msg * msg, struct peer_hdr * peer, void * other, struct fd_hook_permsgdata *pmd, void * regdata) {
140 }
141 static void ta_hook_cb_oneline(enum fd_hook_type type, struct msg * msg, struct peer_hdr * peer, void * other, struct fd_hook_permsgdata *pmd, void * regdata) {
142 char * buf = NULL;
143 size_t len;
144
145 CHECK_MALLOC_DO( fd_msg_dump_summary(&buf, &len, NULL, msg, NULL, 0, 0),
146 { LOG_E("Error while dumping a message"); return; } );
147
148 LOG_N("{%d} %s: %s", type, (char *)other ?:"<nil>", buf ?:"<nil>");
149
150 free(buf);
141 } 151 }
142 152
143 153
144 /* entry point */ 154 /* entry point */
145 static int ta_entry(char * conffile) 155 static int ta_entry(char * conffile)
177 /* Advertise the support for the test application in the peer */ 187 /* Advertise the support for the test application in the peer */
178 CHECK_FCT( fd_disp_app_support ( ta_appli, ta_vendor, 1, 0 ) ); 188 CHECK_FCT( fd_disp_app_support ( ta_appli, ta_vendor, 1, 0 ) );
179 189
180 if (ta_conf->mode & MODE_BENCH) { 190 if (ta_conf->mode & MODE_BENCH) {
181 /* Register an empty hook to disable the default handling */ 191 /* Register an empty hook to disable the default handling */
182 CHECK_FCT( fd_hook_register( HOOK_MASK( HOOK_DATA_RECEIVED, HOOK_MESSAGE_RECEIVED, HOOK_MESSAGE_LOCAL, HOOK_MESSAGE_SENT, HOOK_MESSAGE_FAILOVER, HOOK_MESSAGE_ROUTING_FORWARD, HOOK_MESSAGE_ROUTING_LOCAL ), 192 CHECK_FCT( fd_hook_register( HOOK_MASK( HOOK_DATA_RECEIVED, HOOK_MESSAGE_RECEIVED, HOOK_MESSAGE_LOCAL, HOOK_MESSAGE_SENT, HOOK_MESSAGE_ROUTING_FORWARD, HOOK_MESSAGE_ROUTING_LOCAL ),
183 ta_hook_cb, NULL, NULL, &hookhdl) ); 193 ta_hook_cb_silent, NULL, NULL, &hookhdl[0]) );
194 CHECK_FCT( fd_hook_register( HOOK_MASK( HOOK_MESSAGE_ROUTING_ERROR, HOOK_MESSAGE_DROPPED ),
195 ta_hook_cb_oneline, NULL, NULL, &hookhdl[1]) );
184 196
185 } 197 }
186 198
187 /* Start the statistics thread */ 199 /* Start the statistics thread */
188 CHECK_POSIX( pthread_create(&ta_stats_th, NULL, ta_stats, NULL) ); 200 CHECK_POSIX( pthread_create(&ta_stats_th, NULL, ta_stats, NULL) );
195 { 207 {
196 if (ta_conf->mode & MODE_CLI) 208 if (ta_conf->mode & MODE_CLI)
197 ta_cli_fini(); 209 ta_cli_fini();
198 if (ta_conf->mode & MODE_SERV) 210 if (ta_conf->mode & MODE_SERV)
199 ta_serv_fini(); 211 ta_serv_fini();
200 if (hookhdl) 212 if (hookhdl[0])
201 fd_hook_unregister( hookhdl ); 213 fd_hook_unregister( hookhdl[0] );
214 if (hookhdl[1])
215 fd_hook_unregister( hookhdl[1] );
202 CHECK_FCT_DO( fd_thr_term(&ta_stats_th), ); 216 CHECK_FCT_DO( fd_thr_term(&ta_stats_th), );
203 CHECK_POSIX_DO( pthread_mutex_destroy(&ta_conf->stats_lock), ); 217 CHECK_POSIX_DO( pthread_mutex_destroy(&ta_conf->stats_lock), );
204 } 218 }
205 219
206 EXTENSION_ENTRY("test_app", ta_entry); 220 EXTENSION_ENTRY("test_app", ta_entry);
"Welcome to our mercurial repository"