00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "StdAfx.h"
00023 #include "Shareaza.h"
00024 #include "Statistics.h"
00025 #include "Network.h"
00026 #include "Neighbours.h"
00027
00028 #ifdef _DEBUG
00029 #undef THIS_FILE
00030 static char THIS_FILE[]=__FILE__;
00031 #define new DEBUG_NEW
00032 #endif
00033
00034 CStatistics Statistics;
00035
00036
00038
00039
00040 CStatistics::CStatistics()
00041 {
00042 ZeroMemory( &Today, sizeof(Today) );
00043 ZeroMemory( &Ever, sizeof(Ever) );
00044 ZeroMemory( &Current, sizeof(Current) );
00045
00046 m_tUpdate = m_tSeconds = 0;
00047 }
00048
00049 CStatistics::~CStatistics()
00050 {
00051 }
00052
00054
00055
00056 void CStatistics::Update()
00057 {
00058 DWORD tNow = GetTickCount();
00059
00060 if ( tNow - m_tUpdate < 100 ) return;
00061 m_tUpdate = tNow;
00062
00063 if ( tNow - m_tSeconds >= 1000 )
00064 {
00065 if ( Network.IsWellConnected() )
00066 {
00067 Current.Timer.Connected ++;
00068 if ( Neighbours.IsG2Hub() ) Current.Timer.Hub ++;
00069 if ( Neighbours.IsG1Ultrapeer() ) Current.Timer.Ultrapeer ++;
00070 }
00071
00072 m_tSeconds = tNow;
00073 }
00074
00075 CopyMemory( &Last, &Current, sizeof(Current) );
00076 Add( &Today, &Current, sizeof(Current) );
00077 Add( &Ever, &Current, sizeof(Current) );
00078 ZeroMemory( &Current, sizeof(Current) );
00079 }
00080
00082
00083
00084 void CStatistics::Add(LPVOID pTarget, LPCVOID pSource, int nCount)
00085 {
00086 QWORD* pqwTarget = (QWORD*)pTarget;
00087 QWORD* pqwSource = (QWORD*)pSource;
00088
00089 for ( nCount /= sizeof(QWORD) ; nCount ; nCount-- )
00090 {
00091 *pqwTarget += *pqwSource;
00092
00093 pqwTarget++;
00094 pqwSource++;
00095 }
00096 }
00097