📄 slstats.c
字号:
/*
* Copyright (c) 2005, Dennis Kuschel.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "lwip/opt.h"
#include "lwip/sys.h"
#include "lwip/memp.h"
#include "lwip/tcpip.h"
#include "lwip/ip_addr.h"
#include "lwip/stats.h"
#include "lwip/sockets.h"
#include "arch/perf.h"
#include "../../../e-soft/src/httpd.h"
#include <picoos.h>
#if SYS_STATS == 0
#error SYS_STATS must be set to 1 in lwipopts.h !
#endif
/*-------------------------------------------------------------------------*/
/* exported functions */
sint_t statistics_servlet(SERVLET_t so);
/* global variables */
struct netif *ethnetif_g = NULL;
struct ip_addr ipaddr_g;
struct ip_addr netmask_g;
struct ip_addr gatew_g;
#define PR_LINK 0x00000001
#define PR_IPFRAG 0x00000002
#define PR_IP 0x00000004
#define PR_ICMP 0x00000008
#define PR_UDP 0x00000010
#define PR_TCP 0x00000020
#define PR_PBUF 0x00000040
#define PR_MEM 0x00000080
#define PR_MEMP 0x00000100
#define PR_SYS 0x00000200
/*-------------------------------------------------------------------------*/
void statsServlet_init(struct netif *ethnetif, struct ip_addr ipaddr,
struct ip_addr netmask, struct ip_addr gatew)
{
ethnetif_g = ethnetif;
ipaddr_g = ipaddr;
netmask_g = netmask;
gatew_g = gatew;
}
static char *ip2str(char *buf, struct ip_addr addr)
{
u32_t s_addr = addr.addr;
char inv[3];
char *rp;
u8_t *ap;
u8_t rem;
u8_t n;
u8_t i;
rp = buf;
ap = (u8_t *)&s_addr;
for(n = 0; n < 4; n++) {
i = 0;
do {
rem = *ap % (u8_t)10;
*ap /= (u8_t)10;
inv[i++] = '0' + rem;
} while(*ap);
while(i--)
*rp++ = inv[i];
*rp++ = '.';
ap++;
}
*--rp = 0;
return buf;
}
static void printButtons(SERVLET_t so, u32_t prflags)
{
hsl_printf(so, "<table><tr><td>\n");
hsl_printf(so, "<form action=\"index.html\" method=\"get\">\n");
hsl_printf(so, "<input type=\"submit\" value=\"Back\">\n");
hsl_printf(so, "</form>\n");
hsl_printf(so, "</td><td>  </td><td>\n");
hsl_printf(so, "<form action=\"%s\" method=\"get\">\n",hsl_getOwnName(so));
hsl_printf(so, "<input type=\"hidden\" name=\"i\" value=\"%u\">\n",1000+jiffies%9000);
hsl_printf(so, "<input type=\"hidden\" name=\"err\" value=\"1\">\n");
hsl_printf(so, "<input type=\"submit\" value=\"Show Errors\">\n");
hsl_printf(so, "</form>\n");
hsl_printf(so, "</td><td>  </td><td>\n");
hsl_printf(so, "<form action=\"%s\" method=\"get\">\n",hsl_getOwnName(so));
hsl_printf(so, "<input type=\"hidden\" name=\"i\" value=\"%u\">\n",1000+jiffies%9000);
hsl_printf(so, "<input type=\"hidden\" name=\"print\" value=\"%u\">\n",prflags);
hsl_printf(so, "<input type=\"submit\" value=\"Refresh\">\n");
hsl_printf(so, "</form>\n");
hsl_printf(so, "</td></tr></table>\n");
}
static void printLink(SERVLET_t so, u32_t prflags, const char *text)
{
sint_t status;
hsl_printf(so, "<tr><td width=\"150\">");
status = hsl_linkCreate(so, NULL, 0);
if (status == 0)
status = hsl_linkAddNumberVal(so, "i", 1000+jiffies%9000);
if (status == 0)
status = hsl_linkAddNumberVal(so, "print", prflags);
if (status == 0)
status = hsl_linkInsert(so, text);
hsl_printf(so, "\n");
}
static void printTabEnt(SERVLET_t so, const char *name, u32_t val, int imp)
{
if (imp && val!=0)
{
hsl_printf(so, "<tr><td width=\"150\"> "
"<font color=\"#FF0000\"><b>%s</b></font>\n"
"</td><td><code>"
"<font color=\"#FF0000\"><b>%u</b></font>\n"
"</code></td></tr>\n",
name, val);
}
else
{
hsl_printf(so, "<tr><td width=\"150\"> %s\n"
"</td><td><code>%u</code></td></tr>\n",
name, val);
}
}
static void printExpMsg(SERVLET_t so)
{
hsl_printf(so, "</td><td><font size=\"2\">(click to expand)"
"</font></td></tr>\n");
}
static void printEmptyLn(SERVLET_t so)
{
hsl_printf(so, "<tr><td><font size=\"-2\"> </font></td>"
"<td></td></tr>\n");
}
static void printStatsProto(SERVLET_t so, struct stats_proto* p, int doit)
{
if (doit)
{
printTabEnt(so, "xmit", p->xmit, 0);
printTabEnt(so, "rexmit", p->rexmit, 0);
printTabEnt(so, "recv", p->recv, 0);
printTabEnt(so, "fw", p->fw, 0);
printTabEnt(so, "drop", p->drop, 0);
printTabEnt(so, "chkerr", p->chkerr, 1);
printTabEnt(so, "lenerr", p->lenerr, 1);
printTabEnt(so, "memerr", p->memerr, 1);
printTabEnt(so, "rterr", p->rterr, 1);
printTabEnt(so, "proterr", p->proterr, 1);
printTabEnt(so, "opterr", p->opterr, 1);
printTabEnt(so, "err", p->err, 1);
printTabEnt(so, "cachehit",p->cachehit, 0);
printEmptyLn(so);
}
else printExpMsg(so);
}
static void printStatsPbuf(SERVLET_t so, struct stats_pbuf* p, int doit)
{
if (doit)
{
printTabEnt(so, "avail", p->avail, 0);
printTabEnt(so, "used", p->used, 0);
printTabEnt(so, "max", p->max, 0);
printTabEnt(so, "err", p->err, 1);
printTabEnt(so, "alloc_locked", p->alloc_locked, 0);
printTabEnt(so, "refresh_locked", p->refresh_locked, 0);
printEmptyLn(so);
}
else printExpMsg(so);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -