//------------------------------------------------------------------------------ int TcpuUsage::GetCPUUsageForPP(void) { if (_ProcessorsCount > 2) { int result = 0; for (int i = 0; i < _ProcessorsCount - 1; i++) { int x = GetCPUUsage(i); if (x > result) { result = x; } } return result; } else { return GetCPUUsage(0); } }
// Statistics long ASM L_GetStatistics(REG(d0, long id),REG(a6, struct MyLibrary *libbase)) { struct LibData *data; #ifdef __amigaos4__ libbase = dopuslibbase_global; #endif // Get data pointer data=(struct LibData *)libbase->ml_UserData; // Task count? if (id==STATID_TASKCOUNT) return data->task_count; else if (id==STATID_CPU_USAGE) return GetCPUUsage(); return 0; }
void StatDumper::DumpStats() { if (!Filename) return; FILE * f = fopen(Filename, "w"); if (!f) return; // Dump Header fprintf(f, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); fprintf(f, "<?xml-stylesheet type=\"text/xsl\" href=\"server_stats.xsl\"?>\n"); fprintf(f, "<serverpage>\n"); fprintf(f, " <status>\n"); std::deque<Player*> gms; { // Dump server information. #ifdef WIN32 fprintf(f, " <platform>Antrix/Win32 v2.1.0-%u</platform>\n", g_getRevision()); #else fprintf(f, " <platform>Antrix/Linux v2.1.0-%u</platform>\n", g_getRevision()); #endif char uptime[80]; GenerateUptimeString(uptime); float AvgLat; uint32 GMCount; int gm = 0; int count = 0; int avg = 0; // lock players reader objmgr._playerslock.AcquireReadLock(); HM_NAMESPACE::hash_map<uint32, Player*>::const_iterator itr; for (itr = objmgr._players.begin(); itr != objmgr._players.end(); itr++) { if(itr->second->GetSession() && itr->second->IsInWorld()) { count++; avg += itr->second->GetSession()->GetLatency(); if(itr->second->GetSession()->GetPermissionCount()) { gm++; gms.push_back(itr->second); } } } objmgr._playerslock.ReleaseReadLock(); AvgLat = count ? (float)((float)avg / (float)count) : 0; GMCount = gm; fprintf(f, " <uptime>%s</uptime>\n", uptime); fprintf(f, " <oplayers>%u</oplayers>\n", (unsigned int)(sWorld.AlliancePlayers + sWorld.HordePlayers)); fprintf(f, " <cpu>%2.2f</cpu>\n", GetCPUUsage()); fprintf(f, " <qplayers>%u</qplayers>\n", (unsigned int)sWorld.GetQueueCount()); fprintf(f, " <ram>%.3f</ram>\n", GetRAMUsage()); fprintf(f, " <avglat>%.3f</avglat>\n", AvgLat); fprintf(f, " <threads>%u</threads>\n", (unsigned int)sThreadMgr.GetThreadCount()); time_t t = time(NULL); fprintf(f, " <gmcount>%u</gmcount>\n", (unsigned int)GMCount); fprintf(f, " <lastupdate>%s</lastupdate>\n", asctime(localtime(&t))); fprintf(f, " <alliance>%u</alliance>\n", (unsigned int)sWorld.AlliancePlayers); fprintf(f, " <horde>%u</horde>\n", (unsigned int)sWorld.HordePlayers); fprintf(f, " <acceptedconns>%u</acceptedconns>\n", (unsigned int)sWorld.mAcceptedConnections); fprintf(f, " <peakcount>%u</peakcount>\n", (unsigned int)sWorld.PeakSessionCount); fprintf(f, " <wdbquerysize>%u</wdbquerysize>\n", (unsigned int)(((MySQLDatabase*)Database_World)->GetQueueSize())); fprintf(f, " <cdbquerysize>%u</cdbquerysize>\n", (unsigned int)(((MySQLDatabase*)Database_Character)->GetQueueSize())); } fprintf(f, " </status>\n"); Player * plr; uint32 t = time(NULL); char otime[100]; { fprintf(f, " <instances>\n"); // need a big buffer.. static char buf[500000]; memset(buf, 0, 500000); // Dump Instance Information sWorldCreator.BuildXMLStats(buf); fprintf(f, buf); fprintf(f, " </instances>\n"); } { // GM Information fprintf(f, " <gms>\n"); while(!gms.empty()) { plr = gms.front(); gms.pop_front(); FillOnlineTime(t - plr->OnlineTime, otime); fprintf(f, " <gmplr>\n"); fprintf(f, " <name>%s</name>\n", plr->GetName()); fprintf(f, " <race>%u</race>\n", plr->getRace()); fprintf(f, " <class>%u</class>\n", (unsigned int)plr->getClass()); fprintf(f, " <gender>%u</gender>\n", (unsigned int)plr->getGender()); fprintf(f, " <pvprank>%u</pvprank>\n", (unsigned int)plr->GetPVPRank()); fprintf(f, " <level>%u</level>\n", (unsigned int)plr->GetUInt32Value(UNIT_FIELD_LEVEL)); fprintf(f, " <map>%u</map>\n", (unsigned int)plr->GetMapId()); fprintf(f, " <areaid>%u</areaid>\n", (unsigned int)plr->GetAreaID()); fprintf(f, " <ontime>%s</ontime>\n", otime); fprintf(f, " <latency>%u</latency>\n", (unsigned int)plr->GetSession()->GetLatency()); fprintf(f, " <permissions>%s</permissions>\n", plr->GetSession()->GetPermissions()); fprintf(f, " </gmplr>\n"); } fprintf(f, " </gms>\n"); } { fprintf(f, " <sessions>\n"); // Dump Player Information objmgr._playerslock.AcquireReadLock(); HM_NAMESPACE::hash_map<uint32, Player*>::const_iterator itr; for (itr = objmgr._players.begin(); itr != objmgr._players.end(); itr++) { plr = itr->second; if(itr->second->GetSession() && itr->second->IsInWorld()) { FillOnlineTime(t - plr->OnlineTime, otime); fprintf(f, " <plr>\n"); fprintf(f, " <name>%s</name>\n", plr->GetName()); fprintf(f, " <race>%u</race>\n", (unsigned int)plr->getRace()); fprintf(f, " <class>%u</class>\n", (unsigned int)plr->getClass()); fprintf(f, " <gender>%u</gender>\n", (unsigned int)plr->getGender()); fprintf(f, " <pvprank>%u</pvprank>\n", (unsigned int)plr->GetPVPRank()); fprintf(f, " <level>%u</level>\n", (unsigned int)plr->GetUInt32Value(UNIT_FIELD_LEVEL)); fprintf(f, " <map>%u</map>\n", (unsigned int)plr->GetMapId()); fprintf(f, " <areaid>%u</areaid>\n", (unsigned int)plr->GetAreaID()); //requested by Zdarkside for he's online map. I hope it does not scre up any parser. If so, then make a better one :P fprintf(f, " <xpos>%f</xpos>\n", plr->GetPositionX ()); fprintf(f, " <ypos>%f</ypos>\n", plr->GetPositionY()); fprintf(f, " <ontime>%s</ontime>\n", otime); fprintf(f, " <latency>%u</latency>\n", (unsigned int)plr->GetSession()->GetLatency()); fprintf(f, " </plr>\n"); if(plr->GetSession()->GetPermissionCount() > 0) gms.push_back(plr); } } objmgr._playerslock.ReleaseReadLock(); fprintf(f, " </sessions>\n"); } fprintf(f, "</serverpage>\n"); fclose(f); }
void StatDumper::DumpStats() { double TotalTrafficInKb = 0.0; double TotalTrafficOutKb = 0.0; double LastTotalTrafficInKb = 0.0; double LastTotalTrafficOutKb = 0.0; double TrafficInKb = 0.0; double TrafficOutKb = 0.0; double TrafficInKbsec = 0.0; double TrafficOutKbsec = 0.0; time_t timediff = 0; if( Filename[0] == NULL ) return; FILE* f = fopen( Filename, "w" ); if( !f ) return; Log.Debug( "StatDumper", "Writing %s", Filename ); // Dump Header fprintf(f, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); fprintf(f, "<?xml-stylesheet type=\"text/xsl\" href=\"server_stats.xsl\"?>\n"); fprintf(f, "<serverpage>\n"); fprintf(f, " <status>\n"); uint32 races[RACE_DRAENEI+1]; uint32 classes[DRUID+1]; memset(&races[0], 0, sizeof(uint32)*(RACE_DRAENEI+1)); memset(&classes[0], 0, sizeof(uint32)*(RACE_DRAENEI+1)); std::deque<Player*> gms; { // Dump server information. #ifdef WIN32 fprintf(f, " <platform>ArcEmu %s r%u/%s-Win-%s (www.ArcEmu.org)</platform>\n", BUILD_TAG, BUILD_REVISION, CONFIG, ARCH); #else fprintf(f, " <platform>ArcEmu %s r%u/%s-%s (www.ArcEmu.org)</platform>\n", BUILD_TAG, BUILD_REVISION, PLATFORM_TEXT, ARCH); #endif char uptime[80]; GenerateUptimeString(uptime); float AvgLat; uint32 GMCount; int gm = 0; int count = 0; int avg = 0; // lock players reader objmgr._playerslock.AcquireReadLock(); HM_NAMESPACE::hash_map<uint32, Player*>::const_iterator itr; for (itr = objmgr._players.begin(); itr != objmgr._players.end(); itr++) { if(itr->second->GetSession() && itr->second->IsInWorld()) { count++; avg += itr->second->GetSession()->GetLatency(); if(itr->second->GetSession()->GetPermissionCount()) { gm++; gms.push_back(itr->second); } classes[itr->second->getClass()]++; races[itr->second->getRace()]++; } } objmgr._playerslock.ReleaseReadLock(); AvgLat = count ? (float)((float)avg / (float)count) : 0; GMCount = gm; sWorld.QueryTotalTraffic(&TotalTrafficInKb,&TotalTrafficOutKb); if(LastTrafficUpdate != 0){ sWorld.QueryLastTotalTraffic(&LastTotalTrafficInKb, &LastTotalTrafficOutKb); TrafficInKb = TotalTrafficInKb - LastTotalTrafficInKb; TrafficOutKb = TotalTrafficOutKb - LastTotalTrafficOutKb; timediff = UNIXTIME - LastTrafficUpdate; if(TrafficInKb != 0 && TrafficOutKb != 0 && timediff != 0){ TrafficInKbsec = TrafficInKb / timediff; TrafficOutKbsec = TrafficOutKb / timediff; } } LastTrafficUpdate = UNIXTIME; fprintf(f, " <uptime>%s</uptime>\n", uptime); fprintf(f, " <oplayers>%u</oplayers>\n", (unsigned int)(sWorld.getPlayerCount())); fprintf(f, " <cpu>%2.2f</cpu>\n", GetCPUUsage()); fprintf(f, " <qplayers>%u</qplayers>\n", (unsigned int)sWorld.GetQueueCount()); fprintf(f, " <ram>%.3f</ram>\n", GetRAMUsage()); fprintf(f, " <avglat>%.3f</avglat>\n", AvgLat); fprintf(f, " <threads>%u</threads>\n", (unsigned int)ThreadPool.GetActiveThreadCount()); fprintf(f, " <fthreads>%u</fthreads>\n", (unsigned int)ThreadPool.GetFreeThreadCount()); time_t t = UNIXTIME; fprintf(f, " <gmcount>%u</gmcount>\n", (unsigned int)GMCount); fprintf(f, " <lastupdate>%s</lastupdate>\n", asctime(localtime(&t))); fprintf(f, " <alliance>%u</alliance>\n", (unsigned int)sWorld.getAlliancePlayerCount()); fprintf(f, " <horde>%u</horde>\n", (unsigned int)sWorld.getHordePlayerCount()); fprintf(f, " <acceptedconns>%u</acceptedconns>\n", (unsigned int)sWorld.mAcceptedConnections); fprintf(f, " <peakcount>%u</peakcount>\n", (unsigned int)sWorld.PeakSessionCount); fprintf(f, " <wdbquerysize>%u</wdbquerysize>\n", WorldDatabase.GetQueueSize()); fprintf(f, " <cdbquerysize>%u</cdbquerysize>\n", CharacterDatabase.GetQueueSize()); fprintf(f, " <bandwithin>%lf</bandwithin>\n", TrafficInKbsec); if( TotalTrafficInKb < 1024.0 ) fprintf(f, " <bandwithintotal>%lf KB</bandwithintotal>\n", TotalTrafficInKb); else fprintf(f, " <bandwithintotal>%lf MB</bandwithintotal>\n", ( TotalTrafficInKb / 1024.0)); fprintf(f, " <bandwithout>%lf</bandwithout>\n", TrafficOutKbsec); if( TotalTrafficOutKb < 1024.0 ) fprintf(f, " <bandwithouttotal>%lf KB</bandwithouttotal>\n", TotalTrafficOutKb); else fprintf(f, " <bandwithouttotal>%lf MB</bandwithouttotal>\n", ( TotalTrafficOutKb / 1024.0 )); } fprintf(f, " </status>\n"); static const char * race_names[RACE_DRAENEI+1] = { NULL, "human", "orc", "dwarf", "nightelf", "undead", "tauren", "gnome", "troll", NULL, "bloodelf", "draenei", }; static const char * class_names[DRUID+1] = { NULL, "warrior", "paladin", "hunter", "rogue", "priest", "deathknight", "shaman", "mage", "warlock", NULL, "druid", }; fprintf(f, " <statsummary>\n"); uint32 i; for(i = 0; i <= RACE_DRAENEI; ++i) { if( race_names[i] != NULL ) fprintf(f, " <%s>%u</%s>\n", race_names[i], races[i], race_names[i]); } for(i = 0; i <= DRUID; ++i) { if( class_names[i] != NULL ) fprintf(f, " <%s>%u</%s>\n", class_names[i], classes[i], class_names[i]); } fprintf(f, " </statsummary>\n"); Player * plr; uint32 t = (uint32)time(NULL); char otime[100]; { fprintf(f, " <instances>\n"); // need a big buffer.. static char buf[500000]; memset(buf, 0, 500000); // Dump Instance Information //sWorldCreator.BuildXMLStats(buf); sInstanceMgr.BuildXMLStats(buf); fprintf(f, buf); fprintf(f, " </instances>\n"); } { // GM Information fprintf(f, " <gms>\n"); while(!gms.empty()) { plr = gms.front(); gms.pop_front(); if(!plr->bGMTagOn) continue; FillOnlineTime(t - plr->OnlineTime, otime); fprintf(f, " <gmplr>\n"); fprintf(f, " <name>%s</name>\n", plr->GetName()); fprintf(f, " <race>%u</race>\n", plr->getRace()); fprintf(f, " <class>%u</class>\n", (unsigned int)plr->getClass()); fprintf(f, " <gender>%u</gender>\n", (unsigned int)plr->getGender()); fprintf(f, " <pvprank>%u</pvprank>\n", (unsigned int)plr->GetPVPRank()); fprintf(f, " <level>%u</level>\n", (unsigned int)plr->GetUInt32Value(UNIT_FIELD_LEVEL)); fprintf(f, " <map>%u</map>\n", (unsigned int)plr->GetMapId()); fprintf(f, " <areaid>%u</areaid>\n", (unsigned int)plr->GetAreaID()); fprintf(f, " <ontime>%s</ontime>\n", otime); fprintf(f, " <latency>%u</latency>\n", (unsigned int)plr->GetSession()->GetLatency()); fprintf(f, " <permissions>%s</permissions>\n", plr->GetSession()->GetPermissions()); fprintf(f, " </gmplr>\n"); } fprintf(f, " </gms>\n"); } { fprintf(f, " <sessions>\n"); // Dump Player Information objmgr._playerslock.AcquireReadLock(); HM_NAMESPACE::hash_map<uint32, Player*>::const_iterator itr; for (itr = objmgr._players.begin(); itr != objmgr._players.end(); itr++) { plr = itr->second; if(itr->second->GetSession() && itr->second->IsInWorld()) { FillOnlineTime(t - plr->OnlineTime, otime); fprintf(f, " <plr>\n"); fprintf(f, " <name>%s</name>\n", plr->GetName()); fprintf(f, " <race>%u</race>\n", (unsigned int)plr->getRace()); fprintf(f, " <class>%u</class>\n", (unsigned int)plr->getClass()); fprintf(f, " <gender>%u</gender>\n", (unsigned int)plr->getGender()); fprintf(f, " <pvprank>%u</pvprank>\n", (unsigned int)plr->GetPVPRank()); fprintf(f, " <level>%u</level>\n", (unsigned int)plr->GetUInt32Value(UNIT_FIELD_LEVEL)); fprintf(f, " <map>%u</map>\n", (unsigned int)plr->GetMapId()); fprintf(f, " <areaid>%u</areaid>\n", (unsigned int)plr->GetAreaID()); //requested by Zdarkside for he's online map. I hope it does not scre up any parser. If so, then make a better one :P fprintf(f, " <xpos>%f</xpos>\n", plr->GetPositionX ()); fprintf(f, " <ypos>%f</ypos>\n", plr->GetPositionY()); fprintf(f, " <ontime>%s</ontime>\n", otime); fprintf(f, " <latency>%u</latency>\n", (unsigned int)plr->GetSession()->GetLatency()); fprintf(f, " </plr>\n"); if(plr->GetSession()->GetPermissionCount() > 0) gms.push_back(plr); } } objmgr._playerslock.ReleaseReadLock(); fprintf(f, " </sessions>\n"); } fprintf(f, "</serverpage>\n"); fclose(f); }