From 218e312a1f9c1daf223ae7ad01fc3d0992f64445 Mon Sep 17 00:00:00 2001 From: Roman Arutyunyan Date: Wed, 13 Jun 2012 13:47:43 +0400 Subject: [PATCH] added memory info to stat xml --- ngx_rtmp_stat_module.c | 54 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/ngx_rtmp_stat_module.c b/ngx_rtmp_stat_module.c index 5816cd4..b611526 100644 --- a/ngx_rtmp_stat_module.c +++ b/ngx_rtmp_stat_module.c @@ -93,6 +93,7 @@ ngx_module_t ngx_rtmp_stat_module = { }; + #define NGX_RTMP_STAT_BUFSIZE 256 @@ -199,6 +200,51 @@ ngx_rtmp_stat_bw(ngx_http_request_t *r, ngx_chain_t ***lll, } +#ifdef NGX_RTMP_POOL_DEBUG +static void +ngx_rtmp_stat_get_pool_size(ngx_pool_t *pool, ngx_uint_t *nlarge, + size_t *size) +{ + ngx_pool_large_t *l; + ngx_pool_t *p, *n; + + *nlarge = 0; + for (l = pool->large; l; l = l->next) { + ++*nlarge; + } + + *size = 0; + for (p = pool, n = pool->d.next; /* void */; p = n, n = n->d.next) { + *size += (p->d.last - (u_char *)p); + if (n == NULL) { + break; + } + } +} + + +static void +ngx_rtmp_stat_dump_pool(ngx_http_request_t *r, ngx_chain_t ***lll, + ngx_pool_t *pool) +{ + ngx_uint_t nlarge; + size_t size; + u_char buf[NGX_OFF_T_LEN + 1]; + + size = 0; + nlarge = 0; + ngx_rtmp_stat_get_pool_size(pool, &nlarge, &size); + NGX_RTMP_STAT_L(""); + NGX_RTMP_STAT(buf, ngx_snprintf(buf, sizeof(buf), + "%ui", nlarge) - buf); + NGX_RTMP_STAT_L(""); + NGX_RTMP_STAT(buf, ngx_snprintf(buf, sizeof(buf), + "%uz", size) - buf); + NGX_RTMP_STAT_L("\r\n"); +} +#endif + + static void ngx_rtmp_stat_live(ngx_http_request_t *r, ngx_chain_t ***lll, ngx_rtmp_live_app_conf_t *lacf) @@ -266,6 +312,10 @@ ngx_rtmp_stat_live(ngx_http_request_t *r, ngx_chain_t ***lll, if (slcf->stat & NGX_RTMP_STAT_CLIENTS) { NGX_RTMP_STAT_L(""); +#ifdef NGX_RTMP_POOL_DEBUG + ngx_rtmp_stat_dump_pool(r, lll, s->connection->pool); +#endif + NGX_RTMP_STAT_L("
"); NGX_RTMP_STAT_S(&s->connection->addr_text); NGX_RTMP_STAT_L("
"); @@ -363,6 +413,10 @@ ngx_rtmp_stat_server(ngx_http_request_t *r, ngx_chain_t ***lll, NGX_RTMP_STAT_L("\r\n"); +#ifdef NGX_RTMP_POOL_DEBUG + ngx_rtmp_stat_dump_pool(r, lll, cscf->pool); +#endif + cacf = cscf->applications.elts; for (n = 0; n < cscf->applications.nelts; ++n, ++cacf) { ngx_rtmp_stat_application(r, lll, *cacf);