From 46ea38f8d58c9afca93e76eb790c3266ffa26f00 Mon Sep 17 00:00:00 2001 From: Buginator Date: Sun, 31 Jan 2010 04:45:20 +0000 Subject: [PATCH] Merge r9584/9585 "Add sync counters to more accurately keep track of what is being synced and what isn't. This information is saved in netplay.log in the config dir." git-svn-id: https://warzone2100.svn.sourceforge.net/svnroot/warzone2100/trunk@9590 4a71c877-e1ca-e34f-864e-861f7616d084 --- lib/netplay/netlog.c | 17 +++++++++++++++++ lib/netplay/netplay.c | 3 ++- lib/netplay/netplay.h | 17 ++++++++++++++++- src/multisync.c | 35 +++++++++++++++++++++++++++++++++++ 4 files changed, 70 insertions(+), 2 deletions(-) diff --git a/lib/netplay/netlog.c b/lib/netplay/netlog.c index f615b1350..662d94869 100644 --- a/lib/netplay/netlog.c +++ b/lib/netplay/netlog.c @@ -146,6 +146,7 @@ BOOL NETstartLogging(void) BOOL NETstopLogging(void) { + static const char dash_line[] = "-----------------------------------------------------------\n"; char buf[256]; int i; @@ -161,6 +162,22 @@ BOOL NETstopLogging(void) packetcount[0][i], packetsize[0][i], packetcount[1][i], packetsize[1][i]); PHYSFS_write(pFileHandle, buf, strlen(buf), 1); } + snprintf(buf, sizeof(buf), "\n-Sync statistics -\n"); + PHYSFS_write(pFileHandle, buf, strlen(buf), 1); + PHYSFS_write(pFileHandle, dash_line, strlen(dash_line), 1); + snprintf(buf, sizeof(buf), "sent/unsent DroidCheck %llu / %llu\n", sync_counter.sentDroidCheck, sync_counter.unsentDroidCheck); + PHYSFS_write(pFileHandle, buf, strlen(buf), 1); + snprintf(buf, sizeof(buf), "sent/unsent StructureCheck %llu / %llu\n", sync_counter.sentStructureCheck, sync_counter.unsentStructureCheck); + PHYSFS_write(pFileHandle, buf, strlen(buf), 1); + snprintf(buf, sizeof(buf), "sent/unsent PowerCheck %llu / %llu\n", sync_counter.sentPowerCheck, sync_counter.unsentPowerCheck); + PHYSFS_write(pFileHandle, buf, strlen(buf), 1); + snprintf(buf, sizeof(buf), "sent/unsent ScoreCheck %llu / %llu\n", sync_counter.sentScoreCheck, sync_counter.unsentScoreCheck); + PHYSFS_write(pFileHandle, buf, strlen(buf), 1); + snprintf(buf, sizeof(buf), "sent/unsent Ping %llu / %llu\n", sync_counter.sentPing, sync_counter.unsentPing); + PHYSFS_write(pFileHandle, buf, strlen(buf), 1); + snprintf(buf, sizeof(buf), "sent/unsent isMPDirtyBit %llu / %llu\n", sync_counter.sentisMPDirtyBit, sync_counter.unsentisMPDirtyBit); + PHYSFS_write(pFileHandle, buf, strlen(buf), 1); + PHYSFS_write(pFileHandle, dash_line, strlen(dash_line), 1); if (!PHYSFS_close(pFileHandle)) { diff --git a/lib/netplay/netplay.c b/lib/netplay/netplay.c index 0a29560c8..d452e8f4b 100644 --- a/lib/netplay/netplay.c +++ b/lib/netplay/netplay.c @@ -146,7 +146,7 @@ void NETresetGamePassword(void); * Network globals, these are part of the new network API */ NETMSG NetMsg; - +SYNC_COUNTER sync_counter; // keeps track on how well we are in sync // //////////////////////////////////////////////////////////////////////// // Types @@ -1946,6 +1946,7 @@ int NETinit(BOOL bFirstCall) NetPlay.ShowedMOTD = false; NetPlay.GamePassworded = false; + memset(&sync_counter, 0x0, sizeof(sync_counter)); //clear counters return 0; } diff --git a/lib/netplay/netplay.h b/lib/netplay/netplay.h index 9ba362027..f9de974d9 100644 --- a/lib/netplay/netplay.h +++ b/lib/netplay/netplay.h @@ -186,6 +186,21 @@ typedef struct #define NET_ALL_PLAYERS 255 #define NET_HOST_ONLY 0 +// the following structure is going to be used to track if we sync or not +typedef struct { + uint64_t sentDroidCheck; + uint64_t unsentDroidCheck; + uint64_t sentStructureCheck; + uint64_t unsentStructureCheck; + uint64_t sentPowerCheck; + uint64_t unsentPowerCheck; + uint64_t sentScoreCheck; + uint64_t unsentScoreCheck; + uint64_t sentPing; + uint64_t unsentPing; + uint64_t sentisMPDirtyBit; + uint64_t unsentisMPDirtyBit; +} SYNC_COUNTER; typedef struct { uint16_t size; // used size of body @@ -264,7 +279,7 @@ typedef struct { extern NETPLAY NetPlay; extern NETMSG NetMsg; - +extern SYNC_COUNTER sync_counter; // update flags extern bool netPlayersUpdated; extern int mapDownloadProgress; diff --git a/src/multisync.c b/src/multisync.c index 20cf68cf5..61d56e7af 100644 --- a/src/multisync.c +++ b/src/multisync.c @@ -134,22 +134,57 @@ BOOL sendCheck(void) if(okToSend()) { sendDroidCheck(); + sync_counter.sentDroidCheck++; + } + else + { + sync_counter.unsentDroidCheck++; } if(okToSend()) { sendStructureCheck(); + sync_counter.sentStructureCheck++; + + } + else + { + sync_counter.unsentStructureCheck++; } if(okToSend()) { sendPowerCheck(); + sync_counter.sentPowerCheck++; + } + else + { + sync_counter.unsentPowerCheck++; } if(okToSend()) { sendScoreCheck(); + sync_counter.sentScoreCheck++; + } + else + { + sync_counter.unsentScoreCheck++; } if(okToSend()) { sendPing(); + sync_counter.sentPing++; + } + else + { + sync_counter.unsentPing++; + } + + if (isMPDirtyBit) + { + sync_counter.sentisMPDirtyBit++; + } + else + { + sync_counter.unsentisMPDirtyBit++; } // FIXME: reset flag--For now, we always do this since we have no way of knowing which routine(s) we had to set this flag isMPDirtyBit = false;