aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrey Uzunov <andrey.uzunov@gmail.com>2013-08-28 15:11:55 +0000
committerAndrey Uzunov <andrey.uzunov@gmail.com>2013-08-28 15:11:55 +0000
commit0617124c369fe150123ced3e1c521d69ed4bfff2 (patch)
tree54f411e9d55acf49726cfd844dcd44f288ad6493
parenta5f4e104ccedd8ef63ac2a34696db0c3e0a20136 (diff)
downloadlibmicrohttpd-0617124c369fe150123ced3e1c521d69ed4bfff2.tar.gz
libmicrohttpd-0617124c369fe150123ced3e1c521d69ed4bfff2.zip
mhd2spdy: simple statistics (send/received bytes) added
-rw-r--r--src/examples/mhd2spdy.c27
-rw-r--r--src/examples/mhd2spdy_spdy.c7
-rw-r--r--src/examples/mhd2spdy_structures.c2
-rw-r--r--src/examples/mhd2spdy_structures.h19
4 files changed, 53 insertions, 2 deletions
diff --git a/src/examples/mhd2spdy.c b/src/examples/mhd2spdy.c
index a642d936..01a8c7a3 100644
--- a/src/examples/mhd2spdy.c
+++ b/src/examples/mhd2spdy.c
@@ -45,6 +45,22 @@ catch_signal(int signal)
45} 45}
46 46
47 47
48void
49print_stat()
50{
51 if(!glob_opt.statistics)
52 return;
53
54 printf("--------------------------\n");
55 printf("Statistics (TLS overhead is ignored when used):\n");
56 //printf("HTTP bytes received: %lld\n", glob_stat.http_bytes_received);
57 //printf("HTTP bytes sent: %lld\n", glob_stat.http_bytes_sent);
58 printf("SPDY bytes sent: %lld\n", glob_stat.spdy_bytes_sent);
59 printf("SPDY bytes received: %lld\n", glob_stat.spdy_bytes_received);
60 printf("SPDY bytes received and dropped: %lld\n", glob_stat.spdy_bytes_received_and_dropped);
61}
62
63
48int 64int
49run_everything () 65run_everything ()
50{ 66{
@@ -201,6 +217,8 @@ run_everything ()
201 217
202 PRINT_INFO2("spdy streams: %i; http requests: %i", glob_opt.streams_opened, glob_opt.responses_pending); 218 PRINT_INFO2("spdy streams: %i; http requests: %i", glob_opt.streams_opened, glob_opt.responses_pending);
203 PRINT_INFO2("memory allocated %zu bytes", glob_opt.global_memory); 219 PRINT_INFO2("memory allocated %zu bytes", glob_opt.global_memory);
220
221 print_stat();
204 222
205 return 0; 223 return 0;
206} 224}
@@ -210,7 +228,7 @@ void
210display_usage() 228display_usage()
211{ 229{
212 printf( 230 printf(
213 "Usage: http2spdy [-vo] [-b <SPDY2HTTP-PROXY>] -p <PORT>\n" 231 "Usage: mhd2spdy [-vos] [-b <SPDY2HTTP-PROXY>] -p <PORT>\n"
214 "TODO\n" 232 "TODO\n"
215 ); 233 );
216} 234}
@@ -227,12 +245,13 @@ main (int argc,
227 {"backend-proxy", required_argument, 0, 'b'}, 245 {"backend-proxy", required_argument, 0, 'b'},
228 {"verbose", no_argument, 0, 'v'}, 246 {"verbose", no_argument, 0, 'v'},
229 {"only-proxy", no_argument, 0, 'o'}, 247 {"only-proxy", no_argument, 0, 'o'},
248 {"statistics", no_argument, 0, 's'},
230 {0, 0, 0, 0} 249 {0, 0, 0, 0}
231 }; 250 };
232 251
233 while (1) 252 while (1)
234 { 253 {
235 getopt_ret = getopt_long( argc, argv, "p:b:vo", long_options, &option_index); 254 getopt_ret = getopt_long( argc, argv, "p:b:vos", long_options, &option_index);
236 if (getopt_ret == -1) 255 if (getopt_ret == -1)
237 break; 256 break;
238 257
@@ -256,6 +275,10 @@ main (int argc,
256 glob_opt.only_proxy = true; 275 glob_opt.only_proxy = true;
257 break; 276 break;
258 277
278 case 's':
279 glob_opt.statistics = true;
280 break;
281
259 case 0: 282 case 0:
260 PRINT_INFO("0 from getopt"); 283 PRINT_INFO("0 from getopt");
261 break; 284 break;
diff --git a/src/examples/mhd2spdy_spdy.c b/src/examples/mhd2spdy_spdy.c
index fb749291..2c06ef88 100644
--- a/src/examples/mhd2spdy_spdy.c
+++ b/src/examples/mhd2spdy_spdy.c
@@ -188,6 +188,9 @@ spdy_cb_send(spdylay_session *session,
188 188
189 PRINT_INFO2("%zd bytes written by spdy", rv); 189 PRINT_INFO2("%zd bytes written by spdy", rv);
190 190
191 if(rv > 0)
192 UPDATE_STAT(glob_stat.spdy_bytes_sent, rv);
193
191 return rv; 194 return rv;
192} 195}
193 196
@@ -257,6 +260,10 @@ spdy_cb_recv(spdylay_session *session,
257 else if(rv == 0) 260 else if(rv == 0)
258 rv = SPDYLAY_ERR_EOF; 261 rv = SPDYLAY_ERR_EOF;
259 } 262 }
263
264 if(rv > 0)
265 UPDATE_STAT(glob_stat.spdy_bytes_received, rv);
266
260 return rv; 267 return rv;
261} 268}
262 269
diff --git a/src/examples/mhd2spdy_structures.c b/src/examples/mhd2spdy_structures.c
index 8e7852c2..ff434546 100644
--- a/src/examples/mhd2spdy_structures.c
+++ b/src/examples/mhd2spdy_structures.c
@@ -118,6 +118,8 @@ void
118free_proxy(struct Proxy *proxy) 118free_proxy(struct Proxy *proxy)
119{ 119{
120 PRINT_INFO2("free proxy called for '%s'", proxy->url); 120 PRINT_INFO2("free proxy called for '%s'", proxy->url);
121 if(NULL != proxy->http_body && proxy->http_body_size > 0)
122 UPDATE_STAT(glob_stat.spdy_bytes_received_and_dropped, proxy->http_body_size);
121 free(proxy->http_body); 123 free(proxy->http_body);
122 free_uri(proxy->uri); 124 free_uri(proxy->uri);
123 free(proxy->url); 125 free(proxy->url);
diff --git a/src/examples/mhd2spdy_structures.h b/src/examples/mhd2spdy_structures.h
index 863661b2..c9aa4c39 100644
--- a/src/examples/mhd2spdy_structures.h
+++ b/src/examples/mhd2spdy_structures.h
@@ -159,10 +159,22 @@ struct global_options
159 bool verbose; 159 bool verbose;
160 bool only_proxy; 160 bool only_proxy;
161 bool spdy_data_received; 161 bool spdy_data_received;
162 bool statistics;
162} 163}
163glob_opt; 164glob_opt;
164 165
165 166
167struct global_statistics
168{
169 //unsigned long long http_bytes_sent;
170 //unsigned long long http_bytes_received;
171 unsigned long long spdy_bytes_sent;
172 unsigned long long spdy_bytes_received;
173 unsigned long long spdy_bytes_received_and_dropped;
174}
175glob_stat;
176
177
166//forbidden headers 178//forbidden headers
167#define SPDY_HTTP_HEADER_TRANSFER_ENCODING "transfer-encoding" 179#define SPDY_HTTP_HEADER_TRANSFER_ENCODING "transfer-encoding"
168#define SPDY_HTTP_HEADER_PROXY_CONNECTION "proxy-connection" 180#define SPDY_HTTP_HEADER_PROXY_CONNECTION "proxy-connection"
@@ -241,6 +253,13 @@ glob_opt;
241 while(0) 253 while(0)
242 254
243 255
256#define UPDATE_STAT(stat, value) do{\
257 if(glob_opt.statistics)\
258 {\
259 stat += value;\
260 }\
261 }\
262 while(0)
244 263
245 264
246void 265void