1 // ------------------------------------------------
8 // (c) 2002 peercast.org
9 // ------------------------------------------------
10 // This program is free software; you can redistribute it and/or modify
11 // it under the terms of the GNU General Public License as published by
12 // the Free Software Foundation; either version 2 of the License, or
13 // (at your option) any later version.
15 // This program is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
19 // ------------------------------------------------
27 #include "chkMemoryLeak.h"
28 #define DEBUG_NEW new(__FILE__, __LINE__)
33 // ------------------------------------
36 for(int i=0; i<Stats::MAX; i++)
44 // ------------------------------------
47 unsigned int ctime = sys->getTime();
49 unsigned int diff = ctime - lastUpdate;
50 if (diff >= /* 5 */ 1)
53 for(int i=0; i<Stats::MAX; i++)
55 perSec[i] = (unsigned)(current[i]-last[i])/diff;
63 // ------------------------------------
64 bool Stats::writeVariable(Stream &out,const String &var)
68 if (var == "totalInPerSec")
69 sprintf(buf,"%.1f",BYTES_TO_KBPS(getPerSecond(Stats::BYTESIN)));
70 else if (var == "totalOutPerSec")
71 sprintf(buf,"%.1f",BYTES_TO_KBPS(getPerSecond(Stats::BYTESOUT)));
72 else if (var == "totalPerSec")
73 sprintf(buf,"%.1f",BYTES_TO_KBPS(getPerSecond(Stats::BYTESIN)+getPerSecond(Stats::BYTESOUT)));
74 else if (var == "wanInPerSec")
75 sprintf(buf,"%.1f",BYTES_TO_KBPS(getPerSecond(Stats::BYTESIN)-getPerSecond(Stats::LOCALBYTESIN)));
76 else if (var == "wanOutPerSec")
77 sprintf(buf,"%.1f",BYTES_TO_KBPS(getPerSecond(Stats::BYTESOUT)-getPerSecond(Stats::LOCALBYTESOUT)));
78 else if (var == "wanTotalPerSec")
79 sprintf(buf,"%.1f",BYTES_TO_KBPS((getPerSecond(Stats::BYTESIN)-getPerSecond(Stats::LOCALBYTESIN))+(getPerSecond(Stats::BYTESOUT)-getPerSecond(Stats::LOCALBYTESOUT))));
80 else if (var == "netInPerSec")
81 sprintf(buf,"%.1f",BYTES_TO_KBPS(getPerSecond(Stats::PACKETDATAIN)));
82 else if (var == "netOutPerSec")
83 sprintf(buf,"%.1f",BYTES_TO_KBPS(getPerSecond(Stats::PACKETDATAOUT)));
84 else if (var == "netTotalPerSec")
85 sprintf(buf,"%.1f",BYTES_TO_KBPS(getPerSecond(Stats::PACKETDATAOUT)+getPerSecond(Stats::PACKETDATAIN)));
86 else if (var == "packInPerSec")
87 sprintf(buf,"%.1f",getPerSecond(Stats::NUMPACKETSIN));
88 else if (var == "packOutPerSec")
89 sprintf(buf,"%.1f",getPerSecond(Stats::NUMPACKETSOUT));
90 else if (var == "packTotalPerSec")
91 sprintf(buf,"%.1f",getPerSecond(Stats::NUMPACKETSOUT)+getPerSecond(Stats::NUMPACKETSIN));