From: Willy Tarreau Date: Mon, 1 Jan 2007 21:01:43 +0000 (+0100) Subject: [MINOR] stats: factorize many chunk_printf() X-Git-Tag: v1.3.4~4 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=128e9546637960ad8806606b2e3b3d2b9561eaf8;p=thirdparty%2Fhaproxy.git [MINOR] stats: factorize many chunk_printf() Improve code size, speed and readability by factoring many calls to chunk_printf(). --- diff --git a/src/proto_http.c b/src/proto_http.c index 4d6076f004..75fd1525af 100644 --- a/src/proto_http.c +++ b/src/proto_http.c @@ -3047,37 +3047,28 @@ int produce_content_stats_proxy(struct session *s, struct proxy *px) case DATA_ST_PX_FE: /* print the frontend */ if (px->cap & PR_CAP_FE) { - /* name, queue */ chunk_printf(&msg, sizeof(trash), - "Frontend"); - - /* sessions : current, max, limit, cumul. */ - chunk_printf(&msg, sizeof(trash), - "%d%d%d%d", - px->feconn, px->feconn_max, px->maxconn, px->cum_feconn); - - /* bytes : in, out */ - chunk_printf(&msg, sizeof(trash), - ""); - - /* denied: req, resp */ - chunk_printf(&msg, sizeof(trash), - "%d%d", - px->denied_req, px->denied_resp); - - /* errors : request, connect, response */ - chunk_printf(&msg, sizeof(trash), - "%d", - px->failed_req); - - /* server status : reflect backend status */ - chunk_printf(&msg, sizeof(trash), "%s", + /* name, queue */ + "Frontend" + /* sessions : current, max, limit, cumul. */ + "%d%d%d%d" + /* bytes : in, out */ + "" + /* denied: req, resp */ + "%d%d" + /* errors : request, connect, response */ + "%d" + /* server status : reflect backend status */ + "%s" + /* rest of server: nothing */ + "" + "", + px->feconn, px->feconn_max, px->maxconn, px->cum_feconn, + px->denied_req, px->denied_resp, + px->failed_req, px->state == PR_STRUN ? "OPEN" : px->state == PR_STIDLE ? "FULL" : "STOP"); - /* rest of server: nothing */ - chunk_printf(&msg, sizeof(trash), ""); - if (buffer_write_chunk(rep, &msg) != 0) return 0; } @@ -3108,36 +3099,27 @@ int produce_content_stats_proxy(struct session *s, struct proxy *px) else sv_state = 0; /* DOWN */ - /* name */ chunk_printf(&msg, sizeof(trash), - "%s", + /* name */ + "%s" + /* queue : current, max */ + "%d%d" + /* sessions : current, max, limit, cumul */ + "%d%d%s%d" + /* bytes : in, out */ + "" + /* denied: req, resp */ + "%d" + /* errors : request, connect, response */ + "%d%d\n" + "", (sv->state & SRV_BACKUP) ? "active" : "backup", - sv_state, sv->id); - - /* queue : current, max */ - chunk_printf(&msg, sizeof(trash), - "%d%d", - sv->nbpend, sv->nbpend_max); - - /* sessions : current, max, limit, cumul */ - chunk_printf(&msg, sizeof(trash), - "%d%d%s%d", - sv->cur_sess, sv->cur_sess_max, sv->maxconn ? ultoa(sv->maxconn) : "-", sv->cum_sess); - - /* bytes : in, out */ - chunk_printf(&msg, sizeof(trash), - ""); - - /* denied: req, resp */ - chunk_printf(&msg, sizeof(trash), - "%d", - sv->failed_secu); - - /* errors : request, connect, response */ - chunk_printf(&msg, sizeof(trash), - "%d%d\n", + sv_state, sv->id, + sv->nbpend, sv->nbpend_max, + sv->cur_sess, sv->cur_sess_max, sv->maxconn ? ultoa(sv->maxconn) : "-", sv->cum_sess, + sv->failed_secu, sv->failed_conns, sv->failed_resp); - + /* status */ chunk_printf(&msg, sizeof(trash), ""); chunk_printf(&msg, sizeof(trash), @@ -3145,11 +3127,13 @@ int produce_content_stats_proxy(struct session *s, struct proxy *px) (sv->state & SRV_RUNNING) ? (sv->health - sv->rise + 1) : (sv->health), (sv->state & SRV_RUNNING) ? (sv->fall) : (sv->rise)); - /* weight */ - chunk_printf(&msg, sizeof(trash), "%d", sv->uweight+1); - - /* act, bck */ - chunk_printf(&msg, sizeof(trash), "%s%s", + chunk_printf(&msg, sizeof(trash), + /* weight */ + "%d" + /* act, bck */ + "%s%s" + "", + sv->uweight+1, (sv->state & SRV_BACKUP) ? "-" : "Y", (sv->state & SRV_BACKUP) ? "Y" : "-"); @@ -3174,48 +3158,35 @@ int produce_content_stats_proxy(struct session *s, struct proxy *px) case DATA_ST_PX_BE: /* print the backend */ if (px->cap & PR_CAP_BE) { - /* name */ chunk_printf(&msg, sizeof(trash), - "Backend"); - - /* queue : current, max */ - chunk_printf(&msg, sizeof(trash), - "%d%d", - px->nbpend /* or px->totpend ? */, px->nbpend_max); - - /* sessions : current, max, limit, cumul. */ - chunk_printf(&msg, sizeof(trash), - "%d%d%d%d", - px->beconn, px->beconn_max, px->fullconn, px->cum_beconn); - - /* bytes : in, out */ - chunk_printf(&msg, sizeof(trash), - ""); - - /* denied: req, resp */ - chunk_printf(&msg, sizeof(trash), - "%d%d", - px->denied_req, px->denied_resp); - - /* errors : request, connect, response */ - chunk_printf(&msg, sizeof(trash), - "%d%d\n", - px->failed_conns, px->failed_resp); - - /* server status : reflect backend status (up/down) : we display UP - * if the backend has known working servers or if it has no server at - * all (eg: for stats). Tthen we display the total weight, number of - * active and backups. */ - chunk_printf(&msg, sizeof(trash), - "%s" - "%d" - "%d%d", + /* name */ + "Backend" + /* queue : current, max */ + "%d%d" + /* sessions : current, max, limit, cumul. */ + "%d%d%d%d" + /* bytes : in, out */ + "" + /* denied: req, resp */ + "%d%d" + /* errors : request, connect, response */ + "%d%d\n" + /* server status : reflect backend status (up/down) : we display UP + * if the backend has known working servers or if it has no server at + * all (eg: for stats). Tthen we display the total weight, number of + * active and backups. */ + "%s%d" + "%d%d" + /* rest of server: nothing */ + "" + "", + px->nbpend /* or px->totpend ? */, px->nbpend_max, + px->beconn, px->beconn_max, px->fullconn, px->cum_beconn, + px->denied_req, px->denied_resp, + px->failed_conns, px->failed_resp, (px->srv_map_sz > 0 || !px->srv) ? "UP" : "DOWN", px->srv_map_sz, px->srv_act, px->srv_bck); - /* rest of server: nothing */ - chunk_printf(&msg, sizeof(trash), ""); - if (buffer_write_chunk(rep, &msg) != 0) return 0; }