[Box Backup-commit] COMMIT r1182 - box/chris/merge/lib/common

boxbackup-dev at fluffy.co.uk boxbackup-dev at fluffy.co.uk
Tue Nov 28 20:28:44 GMT 2006


Author: chris
Date: 2006-11-28 20:28:43 +0000 (Tue, 28 Nov 2006)
New Revision: 1182

Modified:
   box/chris/merge/lib/common/Timer.cpp
Log:
Added debug tracing code for timers.


Modified: box/chris/merge/lib/common/Timer.cpp
===================================================================
--- box/chris/merge/lib/common/Timer.cpp	2006-11-27 19:19:57 UTC (rev 1181)
+++ box/chris/merge/lib/common/Timer.cpp	2006-11-28 20:28:43 UTC (rev 1182)
@@ -219,8 +219,26 @@
 : mExpires(GetCurrentBoxTime() + SecondsToBoxTime(timeoutSecs)),
   mExpired(false)
 {
+	#ifndef NDEBUG
+	struct timeval tv;
+	gettimeofday(&tv, NULL);
 	if (timeoutSecs == 0)
 	{
+		TRACE4("%d.%d: timer %p initialised for %d secs, "
+			"will not fire\n", tv.tv_sec, tv.tv_usec, this, 
+			timeoutSecs);
+	}
+	else
+	{
+		TRACE6("%d.%d: timer %p initialised for %d secs, "
+			"to fire at %d.%d\n", tv.tv_sec, tv.tv_usec, this, 
+			timeoutSecs, (int)(mExpires / 1000000), 
+			(int)(mExpires % 1000000));
+	}
+	#endif
+
+	if (timeoutSecs == 0)
+	{
 		mExpires = 0;
 	}
 	else
@@ -231,6 +249,13 @@
 
 Timer::~Timer()
 {
+	#ifndef NDEBUG
+	struct timeval tv;
+	gettimeofday(&tv, NULL);
+	TRACE3("%d.%d: timer %p destroyed, will not fire\n",
+		tv.tv_sec, tv.tv_usec, this);
+	#endif
+
 	Timers::Remove(*this);
 }
 
@@ -238,14 +263,62 @@
 : mExpires(rToCopy.mExpires),
   mExpired(rToCopy.mExpired)
 {
-	if (mExpires != 0)
+	#ifndef NDEBUG
+	struct timeval tv;
+	gettimeofday(&tv, NULL);
+	if (mExpired)
 	{
+		TRACE4("%d.%d: timer %p initialised from timer %p, "
+			"already expired, will not fire\n", tv.tv_sec, 
+			tv.tv_usec, this, &rToCopy);
+	}
+	else if (mExpires == 0)
+	{
+		TRACE4("%d.%d: timer %p initialised from timer %p, "
+			"will not fire\n", tv.tv_sec, tv.tv_usec, this, 
+			&rToCopy);
+	}
+	else
+	{
+		TRACE6("%d.%d: timer %p initialised from timer %p, "
+			"to fire at %d.%d\n", tv.tv_sec, tv.tv_usec, this, 
+			&rToCopy, (int)(mExpires / 1000000), 
+			(int)(mExpires % 1000000));
+	}
+	#endif
+
+	if (!mExpired && mExpires != 0)
+	{
 		Timers::Add(*this);
 	}
 }
 
 Timer& Timer::operator=(const Timer& rToCopy)
 {
+	#ifndef NDEBUG
+	struct timeval tv;
+	gettimeofday(&tv, NULL);
+	if (rToCopy.mExpired)
+	{
+		TRACE4("%d.%d: timer %p initialised from timer %p, "
+			"already expired, will not fire\n", tv.tv_sec, 
+			tv.tv_usec, this, &rToCopy);
+	}
+	else if (rToCopy.mExpires == 0)
+	{
+		TRACE4("%d.%d: timer %p initialised from timer %p, "
+			"will not fire\n", tv.tv_sec, tv.tv_usec, this, 
+			&rToCopy);
+	}
+	else
+	{
+		TRACE6("%d.%d: timer %p initialised from timer %p, "
+			"to fire at %d.%d\n", tv.tv_sec, tv.tv_usec, this, 
+			&rToCopy, (int)(rToCopy.mExpires / 1000000), 
+			(int)(rToCopy.mExpires % 1000000));
+	}
+	#endif
+
 	Timers::Remove(*this);
 	mExpires = rToCopy.mExpires;
 	mExpired = rToCopy.mExpired;
@@ -258,6 +331,12 @@
 
 void Timer::OnExpire()
 {
+	#ifndef NDEBUG
+	struct timeval tv;
+	gettimeofday(&tv, NULL);
+	TRACE3("%d.%d: timer %p fired\n", tv.tv_sec, tv.tv_usec, this);
+	#endif
+
 	mExpired = true;
 	Timers::Remove(*this);
 }




More information about the Boxbackup-commit mailing list