Skip to content

Commit 0ff497b

Browse files
committed
[dev] optimize stat module (thanks to plainheart).
1 parent 454cd04 commit 0ff497b

File tree

2 files changed

+26
-13
lines changed

2 files changed

+26
-13
lines changed

ngx_rtmp_stat_module.c

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -809,7 +809,7 @@ ngx_rtmp_stat_live(ngx_http_request_t *r, ngx_chain_t ***lll,
809809
NGX_RTMP_STAT(buf, ngx_snprintf(buf, sizeof(buf),
810810
"%ui", codec->aac_chan_conf) - buf);
811811
} else if (codec->audio_channels) {
812-
if (f >= 1) NGX_RTMP_STAT_L(",");
812+
if (f >= 1) NGX_RTMP_STAT_L("\",");
813813
f = 3;
814814
NGX_RTMP_STAT_L("\"channels\":");
815815
NGX_RTMP_STAT(buf, ngx_snprintf(buf, sizeof(buf),
@@ -1005,21 +1005,12 @@ static void
10051005
ngx_rtmp_stat_application(ngx_http_request_t *r, ngx_chain_t ***lll,
10061006
ngx_rtmp_core_srv_conf_t *cscf, ngx_rtmp_core_app_conf_t *cacf)
10071007
{
1008-
u_char buf[NGX_INT_T_LEN];
10091008
ngx_rtmp_stat_loc_conf_t *slcf;
10101009

10111010
slcf = ngx_http_get_module_loc_conf(r, ngx_rtmp_stat_module);
10121011

10131012
if (slcf->format & NGX_RTMP_STAT_FORMAT_XML) {
10141013
NGX_RTMP_STAT_L("<application>\r\n");
1015-
NGX_RTMP_STAT_L("<port>");
1016-
NGX_RTMP_STAT(buf, ngx_snprintf(buf, sizeof(buf),
1017-
"%ui", cscf->port) - buf);
1018-
NGX_RTMP_STAT_L("</port>\r\n");
1019-
NGX_RTMP_STAT_L("<server_index>");
1020-
NGX_RTMP_STAT(buf, ngx_snprintf(buf, sizeof(buf),
1021-
"%ui", cscf->index) - buf);
1022-
NGX_RTMP_STAT_L("</server_index>\r\n");
10231014
NGX_RTMP_STAT_L("<name>");
10241015
NGX_RTMP_STAT_ES(&cacf->name);
10251016
NGX_RTMP_STAT_L("</name>\r\n");
@@ -1052,18 +1043,35 @@ static void
10521043
ngx_rtmp_stat_server(ngx_http_request_t *r, ngx_chain_t ***lll,
10531044
ngx_rtmp_core_srv_conf_t *cscf)
10541045
{
1055-
ngx_rtmp_core_app_conf_t **cacf;
1046+
u_char buf[NGX_INT_T_LEN];
10561047
size_t n;
1048+
ngx_rtmp_core_app_conf_t **cacf;
10571049
ngx_rtmp_stat_loc_conf_t *slcf;
10581050

10591051
slcf = ngx_http_get_module_loc_conf(r, ngx_rtmp_stat_module);
10601052

10611053
if (slcf->format & NGX_RTMP_STAT_FORMAT_XML) {
10621054
NGX_RTMP_STAT_L("<server>\r\n");
1055+
NGX_RTMP_STAT_L("<port>");
1056+
NGX_RTMP_STAT(buf, ngx_snprintf(buf, sizeof(buf),
1057+
"%ui", cscf->port) - buf);
1058+
NGX_RTMP_STAT_L("</port>\r\n");
1059+
NGX_RTMP_STAT_L("<server_index>");
1060+
NGX_RTMP_STAT(buf, ngx_snprintf(buf, sizeof(buf),
1061+
"%ui", cscf->index) - buf);
1062+
NGX_RTMP_STAT_L("</server_index>\r\n");
10631063
}
10641064

10651065
if (slcf->format & NGX_RTMP_STAT_FORMAT_JSON) {
10661066
NGX_RTMP_STAT_L("{");
1067+
NGX_RTMP_STAT_L("\"port\":");
1068+
NGX_RTMP_STAT(buf, ngx_snprintf(buf, sizeof(buf),
1069+
"%ui", cscf->port) - buf);
1070+
NGX_RTMP_STAT_L(",");
1071+
NGX_RTMP_STAT_L("\"server_index\":");
1072+
NGX_RTMP_STAT(buf, ngx_snprintf(buf, sizeof(buf),
1073+
"%ui", cscf->index) - buf);
1074+
NGX_RTMP_STAT_L(",");
10671075
}
10681076

10691077
#ifdef NGX_RTMP_POOL_DEBUG

stat.xsl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
<tr bgcolor="#999999">
3333
<th>HTTP-FLV</th>
3434
<th>#clients</th>
35+
<th colspan="2">Server</th>
3536
<th colspan="4">Video</th>
3637
<th colspan="4">Audio</th>
3738
<th>In bytes</th>
@@ -43,6 +44,8 @@
4344
</tr>
4445
<tr>
4546
<td colspan="2">Accepted: <xsl:value-of select="naccepted"/></td>
47+
<th bgcolor="#999999">port</th>
48+
<th bgcolor="#999999">index</th>
4649
<th bgcolor="#999999">codec</th>
4750
<th bgcolor="#999999">bits/s</th>
4851
<th bgcolor="#999999">size</th>
@@ -135,7 +138,7 @@
135138
<td>
136139
<a href="">
137140
<xsl:attribute name="onclick">
138-
var d=document.getElementById('<xsl:value-of select="../../port"/>-<xsl:value-of select="../../server_index"/>-<xsl:value-of select="../../name"/>-<xsl:value-of select="name"/>');
141+
var d=document.getElementById('<xsl:value-of select="../../../port"/>-<xsl:value-of select="../../../server_index"/>-<xsl:value-of select="../../name"/>-<xsl:value-of select="name"/>');
139142
d.style.display=d.style.display=='none'?'':'none';
140143
return false
141144
</xsl:attribute>
@@ -146,6 +149,8 @@
146149
</a>
147150
</td>
148151
<td align="middle"> <xsl:value-of select="nclients"/> </td>
152+
<td align="middle"> <xsl:value-of select="../../../port"/> </td>
153+
<td align="middle"> <xsl:value-of select="../../../server_index"/> </td>
149154
<td>
150155
<xsl:value-of select="meta/video/codec"/>&#160;<xsl:value-of select="meta/video/profile"/>&#160;<xsl:value-of select="meta/video/level"/>
151156
</td>
@@ -211,7 +216,7 @@
211216
</tr>
212217
<tr style="display:none">
213218
<xsl:attribute name="id">
214-
<xsl:value-of select="../../port"/>-<xsl:value-of select="../../server_index"/>-<xsl:value-of select="../../name"/>-<xsl:value-of select="name"/>
219+
<xsl:value-of select="../../../port"/>-<xsl:value-of select="../../../server_index"/>-<xsl:value-of select="../../name"/>-<xsl:value-of select="name"/>
215220
</xsl:attribute>
216221
<td colspan="16" ngcolor="#eeeeee">
217222
<table cellspacing="1" cellpadding="5">

0 commit comments

Comments
 (0)